@@ -5,51 +5,67 @@ import { NavPage } from '@podman-desktop/ui-svelte';
5
5
import { bootcClient } from ' /@/api/client' ;
6
6
import ExamplesCard from ' ./ExamplesCard.svelte' ;
7
7
import { SvelteMap } from ' svelte/reactivity' ;
8
+ import { imageInfo } from ' /@/stores/imageInfo' ;
8
9
9
- let groups: Map <Category , Example []> = new Map ();
10
+ let baseExamples = $state <Example []>([]);
11
+ let baseCategories = $state <Category []>([]);
10
12
11
13
const UNCLASSIFIED: Category = {
12
14
id: ' unclassified' ,
13
15
name: ' Unclassified' ,
14
16
};
15
17
16
18
onMount (async () => {
17
- // onmount get the examples
18
- let examples = await bootcClient .getExamples ();
19
+ const data = await bootcClient .getExamples ();
20
+ baseExamples = data .examples ;
21
+ baseCategories = data .categories ;
22
+ });
23
+
24
+ const examplesWithState = $derived .by (() => {
25
+ const pulledImages = new Set ($imageInfo ?.map (image => image .RepoTags ?.[0 ] ?? ' ' ) ?? []);
26
+ return baseExamples .map (example => {
27
+ const exampleWithState: Example = {
28
+ ... example ,
29
+ state: pulledImages .has (` ${example .image }:${example .tag } ` ) ? ' pulled' : ' unpulled' ,
30
+ };
31
+ return exampleWithState ;
32
+ });
33
+ });
19
34
20
- const categoryDict = Object .fromEntries (examples .categories .map ((category : Category ) => [category .id , category ]));
35
+ const groups = $derived .by (() => {
36
+ const newGroups = new SvelteMap <Category , Example []>();
37
+ const categoryDict = Object .fromEntries (baseCategories .map (c => [c .id , c ]));
21
38
22
- const output: SvelteMap <Category , Example []> = new SvelteMap ();
39
+ for (const example of examplesWithState ) {
40
+ const addExampleToCategory = (key : Category ): void => {
41
+ const list = newGroups .get (key );
42
+ if (list ) {
43
+ list .push (example );
44
+ } else {
45
+ newGroups .set (key , [example ]);
46
+ }
47
+ };
23
48
24
- for (const example of examples .examples ) {
25
49
if (example .categories .length === 0 ) {
26
- output . set (UNCLASSIFIED , [ ... ( output . get ( UNCLASSIFIED ) ?? []), example ] );
50
+ addExampleToCategory (UNCLASSIFIED );
27
51
continue ;
28
52
}
29
53
30
- // iterate over all categories
31
54
for (const categoryId of example .categories ) {
32
- let key: Category ;
33
- if (categoryId in categoryDict ) {
34
- key = categoryDict [categoryId ];
35
- } else {
36
- key = UNCLASSIFIED ;
37
- }
38
-
39
- output .set (key , [... (output .get (key ) ?? []), example ]);
55
+ const key = categoryDict [categoryId ] ?? UNCLASSIFIED ;
56
+ addExampleToCategory (key );
40
57
}
41
58
}
42
-
43
- groups = output ;
59
+ return newGroups ;
44
60
});
45
61
</script >
46
62
47
63
<NavPage title ="Examples" searchEnabled ={false }>
48
64
<div slot =" content" class =" flex flex-col min-w-full min-h-full" >
49
65
<div class =" min-w-full min-h-full flex-1" >
50
66
<div class =" px-5 space-y-5" >
51
- {#each groups .entries () as [category, examples](category .id )}
52
- <ExamplesCard category = {category } examples = {examples } />
67
+ {#each groups .entries () as [category, examples] (category .id )}
68
+ <ExamplesCard {category } {examples } />
53
69
{/each }
54
70
</div >
55
71
</div >
0 commit comments