diff --git a/src/components/ErrorComponent.tsx b/src/components/ErrorComponent.tsx index 640325b0..7a12b2d8 100644 --- a/src/components/ErrorComponent.tsx +++ b/src/components/ErrorComponent.tsx @@ -13,14 +13,14 @@ import { useNavigate } from "@tanstack/react-router"; export default function ErrorComponent({ error, }: { - error: any; + error: unknown; }) { const navigate = useNavigate(); return ( An error ocurred - {error instanceof Error && ( + {error instanceof Error ? ( <> {error.name}: {error.message} @@ -28,6 +28,10 @@ export default function ErrorComponent({ {error.stack} {error.cause} + ) : ( + + Unexpected Error: {JSON.stringify(error)} + )} {error instanceof Error && ( diff --git a/src/components/boards/AnnotationHint.tsx b/src/components/boards/AnnotationHint.tsx index 6081cc24..c0beeeb1 100644 --- a/src/components/boards/AnnotationHint.tsx +++ b/src/components/boards/AnnotationHint.tsx @@ -30,7 +30,7 @@ export default function AnnotationHint({ }} > - {isBasicAnnotation(annotation) && ( + { {glyphToSvg[annotation]} - )} + } ); } // taken from lichess https://github.com/lichess-org/lila/blob/b7d9abb9f624b1525804aeb49a5b2678f23aae09/ui/analyse/src/glyphs.ts#L49C1-L85 -const glyphToSvg = { - "?!": ( +const glyphToSvg: Record = { + "": <>, + "!": ( <> + + ), + "!!": ( + <> + ), @@ -97,25 +106,158 @@ const glyphToSvg = { ), - "!": ( + "?!": ( <> ), - "!!": ( + "+-": ( <> + + ), + "±": ( + <> + + + ), + "⩲": ( + <> + + + ), + "=": ( + <> + + + ), + "∞": ( + <> + + + ), + "⩱": ( + <> + + + ), + "∓": ( + <> + + + ), + "-+": ( + <> + + + ), + N: ( + <> + + + ), + "↑↑": ( + <> + + + ), + "↑": ( + <> + + + ), + "→": ( + <> + + + ), + "⇆": ( + <> + + + ), + "=∞": ( + <> + + + ), + "⊕": ( + <> + + + ), + "∆": ( + <> + + + ), + "□": ( + <> + + + ), + "⨀": ( + <> + ), diff --git a/src/components/files/FilesPage.tsx b/src/components/files/FilesPage.tsx index 8f57acc4..6061d7b2 100644 --- a/src/components/files/FilesPage.tsx +++ b/src/components/files/FilesPage.tsx @@ -12,7 +12,7 @@ import { import { useToggle } from "@mantine/hooks"; import { IconPlus, IconSearch, IconX } from "@tabler/icons-react"; import { useLoaderData } from "@tanstack/react-router"; -import { readDir, removeFile } from "@tauri-apps/api/fs"; +import { type FileEntry, readDir, removeFile } from "@tauri-apps/api/fs"; import React, { useEffect, useState } from "react"; import useSWR from "swr"; import ConfirmModal from "../common/ConfirmModal"; @@ -39,9 +39,16 @@ export type MetadataOrEntry = { async function processFiles( files: MetadataOrEntry[], ): Promise { - const filesInfo = await Promise.all( - files.map((f) => readFileMetadata(f.name, f.path, f.children)), - ); + const filesInfo = ( + await Promise.allSettled( + files.map((f) => readFileMetadata(f.name, f.path, f.children)), + ) + ) + .filter((r) => r.status === "fulfilled") + .map( + (r) => + (r as PromiseFulfilledResult).value, + ); for (let i = 0; i < files.length; i++) { const file = files[i]; if (file.children) { diff --git a/src/components/home/Databases.tsx b/src/components/home/Databases.tsx index afb71b2b..ed2c4ee3 100644 --- a/src/components/home/Databases.tsx +++ b/src/components/home/Databases.tsx @@ -158,7 +158,7 @@ function Databases() { async () => { const playerDbs = playerDbNames.find((p) => p.name === name)?.databases; if (!databases || !playerDbs) return []; - const newInfo: PersonalInfo[] = await Promise.all( + const results = await Promise.allSettled( databases .filter((db) => playerDbs.includes(db.title || "")) .map(async (db, i) => { @@ -172,7 +172,7 @@ function Databases() { if (players.data.length > 0) { player = players.data[0]; } else { - throw "Player not found in database"; + throw new Error("Player not found in database"); } const info = unwrap( await commands.getPlayersGameInfo(db.file, player.id), @@ -180,7 +180,9 @@ function Databases() { return { db, info }; }), ); - return newInfo; + return results + .filter((r) => r.status === "fulfilled") + .map((r) => (r as PromiseFulfilledResult).value); }, ); diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 0caa691b..8734b046 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -7,6 +7,7 @@ import TopBar from "@/components/TopBar"; import { openFile } from "@/utils/files"; import { createTab } from "@/utils/tabs"; import { AppShell } from "@mantine/core"; +import { notifications } from "@mantine/notifications"; import { Outlet, createRootRouteWithContext, @@ -14,7 +15,7 @@ import { } from "@tanstack/react-router"; import { ask, message, open } from "@tauri-apps/api/dialog"; import { listen } from "@tauri-apps/api/event"; -import { appDataDir, resolve } from "@tauri-apps/api/path"; +import { appLogDir, resolve } from "@tauri-apps/api/path"; import { open as shellOpen } from "@tauri-apps/api/shell"; import { checkUpdate, installUpdate } from "@tauri-apps/api/updater"; import { appWindow } from "@tauri-apps/api/window"; @@ -143,12 +144,11 @@ function RootLayout() { label: "Open Logs", id: "logs", action: async () => { - const appDataDirPath = await appDataDir(); - const path = await resolve( - appDataDirPath, - "logs", - "en-croissant.log", - ); + const path = await resolve(await appLogDir(), "en-croissant.log"); + notifications.show({ + title: "Logs", + message: `Opened logs in ${path}`, + }); await shellOpen(path); }, }, diff --git a/src/utils/db.ts b/src/utils/db.ts index 273ce71e..7e229818 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -181,7 +181,9 @@ export async function query_tournaments( export async function getDatabases(): Promise { const files = await readDir("db", { dir: BaseDirectory.AppData }); const dbs = files.filter((file) => file.name?.endsWith(".db3")); - return await Promise.all(dbs.map((db) => getDatabase(db.path))); + return (await Promise.allSettled(dbs.map((db) => getDatabase(db.path)))) + .filter((r) => r.status === "fulfilled") + .map((r) => (r as PromiseFulfilledResult).value); } export async function getDatabase(path: string): Promise { diff --git a/src/utils/invoke.tsx b/src/utils/invoke.tsx index 3e1227c5..5533e5a8 100644 --- a/src/utils/invoke.tsx +++ b/src/utils/invoke.tsx @@ -40,5 +40,5 @@ export function unwrap(result: Result): T { color: "red", icon: , }); - throw result.error; + throw new Error(result.error); } diff --git a/src/utils/puzzles.ts b/src/utils/puzzles.ts index 646d8500..5e0ae2b3 100644 --- a/src/utils/puzzles.ts +++ b/src/utils/puzzles.ts @@ -32,9 +32,7 @@ export async function getPuzzleDatabase(path: string): Promise { export async function getPuzzleDatabases(): Promise { const files = await readDir("puzzles", { dir: BaseDirectory.AppData }); const dbs = files.filter((file) => file.name?.endsWith(".db3")); - return ( - await Promise.all( - dbs.map((db) => getPuzzleDatabase(db.path).catch(() => null)), - ) - ).filter((db) => db !== null) as PuzzleDatabase[]; + return (await Promise.allSettled(dbs.map((db) => getPuzzleDatabase(db.path)))) + .filter((r) => r.status === "fulfilled") + .map((r) => (r as PromiseFulfilledResult).value); }