Skip to content

Commit d9a048b

Browse files
committed
Track status of IIcons
1 parent d9b958a commit d9a048b

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/components/Editor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'ace-code/styles/theme/tomorrow.css';
1717
import * as RDT from '@/editor/rdt';
1818
1919
import type ISelection from '@/types/selection';
20-
import type IIcon from '@/types/icon';
20+
import type { IIcon } from '@/types/icon';
2121
2222
import bindEditorValue from '@/composables/bindEditorValue';
2323
import bindEditorSelection from '@/composables/bindEditorSelection';
@@ -69,7 +69,7 @@ class Completer implements Ace.Completer {
6969
7070
getCompletions(_editor: Ace.Editor, _session: Ace.EditSession, _pos: Ace.Point, _prefix: string, callback: Ace.CompleterCallback): void {
7171
callback(null, Object.keys(props.icons)
72-
.filter((icon) => !!props.icons[icon])
72+
.filter((icon) => props.icons[icon]?.status == 'ready')
7373
.map((icon) => ({ value: icon })));
7474
}
7575

src/stores/icon.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
22
import { ref } from 'vue';
33
import md5 from 'md5';
44

5-
import type IIcon from '@/types/icon';
5+
import type { IIcon } from '@/types/icon';
66

77
const baseUrl = 'https://upload.wikimedia.org/wikipedia/commons';
88

@@ -16,25 +16,25 @@ function loadImage(url: string): Promise<HTMLImageElement> {
1616
}
1717

1818
export const useIconStore = defineStore('icon', () => {
19-
const icons = ref<Record<string, IIcon | null>>({});
19+
const icons = ref<Record<string, IIcon>>({});
2020

21-
function patch(name: string, icon: IIcon | null): void {
21+
function patch(name: string, icon: IIcon): void {
2222
icons.value = {
2323
...icons.value,
2424
[name]: icon,
2525
};
2626
}
2727

2828
function fetching(name: string): void {
29-
patch(name, null);
29+
patch(name, { status: 'loading' });
3030
}
3131

3232
function fetched(name: string, data: string) {
33-
patch(name, { data, ratio: 1 });
33+
patch(name, { status: 'ready', data, ratio: 1 });
3434
}
3535

3636
function failed(name: string): void {
37-
patch(name, null);
37+
patch(name, { status: 'failed' });
3838
}
3939

4040
function resolved(name: string, ratio: number) {

src/types/icon.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
export default interface IIcon {
1+
export type IIcon = {
2+
status: string;
3+
data?: string;
4+
ratio?: number;
5+
} & ({
6+
status: 'loading';
7+
} | {
8+
status: 'failed';
9+
} | {
10+
status: 'ready';
211
data: string;
312
ratio: number;
4-
}
13+
});

0 commit comments

Comments
 (0)