@@ -24,7 +24,7 @@ import {
2424} from " $lib/utils/personalBinding" ;
2525import {
2626 deleteCachedPhoto ,
27- getAllCachedPhotos ,
27+ getCachedPhotosForEname ,
2828 setCachedPhoto ,
2929} from " $lib/utils/photoCache" ;
3030import { Delete02Icon , PencilEdit02Icon } from " @hugeicons/core-free-icons" ;
@@ -36,6 +36,11 @@ import AddPhotoSheet from "./components/AddPhotoSheet.svelte";
3636
3737const binding = $derived ($personalBinding );
3838const achieved = $derived (marksAchieved (binding ));
39+ const sortedPhotos = $derived (
40+ [... binding .photos ].sort ((a , b ) =>
41+ (a .metaEnvelopeId ?? a .id ).localeCompare (b .metaEnvelopeId ?? b .id ),
42+ ),
43+ );
3944const photosFilled = $derived (binding .photos .length > 0 );
4045const parametersFilled = $derived (
4146 !! binding .parameters && binding .parameters .text .trim ().length > 0 ,
@@ -98,7 +103,7 @@ onMount(() => {
98103 // This runs before the network requests so photos are already
99104 // in the store when loading = false fires and the UI becomes
100105 // visible — no skeleton flash on repeat visits.
101- const cachedPhotos = await getAllCachedPhotos ( );
106+ const cachedPhotos = await getCachedPhotosForEname ( ename );
102107 if (cachedPhotos .length > 0 ) {
103108 replaceAll ({
104109 ... $personalBinding ,
@@ -118,26 +123,38 @@ onMount(() => {
118123 // base64 blobs and arrive later — they update the store and
119124 // refresh the cache when done.
120125 const paramsPromise = loadPersonalParameters (gqlUrl , ename ).then (
121- (params ) => { setParametersLocal (params ); },
122- );
123- const securityPromise = loadPersonalSecurityQuestion (gqlUrl , ename ).then (
124- (security ) => { setKnowledgeLocal (security ); },
126+ (params ) => {
127+ setParametersLocal (params );
128+ },
125129 );
130+ const securityPromise = loadPersonalSecurityQuestion (
131+ gqlUrl ,
132+ ename ,
133+ ).then ((security ) => {
134+ setKnowledgeLocal (security );
135+ });
126136 const photosPromise = loadPersonalPhotographs (gqlUrl , ename ).then (
127137 async (photographs ) => {
138+ if (! ename ) return ;
128139 const current = $personalBinding ;
129140
130141 // Strip photos that the user deleted during this session
131142 // so a slow server response never resurrects them.
132143 const visibleFromServer = photographs .filter (
133144 (p ) => ! locallyDeletedIds .has (p .metaEnvelopeId ),
134145 );
135- const visibleIds = new Set (visibleFromServer .map ((p ) => p .metaEnvelopeId ));
146+ const visibleIds = new Set (
147+ visibleFromServer .map ((p ) => p .metaEnvelopeId ),
148+ );
136149
137150 // Photos in the store not in the server response were
138151 // uploaded after this fetch started — keep them.
139152 const localPending = current .photos .filter (
140- (p ) => p .dataUrl && p .metaEnvelopeId !== null && ! visibleIds .has (p .metaEnvelopeId ) && ! locallyDeletedIds .has (p .metaEnvelopeId ),
153+ (p ) =>
154+ p .dataUrl &&
155+ p .metaEnvelopeId !== null &&
156+ ! visibleIds .has (p .metaEnvelopeId ) &&
157+ ! locallyDeletedIds .has (p .metaEnvelopeId ),
141158 );
142159
143160 replaceAll ({
@@ -161,6 +178,7 @@ onMount(() => {
161178 metaEnvelopeId: p .metaEnvelopeId ,
162179 dataUrl: p .photoBlob ,
163180 description: p .description ,
181+ ename: ename ,
164182 }),
165183 ),
166184 );
@@ -170,7 +188,7 @@ onMount(() => {
170188 const localPendingIds = new Set (
171189 localPending .map ((p ) => p .metaEnvelopeId ),
172190 );
173- const allCached = await getAllCachedPhotos ( );
191+ const allCached = await getCachedPhotosForEname ( ename );
174192 await Promise .all (
175193 allCached
176194 .filter (
@@ -267,6 +285,7 @@ async function handlePhotoSave(data: {
267285 metaEnvelopeId: id ,
268286 dataUrl: data .dataUrl ,
269287 description: data .description ,
288+ ename: ename ?? " " ,
270289 });
271290 editingPhoto = null ;
272291
@@ -434,7 +453,7 @@ async function handleKnowledgeSave(data: {
434453{#snippet photosBody ()}
435454 {#if binding .photos .length > 0 || loading }
436455 <ul class =" flex flex-col gap-3 mt-3" >
437- {#each binding . photos as photo (photo .id )}
456+ {#each sortedPhotos as photo (photo .id )}
438457 {#if photo .dataUrl }
439458 <li class =" flex items-center gap-3" >
440459 <img
0 commit comments