Skip to content

Commit 5f59f27

Browse files
authored
Merge pull request #1374 from roiLeo/refactoring/store
👔 refactoring store
2 parents 5c4c217 + 6b4e397 commit 5f59f27

34 files changed

+490
-474
lines changed

components/accounts/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const toDistribute = (length: number, distribution: number): number => {
1818
}
1919

2020
export const parseBatchAddresses = (batchAddresses: string): string[] => {
21-
const ss58Format: any = store.getters.getChainProperties58Format
21+
const ss58Format: any = store.getters['chain/getChainProperties58Format']
2222
const addresses = batchAddresses
2323
.split('\n')
2424
.map((x) => x.split('-'))

components/metadata/Metadata.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export default class Summary extends Vue {
4646
public chainProperties: any = this.emptyChainProperties;
4747
public loading = false;
4848
49-
@Watch('$store.state.chainProperties')
49+
@Watch('$store.state["chain/chainProperties"]')
5050
public mapProp(): void {
51-
this.chainProperties = {...this.emptyChainProperties, ...this.$store.state.chainProperties}
51+
this.chainProperties = {...this.emptyChainProperties, ...this.$store.state['chain/chainProperties']}
5252
}
5353
5454
@Watch('$store.state.loading')

components/rmrk/Create/SimpleMint.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
tooltipsize="is-large"
187187
>
188188
<template v-slot:content>
189-
{{ $t('carbonOffset.tooltip') }}
189+
{{ $t('carbonOffset.tooltip') }}
190190
(<a class="has-text-black is-underlined" href='https://kodadot.xyz/carbonless'>https://kodadot.xyz/carbonless</a>)
191191
</template>
192192
</Tooltip>
@@ -617,7 +617,7 @@ export default class SimpleMint extends mixins(
617617
}
618618
619619
get chainProperties() {
620-
return this.$store.getters.getChainProperties
620+
return this.$store.getters['chain/getChainProperties']
621621
}
622622
623623
get decimals(): number {

components/rmrk/Gallery/CollectionItem.vue

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
<div class="columns is-centered">
44
<div class="column is-half has-text-centered">
55
<div class="container image is-128x128 mb-2">
6-
<b-image
7-
v-if="!isLoading"
6+
<BasicImage
87
:src="image"
98
:alt="name"
10-
ratio="1by1"
119
rounded
12-
></b-image>
10+
customClass="collection__image"
11+
/>
1312
</div>
1413
<h1 class="title is-2">
15-
{{ name }}
14+
<template v-if="!isLoading">
15+
{{ name }}
16+
</template>
17+
<b-skeleton :active="isLoading" size="is-medium"></b-skeleton>
1618
</h1>
1719
</div>
1820
</div>
1921

2022
<div class="columns is-align-items-center">
2123
<div class="column">
22-
<div class="label">
23-
{{ $t('creator') }}
24-
</div>
25-
<div class="subtitle is-size-6">
26-
<ProfileLink :address="issuer" :inline="true" :showTwitter="true"/>
27-
</div>
28-
</div>
29-
<div class="column" v-if="owner">
30-
<div class="label">
31-
{{ $t('owner') }}
32-
</div>
33-
<div class="subtitle is-size-6">
34-
<ProfileLink :address="owner" :inline="true" :showTwitter="true" />
24+
<div v-if="!isLoading">
25+
<div class="label">
26+
{{ $t('creator') }}
27+
</div>
28+
<div v-if="issuer" class="subtitle is-size-6">
29+
<ProfileLink :address="issuer" inline showTwitter />
30+
</div>
3531
</div>
32+
<b-skeleton :active="isLoading" width="40%" size="is-small"></b-skeleton>
33+
<b-skeleton :active="isLoading" width="60%" size="is-small"></b-skeleton>
3634
</div>
35+
3736
<div class="column is-6-tablet is-7-desktop is-8-widescreen">
3837
<CollectionActivity :nfts="stats" />
3938
</div>
39+
4040
<div class="column has-text-right">
4141
<Sharing v-if="sharingVisible"
4242
class="mb-2"
@@ -47,27 +47,27 @@
4747
</div>
4848
</div>
4949

50-
<b-tabs v-model="activeTab" position="is-centered">
51-
<b-tab-item label="Collection">
52-
<div class="columns is-centered">
53-
<div class="column is-8 has-text-centered">
54-
<CollapseWrapper
55-
visible="collapse.collection.description.show"
56-
hidden="collapse.collection.description.hide"
57-
>
58-
<VueMarkdown :source="description" />
59-
</CollapseWrapper>
60-
</div>
61-
</div>
50+
<div class="columns is-centered">
51+
<div class="column is-8 has-text-centered">
52+
<CollapseWrapper
53+
visible="collapse.collection.description.show"
54+
hidden="collapse.collection.description.hide"
55+
>
56+
<VueMarkdown :source="description" />
57+
</CollapseWrapper>
58+
</div>
59+
</div>
6260

61+
<b-tabs position="is-centered" v-model="activeTab">
62+
<b-tab-item label="Collection" value="collection">
6363
<Search v-bind.sync="searchQuery">
6464
<Layout class="mr-5" />
6565
<b-field>
6666
<Pagination hasMagicBtn simple replace preserveScroll :total="total" v-model="currentValue" :per-page="first" />
6767
</b-field>
6868
</Search>
6969

70-
<GalleryCardList :items="collection.nfts" :horizontalLayout="true" />
70+
<GalleryCardList :items="collection.nfts" horizontalLayout />
7171

7272
<Pagination
7373
class="py-5"
@@ -78,26 +78,28 @@
7878
:per-page="first"
7979
/>
8080
</b-tab-item>
81-
<b-tab-item label="Activity">
82-
<CollectionPriceChart v-if="activeTab === 1" :priceData="priceData" />
81+
<b-tab-item label="Activity" value="activity">
82+
<CollectionPriceChart :priceData="priceData" />
8383
</b-tab-item>
8484
</b-tabs>
8585
</section>
8686
</template>
8787

8888
<script lang="ts" >
8989
import { emptyObject } from '@/utils/empty'
90-
import { Component, mixins } from 'nuxt-property-decorator'
90+
import { Component, mixins, Watch } from 'nuxt-property-decorator'
9191
import { CollectionWithMeta, Interaction } from '../service/scheme'
9292
import {
9393
sanitizeIpfsUrl, fetchCollectionMetadata, sortByTimeStamp, onlyEvents, onlyPriceEvents,
9494
eventTimestamp, soldNFTPrice, collectionFloorPriceList, PriceDataType, onlyBuyEvents
9595
} from '../utils'
9696
import isShareMode from '@/utils/isShareMode'
97+
import shouldUpdate from '@/utils/shouldUpdate'
9798
import collectionById from '@/queries/collectionById.graphql'
9899
import nftListByCollection from '@/queries/nftListByCollection.graphql'
99100
import { CollectionMetadata } from '../types'
100101
import { NFT } from '@/components/rmrk/service/scheme'
102+
import { exist } from '@/components/rmrk/Gallery/Search/exist'
101103
import { SearchQuery } from './Search/types'
102104
import ChainMixin from '@/utils/mixins/chainMixin'
103105
@@ -112,6 +114,7 @@ const components = {
112114
DonationButton: () => import('@/components/transfer/DonationButton.vue'),
113115
Layout: () => import('@/components/rmrk/Gallery/Layout.vue'),
114116
CollectionPriceChart: () => import('@/components/rmrk/Gallery/CollectionPriceChart.vue'),
117+
BasicImage: () => import('@/components/shared/view/BasicImage.vue'),
115118
CollapseWrapper: () => import('@/components/shared/collapse/CollapseWrapper.vue'),
116119
}
117120
@Component<CollectionItem>({
@@ -139,27 +142,30 @@ export default class CollectionItem extends mixins(
139142
) {
140143
private id = '';
141144
private collection: CollectionWithMeta = emptyObject<CollectionWithMeta>();
142-
private isLoading = false;
143145
public meta: CollectionMetadata = emptyObject<CollectionMetadata>();
144146
private searchQuery: SearchQuery = {
145147
search: '',
146148
type: '',
147149
sortBy: 'BLOCK_NUMBER_DESC',
148150
listed: false,
149151
};
150-
private activeTab = 0;
152+
public activeTab = 'collection';
151153
private currentValue = 1;
152154
private first = 15;
153-
private total = 0;
155+
protected total = 0;
154156
protected stats: NFT[] = [];
155157
protected priceData: any = [];
156158
159+
get isLoading(): boolean {
160+
return this.$apollo.queries.collection.loading
161+
}
162+
157163
get offset(): number {
158164
return this.currentValue * this.first - this.first
159165
}
160166
161-
get image(): string {
162-
return this.meta.image || ''
167+
get image(): string|undefined {
168+
return this.meta.image
163169
}
164170
165171
get description(): string {
@@ -178,10 +184,6 @@ export default class CollectionItem extends mixins(
178184
return this.collection.issuer || ''
179185
}
180186
181-
get owner(): string {
182-
return this.collection.issuer === (this.collection as any).currentOwner ? '' : (this.collection as any).currentOwner
183-
}
184-
185187
get sharingVisible(): boolean {
186188
return !isShareMode
187189
}
@@ -205,10 +207,12 @@ export default class CollectionItem extends mixins(
205207
}
206208
207209
public created(): void {
208-
this.isLoading = true
209210
this.checkId()
211+
this.checkActiveTab()
212+
this.loadStats()
210213
this.$apollo.addSmartQuery('collection', {
211214
query: collectionById,
215+
loadingKey: 'isLoading',
212216
variables: () => {
213217
return {
214218
id: this.id,
@@ -225,11 +229,9 @@ export default class CollectionItem extends mixins(
225229
result: this.handleResult,
226230
})
227231
228-
this.loadStats()
229-
this.isLoading = false
230232
}
231233
232-
public async loadStats(): Promise<void> {
234+
public loadStats(): void {
233235
const nftStatsP = this.$apollo.query({
234236
query: nftListByCollection,
235237
variables: {
@@ -244,29 +246,27 @@ export default class CollectionItem extends mixins(
244246
}
245247
246248
public loadPriceData(): void {
247-
248249
this.priceData = []
249250
250-
const events : Interaction[][] = this.stats?.map(onlyEvents) || []
251-
const priceEvents : Interaction[][] = events.map(this.priceEvents) || []
251+
const events: Interaction[][] = this.stats?.map(onlyEvents) || []
252+
const priceEvents: Interaction[][] = events.map(this.priceEvents) || []
252253
253-
const overTime : string[] = priceEvents.flat().sort(sortByTimeStamp).map(eventTimestamp)
254+
const overTime: string[] = priceEvents.flat().sort(sortByTimeStamp).map(eventTimestamp)
254255
255-
const floorPriceData : PriceDataType[] = overTime.map(collectionFloorPriceList(priceEvents, this.decimals))
256+
const floorPriceData: PriceDataType[] = overTime.map(collectionFloorPriceList(priceEvents, this.decimals))
256257
257258
const buyEvents = events.map(onlyBuyEvents)?.flat().sort(sortByTimeStamp)
258-
const soldPriceData : PriceDataType[] = buyEvents?.map(soldNFTPrice(this.decimals))
259+
const soldPriceData: PriceDataType[] = buyEvents?.map(soldNFTPrice(this.decimals))
259260
260261
this.priceData = [floorPriceData, soldPriceData]
261262
}
262263
263264
public async handleResult({data}: any): Promise<void> {
264265
this.total = data.collectionEntity.nfts.totalCount
265-
this.fetchMetadata()
266+
await this.fetchMetadata()
266267
}
267268
268269
public async fetchMetadata(): Promise<void> {
269-
console.log(this.collection['metadata'], !this.meta['image'])
270270
if (this.collection['metadata'] && !this.meta['image']) {
271271
const meta = await fetchCollectionMetadata(this.collection)
272272
this.meta = {
@@ -282,12 +282,34 @@ export default class CollectionItem extends mixins(
282282
}
283283
}
284284
285+
public checkActiveTab(): void {
286+
exist(this.$route.query.tab, (val) => {
287+
this.activeTab = val
288+
})
289+
}
290+
291+
@Watch('activeTab')
292+
protected onTabChange(val: string, oldVal: string): void {
293+
if (shouldUpdate(val, oldVal)) {
294+
this.$router.replace({
295+
name: String(this.$route.name),
296+
query: { tab: val },
297+
})
298+
}
299+
}
300+
285301
get iframeSettings(): Record<string, unknown> {
286302
return { width: '100%', height: '100vh' }
287303
}
288304
289-
protected priceEvents(nftEvents:Interaction[]) : Interaction[] {
305+
protected priceEvents(nftEvents: Interaction[]): Interaction[] {
290306
return nftEvents.filter(onlyPriceEvents)
291307
}
292308
}
293309
</script>
310+
311+
<style>
312+
.collection__image img {
313+
color: transparent;
314+
}
315+
</style>

components/rmrk/Gallery/GalleryCardList.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ export default class GalleryCardList extends Vue {
3838
@Prop({ default: '/rmrk/gallery' }) public route!: string;
3939
@Prop({ default: 'rmrk/gallery' }) public link!: string;
4040
@Prop() public items!: RmrkType[];
41-
@Prop(Boolean) horizontalLayout!: boolean;
41+
@Prop(Boolean) public horizontalLayout!: boolean;
4242
get classLayout() {
43-
return this.$store.getters.getLayoutClass
43+
return this.$store.getters['preferences/getLayoutClass']
4444
}
4545
}
4646
4747
</script>
4848
<style>
49+
/* TODO: move to global */
4950
.b-radio.radio.button.is-selected{
5051
background-color: #db2980;
5152
}

components/rmrk/Gallery/History.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default class History extends mixins(ChainMixin) {
203203
protected getBlockUrl(block: string): string {
204204
return urlBuilderBlockNumber(
205205
block,
206-
this.$store.getters.getCurrentChain,
206+
this.$store.getters['explorer/getCurrentChain'],
207207
'subscan'
208208
);
209209
}

components/rmrk/Gallery/Layout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class Layout extends Vue {
4141
public layout = 'is-one-third-desktop is-one-third-tablet'
4242
4343
public onInputChange (data :string) {
44-
this.$store.dispatch('setLayoutClass', data)
44+
this.$store.dispatch('preferences/setLayoutClass', data)
4545
}
4646
}
4747
</script>

components/series/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const nftFn = (a: any): RowSeries => {
5959
}
6060
}
6161

62-
const tokenDecimals = store.getters.getChainPropertiesTokenDecimals as any
62+
const tokenDecimals = store.getters['chain/getChainPropertiesTokenDecimals'] as any
6363
const formatNumber = (val: SimpleSeriesNFT) =>
6464
Number(
6565
formatBalance(

components/settings/SettingChooserExplorer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ export default class SettingChooserExplorer extends Vue {
3131
@Prop() public addMethod!: string;
3232
3333
get options() {
34-
return this.$store.state.explorerOptions.availableOptions[this.selector]
34+
return this.$store.state['explorer/explorerOptions'].availableOptions[this.selector]
3535
}
3636
3737
get selected() {
38-
return this.$store.state.explorerOptions.availableOptions[this.selector][this.defaultValue].value
38+
return this.$store.state['explorer/explorerOptions'].availableOptions[this.selector][this.defaultValue].value
3939
}
4040
4141
set selected(value) {
4242
this.$store.commit(this.setter, { [this.selector]: value })
4343
}
4444
4545
public async mounted() {
46-
this.$store.commit('setExplorerOptions',{ availableOptions: {
46+
this.$store.dispatch('explorer/setExplorerOptions', { availableOptions: {
4747
provider: [
4848
{ text: 'Subscan', value: 'subscan' },
4949
{ text: 'Polkascan', value: 'polkascan'}

0 commit comments

Comments
 (0)