11<script setup>
2- import {onMounted , onUnmounted , ref } from " vue" ;
2+ import {onMounted , onUnmounted , ref , watch } from " vue" ;
33import {useRouter } from " vue-router" ;
44import {arrayBufferToBase64 } from " @/utils/bytes2img.js"
55import StatusItem from " ./StatusItem.vue"
@@ -13,7 +13,8 @@ import i18n from "@/i18n/index.js";
1313const router = useRouter ()
1414const service = useService ();
1515
16- const images = ref ([])
16+ const presentationState = ref (imagePresentation)
17+ const images = ref ({})
1718const coinsList = ref ([])
1819const searchVal = ref (null )
1920const sortedBy = ref (null )
@@ -38,13 +39,27 @@ const props = defineProps({
3839});
3940
4041onMounted (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})
4252onUnmounted (async () => {
4353})
4454
4555const 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
100114const 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" />
0 commit comments