Skip to content

Commit 0cc36f6

Browse files
committed
CAche images in dict instead list
1 parent 7abdfba commit 0cc36f6

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

frontend/src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ const openFile = async (file, connection_type) => {
7777
})
7878
7979
await router.replace('/')
80+
collectionSettings.value = {};
81+
collectionFilters.value = {'status': [], 'country': [], 'series': [], 'type': [], 'period': [], 'mint': []}
8082
isOpened = true;
8183
82-
collectionFilters.value = {'status': [], 'country': [], 'series': [], 'type': [], 'period': [], 'mint': []}
8384
let ret = null
8485
8586
if (connection_type === 'remote') {

frontend/src/components/CoinListView.vue

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import {onMounted, onUnmounted, ref} from "vue";
2+
import {onMounted, onUnmounted, ref, watch} from "vue";
33
import {useRouter} from "vue-router";
44
import {arrayBufferToBase64} from "@/utils/bytes2img.js"
55
import StatusItem from "./StatusItem.vue"
@@ -13,7 +13,8 @@ import i18n from "@/i18n/index.js";
1313
const router = useRouter()
1414
const service = useService();
1515
16-
const images = ref([])
16+
const presentationState = ref(imagePresentation)
17+
const images = ref({})
1718
const coinsList = ref([])
1819
const searchVal = ref(null)
1920
const sortedBy = ref(null)
@@ -38,13 +39,27 @@ const props = defineProps({
3839
});
3940
4041
onMounted(async () => {
42+
watch(presentationState, () => {
43+
images.value = {}
44+
if (imagePresentation.value === 'image' && props.settings.type) {
45+
const coins_list = service.loadCoins()
46+
coins_list.forEach((coin) => {
47+
images.value[coin[0]] = coin[1];
48+
});
49+
}
50+
})
4151
})
4252
onUnmounted(async () => {
4353
})
4454
4555
const onOpenFile = async () => {
56+
images.value = {};
4657
coinsList.value = await service.loadCoins()
47-
images.value = new Array(coinsList.value.length).fill('')
58+
if (imagePresentation.value === 'image') {
59+
coinsList.value.forEach((coin) => {
60+
images.value[coin[0]] = coin[1];
61+
});
62+
}
4863
4964
fields.value = ['title', 'year']
5065
if (props.filters['status'].length > 1)
@@ -69,7 +84,6 @@ const clear = async () => {
6984
selectedType.value = null
7085
selectedPeriod.value = null
7186
selectedMint.value = null
72-
images.value = []
7387
coinsList.value = []
7488
}
7589
@@ -98,7 +112,6 @@ function generateDescription( coin_data ) {
98112
}
99113
100114
const onChanged = async () => {
101-
images.value = []
102115
coinsList.value = []
103116
coinsList.value = await service.loadCoins(
104117
searchVal.value,
@@ -113,8 +126,11 @@ const onChanged = async () => {
113126
);
114127
}
115128
116-
const loadImage = async (index, coinId) => {
117-
images.value[index] = await service.loadImage(coinId, imagePresentation.value);
129+
const loadImage = async (coinId) => {
130+
if (coinId in images.value)
131+
return;
132+
133+
images.value[coinId] = await service.loadImage(coinId, imagePresentation.value);
118134
}
119135
</script>
120136

@@ -157,21 +173,21 @@ const loadImage = async (index, coinId) => {
157173
>
158174
<template v-slot:prepend v-if="imagePresentation === 'obverse'">
159175
<v-lazy :width="56">
160-
<v-img :src="images[index]" :width="56" max-height="56" :tmp="loadImage(index, coin[0])" />
176+
<v-img :src="images[coin[0]]" :width="56" max-height="56" :tmp="loadImage(coin[0])" />
161177
</v-lazy>
162178
</template>
163179
<template v-slot:prepend v-else-if="imagePresentation === 'reverse'">
164180
<v-lazy :width="56">
165-
<v-img :src="images[index]" :width="56" max-height="56" :tmp="loadImage(index, coin[0])" />
181+
<v-img :src="images[coin[0]]" :width="56" max-height="56" :tmp="loadImage(coin[0])" />
166182
</v-lazy>
167183
</template>
168184
<template v-slot:prepend v-else-if="imagePresentation === 'both'">
169185
<v-lazy :width="100">
170-
<v-img :src="images[index]" :width="100" max-height="56" :tmp="loadImage(index, coin[0])" />
186+
<v-img :src="images[coin[0]]" :width="100" max-height="56" :tmp="loadImage(coin[0])" />
171187
</v-lazy>
172188
</template>
173189
<template v-slot:prepend v-else>
174-
<v-img :src="arrayBufferToBase64(coin[1])" :width="100" max-height="56" />
190+
<v-img :src="arrayBufferToBase64(images[coin[0]])" :width="100" max-height="56" />
175191
</template>
176192
<template v-slot:append>
177193
<StatusItem :status="coin[3]" :statuses="settings.statuses" :statusPresentation="statusPresentation" />

frontend/src/components/SortItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const onChanged = async (val) => {
1212
</script>
1313

1414
<template>
15-
<v-row align="center" density="compact" v-if="fields.length > 0">
15+
<v-row align="center" density="compact" v-if="fields.length > 0 && settings.type">
1616
<v-col class="mr-4">
1717
<v-select
1818
v-model="sortedBy"

0 commit comments

Comments
 (0)