Skip to content

Commit b8927bd

Browse files
committed
refactor: simplify type definitions and improve plugin import handling in OerImagePicker
1 parent 610d5b0 commit b8927bd

File tree

1 file changed

+13
-46
lines changed

1 file changed

+13
-46
lines changed

src/lib/components/OerImagePicker.svelte

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,15 @@
11
<script lang="ts">
2+
import type {
3+
OerSearchResultEvent,
4+
OerSearchElement,
5+
OerListElement,
6+
OerCardClickEvent,
7+
SourceConfig,
8+
LoadMoreElement
9+
} from '@edufeed-org/oer-finder-plugin';
210
import { onMount } from 'svelte';
311
import { settingsStore } from '$lib/stores/settingsStore.svelte';
4-
5-
type SourceConfig = {
6-
id: string;
7-
label: string;
8-
checked?: boolean;
9-
baseUrl?: string;
10-
};
11-
12-
type OerData = {
13-
extensions?: {
14-
images?: {
15-
high?: string;
16-
medium?: string;
17-
small?: string;
18-
} | null;
19-
};
20-
amb?: {
21-
id?: string;
22-
};
23-
};
24-
25-
type OerSearchResultEvent = CustomEvent<{
26-
data: OerData[];
27-
meta: unknown;
28-
}>;
29-
30-
type OerCardClickEvent = CustomEvent<{
31-
oer: OerData;
32-
}>;
33-
34-
type OerSearchElement = HTMLElement & {
35-
sources?: SourceConfig[];
36-
};
37-
38-
type OerListElement = HTMLElement & {
39-
loading: boolean;
40-
oers: unknown[];
41-
error?: string | null;
42-
};
43-
44-
type LoadMoreElement = HTMLElement & {
45-
loading: boolean;
46-
metadata: unknown;
47-
};
12+
import { registerAllBuiltInAdapters } from '@edufeed-org/oer-finder-plugin/adapters';
4813
4914
interface Props {
5015
onSelect: (imageUrl: string) => void;
@@ -55,6 +20,8 @@
5520
const language = $state(settingsStore.settings.language)
5621
const { onSelect }: Props = $props();
5722
23+
registerAllBuiltInAdapters();
24+
5825
const availableSources: SourceConfig[] = [
5926
{ id: 'arasaac', label: 'ARASAAC' },
6027
{ id: 'openverse', label: 'Openverse', checked: true },
@@ -68,8 +35,8 @@
6835
let loadMoreElement: LoadMoreElement;
6936
7037
onMount(async () => {
71-
const plugin = await import('@edufeed-org/oer-finder-plugin');
72-
plugin.registerAllBuiltInAdapters();
38+
// Dynamically import the plugin only on the client side to avoid SSR issues
39+
await import('@edufeed-org/oer-finder-plugin');
7340
7441
// Set sources as a JS property (not HTML attribute)
7542
searchEl.sources = availableSources;

0 commit comments

Comments
 (0)