Skip to content

Commit 6aa6354

Browse files
committed
formatting and add sw to tsconfig
1 parent d56ed92 commit 6aa6354

File tree

4 files changed

+48
-98
lines changed

4 files changed

+48
-98
lines changed

public/sw.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const URLS_TO_CACHE = [
44
"/index.html",
55
"/manifest.json",
66
"/icon.png",
7+
"/icons/icon-192x192.png",
8+
"/icons/icon-512x512.png",
79
"/Inter-Regular.woff2",
810
];
911

@@ -12,7 +14,7 @@ self.addEventListener("install", (event) => {
1214
caches
1315
.open(CACHE_NAME)
1416
.then((cache) => cache.addAll(URLS_TO_CACHE))
15-
.then(() => self.skipWaiting()),
17+
.then(() => self.skipWaiting())
1618
);
1719
});
1820

@@ -22,27 +24,27 @@ self.addEventListener("activate", (event) => {
2224
.keys()
2325
.then((keys) =>
2426
Promise.all(
25-
keys.map((key) => key !== CACHE_NAME && caches.delete(key)),
26-
),
27+
keys.map((key) => (key !== CACHE_NAME ? caches.delete(key) : Promise.resolve()))
28+
)
2729
)
28-
.then(() => self.clients.claim()),
30+
.then(() => self.clients.claim())
2931
);
3032
});
3133

3234
self.addEventListener("fetch", (event) => {
3335
if (event.request.method !== "GET") return;
36+
3437
event.respondWith(
35-
caches.match(event.request).then((cached) => {
36-
return (
37-
cached ||
38-
fetch(event.request).then((res) => {
39-
const resClone = res.clone();
40-
caches.open(CACHE_NAME).then((cache) => {
41-
cache.put(event.request, resClone);
42-
});
43-
return res;
44-
})
45-
);
46-
}),
38+
(async () => {
39+
const cached = await caches.match(event.request);
40+
if (cached) return cached;
41+
42+
const response = await fetch(event.request);
43+
const clone = response.clone();
44+
45+
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone)));
46+
47+
return response;
48+
})()
4749
);
4850
});

src/components/IMEField.tsx

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ type LastConversion = {
4444
end: number;
4545
};
4646

47-
const [jishoCache, setJishoCache] = createStorageSignal<
48-
Record<string, string[]>
49-
>("jisho-cache", {});
47+
const [jishoCache, setJishoCache] = createStorageSignal<Record<string, string[]>>(
48+
"jisho-cache",
49+
{}
50+
);
5051

5152
async function fetchKanjiFromJisho(reading: string): Promise<string[]> {
5253
if (!reading) return [];
@@ -57,9 +58,7 @@ async function fetchKanjiFromJisho(reading: string): Promise<string[]> {
5758
}
5859

5960
const JISHO_PROXY_BASE = "https://cors-anywhere.com/";
60-
const jishoUrl =
61-
"https://jisho.org/api/v1/search/words?keyword=" +
62-
encodeURIComponent(reading);
61+
const jishoUrl = "https://jisho.org/api/v1/search/words?keyword=" + encodeURIComponent(reading);
6362

6463
const proxyUrl = JISHO_PROXY_BASE + jishoUrl;
6564
const hiragana = wanakana.toHiragana(reading);
@@ -68,17 +67,13 @@ async function fetchKanjiFromJisho(reading: string): Promise<string[]> {
6867
try {
6968
const res = await fetch(proxyUrl);
7069
if (!res.ok) {
71-
console.error(
72-
`Error fetching from CORS proxy: ${res.status} ${res.statusText}`,
73-
);
70+
console.error(`Error fetching from CORS proxy: ${res.status} ${res.statusText}`);
7471
return [hiragana, katakana];
7572
}
7673
const json = (await res.json()) as JishoResponse;
7774
if (!json?.data) return [hiragana, katakana];
7875

79-
const unique = new Set(
80-
json.data.map((e) => e.japanese[0].word || e.japanese[0].reading),
81-
);
76+
const unique = new Set(json.data.map((e) => e.japanese[0].word || e.japanese[0].reading));
8277
const results = [...new Set([hiragana, katakana, ...Array.from(unique)])];
8378

8479
setJishoCache((prev) => ({ ...prev, [reading]: results }));
@@ -106,9 +101,7 @@ export function IMEField() {
106101
const [isMenuOpen, setIsMenuOpen] = createSignal(false);
107102
const [confirmedIndex, setConfirmedIndex] = createSignal(0);
108103
const [isComposing, setIsComposing] = createSignal(false);
109-
const [conversionHistory, setConversionHistory] = createSignal<
110-
LastConversion[]
111-
>([]);
104+
const [conversionHistory, setConversionHistory] = createSignal<LastConversion[]>([]);
112105
const [copied, setCopied] = createSignal(false);
113106

114107
let ta: HTMLTextAreaElement | undefined;
@@ -166,10 +159,7 @@ export function IMEField() {
166159
ta.value = newVal;
167160
ta.setSelectionRange(newPos, newPos);
168161
}
169-
setConversionHistory((prev) => [
170-
...prev,
171-
{ confirmed: cand, reading, start, end: newPos },
172-
]);
162+
setConversionHistory((prev) => [...prev, { confirmed: cand, reading, start, end: newPos }]);
173163
setLookupReading(null);
174164
setSelectedIndex(0);
175165
setIsMenuOpen(false);
@@ -189,9 +179,7 @@ export function IMEField() {
189179
}
190180
}
191181

192-
function handleKeyDown(
193-
e: KeyboardEvent & { currentTarget: HTMLTextAreaElement },
194-
) {
182+
function handleKeyDown(e: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {
195183
if (isMenuOpen()) {
196184
if (e.key === "Enter" || e.key === " ") {
197185
e.preventDefault();
@@ -203,9 +191,7 @@ export function IMEField() {
203191
}
204192
if (e.key === "ArrowUp") {
205193
e.preventDefault();
206-
setSelectedIndex(
207-
(prev) => (prev - 1 + suggestions().length) % suggestions().length,
208-
);
194+
setSelectedIndex((prev) => (prev - 1 + suggestions().length) % suggestions().length);
209195
}
210196
return;
211197
}
@@ -268,16 +254,12 @@ export function IMEField() {
268254
setIsComposing(val.length > currentConfirmedIndex);
269255
}
270256

271-
function handleCompositionStart(
272-
e: CompositionEvent & { currentTarget: HTMLTextAreaElement },
273-
) {
257+
function handleCompositionStart(e: CompositionEvent & { currentTarget: HTMLTextAreaElement }) {
274258
setIsComposing(true);
275259
setCompositionStart(e.currentTarget.selectionStart);
276260
}
277261

278-
function handleCompositionEnd(
279-
e: CompositionEvent & { currentTarget: HTMLTextAreaElement },
280-
) {
262+
function handleCompositionEnd(e: CompositionEvent & { currentTarget: HTMLTextAreaElement }) {
281263
setIsComposing(false);
282264
const start = compositionStart();
283265
const pos = e.currentTarget.selectionStart;
@@ -302,22 +284,17 @@ export function IMEField() {
302284

303285
return (
304286
<div class="relative w-full">
305-
<DropdownMenu
306-
open={isMenuOpen()}
307-
onOpenChange={setIsMenuOpen}
308-
placement="bottom-start"
309-
>
287+
<DropdownMenu open={isMenuOpen()} onOpenChange={setIsMenuOpen} placement="bottom-start">
310288
<DropdownMenuTrigger as="div" class="w-full outline-none" disabled>
311289
<TextField>
312290
<div class="relative w-full">
313-
<div class="absolute right-2 top-2 z-20 flex items-center space-x-2">
291+
<div class="absolute top-2 right-2 z-20 flex items-center space-x-2">
314292
<Show when={unconfirmedText().length > 0 && !isMenuOpen()}>
315293
<Button
316294
onClick={handleConvert}
317295
size="sm"
318296
variant="default"
319-
class="block lg:hidden"
320-
>
297+
class="block lg:hidden">
321298
Convert
322299
</Button>
323300
</Show>
@@ -330,8 +307,7 @@ export function IMEField() {
330307
<CopyIcon class="h-4 w-4" />
331308
<span>Copy</span>
332309
</>
333-
}
334-
>
310+
}>
335311
<CheckIcon class="h-4 w-4" />
336312
<span>Copied!</span>
337313
</Show>
@@ -340,12 +316,9 @@ export function IMEField() {
340316
</div>
341317
<div
342318
aria-hidden="true"
343-
class="pointer-events-none absolute inset-0 select-none whitespace-pre-wrap px-3 py-2 text-base"
344-
>
319+
class="pointer-events-none absolute inset-0 px-3 py-2 text-base whitespace-pre-wrap select-none">
345320
<span>{confirmedText()}</span>
346-
<span class="border-b border-dotted border-current">
347-
{unconfirmedText()}
348-
</span>
321+
<span class="border-b border-dotted border-current">{unconfirmedText()}</span>
349322
</div>
350323
<TextFieldTextArea
351324
autoResize
@@ -368,17 +341,13 @@ export function IMEField() {
368341
onCloseAutoFocus={(e) => {
369342
e.preventDefault();
370343
ta?.focus();
371-
}}
372-
>
344+
}}>
373345
<Suspense fallback={<Spinner />}>
374346
<Show
375347
when={suggestions()?.length > 0}
376348
fallback={
377-
<div class="text-muted-foreground px-2 py-1.5 text-sm">
378-
No results found.
379-
</div>
380-
}
381-
>
349+
<div class="text-muted-foreground px-2 py-1.5 text-sm">No results found.</div>
350+
}>
382351
<div ref={listRef} class="max-h-[13rem] overflow-y-auto">
383352
<For each={suggestions()}>
384353
{(s, idx) => (
@@ -387,8 +356,7 @@ export function IMEField() {
387356
onSelect={() => commitSuggestion(idx())}
388357
onFocus={() => setSelectedIndex(idx())}
389358
data-highlighted={selectedIndex() === idx()}
390-
class="data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground scroll-m-1"
391-
>
359+
class="data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground scroll-m-1">
392360
{s}
393361
</DropdownMenuItem>
394362
)}

src/entry-server.tsx

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,9 @@ export default createHandler(() => (
1818
<meta name="mobile-web-app-capable" content="yes" />
1919
<meta name="apple-mobile-web-app-capable" content="yes" />
2020
<meta name="apple-mobile-web-app-title" content="QuickIME" />
21-
<meta
22-
name="apple-mobile-web-app-status-bar-style"
23-
content="default"
24-
/>
25-
<link
26-
rel="apple-touch-icon"
27-
sizes="192x192"
28-
href="/icons/-192x192.png"
29-
/>
30-
<link
31-
rel="apple-touch-icon"
32-
sizes="512x512"
33-
href="/icons/-512x512.png"
34-
/>
21+
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
22+
<link rel="apple-touch-icon" sizes="192x192" href="/icons/-192x192.png" />
23+
<link rel="apple-touch-icon" sizes="512x512" href="/icons/-512x512.png" />
3524
<meta
3625
property="og:title"
3726
content="QuickIME – An Input Method Editor that doesn't suck"
@@ -52,18 +41,9 @@ export default createHandler(() => (
5241
name="twitter:description"
5342
content="A local-first Input Method Editor (IME) for Japanese, aiming for a fast and frustration-free experience. Since all IME's on Linux/Windows/Android are annoying or slow."
5443
/>
55-
<meta
56-
property="og:image"
57-
content="https://xlc-dev.github.io/QuickIME/icon.png"
58-
/>
59-
<meta
60-
name="twitter:image"
61-
content="https://xlc-dev.github.io/QuickIME/icon.png"
62-
/>
63-
<meta
64-
property="og:url"
65-
content="https://xlc-dev.github.io/QuickIME/"
66-
/>
44+
<meta property="og:image" content="https://xlc-dev.github.io/QuickIME/icon.png" />
45+
<meta name="twitter:image" content="https://xlc-dev.github.io/QuickIME/icon.png" />
46+
<meta property="og:url" content="https://xlc-dev.github.io/QuickIME/" />
6747

6848
{assets}
6949
</head>

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"isolatedModules": true,
1818
"skipLibCheck": true
1919
},
20-
"include": ["src/**/*", "app.config.ts", "eslint.config.js"],
20+
"include": ["src/**/*", "app.config.ts", "eslint.config.js", "public/sw.js"],
2121
"exclude": ["node_modules", ".output", ".vinxi"]
2222
}

0 commit comments

Comments
 (0)