mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
solved issue: error code removed and error page styled and close button added
This commit is contained in:
parent
d11b74fd38
commit
b536a497bb
5 changed files with 57 additions and 21 deletions
|
|
@ -160,7 +160,7 @@ importing-cards-added =
|
||||||
[one] { $count } card added.
|
[one] { $count } card added.
|
||||||
*[other] { $count } cards added.
|
*[other] { $count } cards added.
|
||||||
}
|
}
|
||||||
importing-file-empty = The file you selected is empty.
|
importing-file-empty = The selected file is empty. Please choose a valid file.
|
||||||
importing-notes-added =
|
importing-notes-added =
|
||||||
{ $count ->
|
{ $count ->
|
||||||
[one] { $count } new note imported.
|
[one] { $count } new note imported.
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,42 @@
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
Copyright: Ankitects Pty Ltd and contributors
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script context="module" lang="ts">
|
||||||
export let error: Error;
|
declare function pycmd(cmd: string);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="message">
|
<script lang="ts">
|
||||||
{error.message}
|
export let error: Error;
|
||||||
|
|
||||||
|
function closePage() {
|
||||||
|
try {
|
||||||
|
pycmd("close");
|
||||||
|
} catch {
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="error-box">
|
||||||
|
<p class="error-text">{error.message}</p>
|
||||||
|
<button class="btn btn-primary" on:click={closePage}>Got it</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.message {
|
.error-box {
|
||||||
text-align: center;
|
background-color: var(--window-bg);
|
||||||
margin: 50px 0 0;
|
border: 1px solid var(--error-fg);
|
||||||
}
|
color: var(--fg);
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
max-width: 400px;
|
||||||
|
margin: 1rem auto;
|
||||||
|
text-align: center;
|
||||||
|
box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
.error-text {
|
||||||
|
color: var(--error-fg);
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ async function postProtoInner(url: string, body: Uint8Array): Promise<Uint8Array
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
throw new Error(`${result.status}: ${msg}`);
|
// it is ugly to show internall server client status to user, we should just show error's to user
|
||||||
|
throw new Error(process.env.NODE_ENV === "production"?`${msg}`:`${result.status}: ${msg}`);
|
||||||
}
|
}
|
||||||
const blob = await result.blob();
|
const blob = await result.blob();
|
||||||
const respBuf = await new Response(blob).arrayBuffer();
|
const respBuf = await new Response(blob).arrayBuffer();
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,15 @@ Copyright: Ankitects Pty Ltd and contributors
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import ErrorPage from "$lib/components/ErrorPage.svelte";
|
||||||
import ImportCsvPage from "../ImportCsvPage.svelte";
|
import ImportCsvPage from "../ImportCsvPage.svelte";
|
||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types";
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ImportCsvPage state={data.state} />
|
{#if data.initialError}
|
||||||
|
<ErrorPage error={data.initialError} />
|
||||||
|
{:else}
|
||||||
|
<ImportCsvPage state={data.state} />
|
||||||
|
{/if}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,19 @@ import { ImportCsvState } from "../lib";
|
||||||
import type { PageLoad } from "./$types";
|
import type { PageLoad } from "./$types";
|
||||||
|
|
||||||
export const load = (async ({ params }) => {
|
export const load = (async ({ params }) => {
|
||||||
const [notetypes, decks, metadata] = await Promise.all([
|
try {
|
||||||
getNotetypeNames({}),
|
const [notetypes, decks, metadata] = await Promise.all([
|
||||||
getDeckNames({
|
getNotetypeNames({}),
|
||||||
skipEmptyDefault: false,
|
getDeckNames({
|
||||||
includeFiltered: false,
|
skipEmptyDefault: false,
|
||||||
}),
|
includeFiltered: false,
|
||||||
getCsvMetadata({ path: params.path }, { alertOnError: false }),
|
}),
|
||||||
]);
|
getCsvMetadata({ path: params.path }, { alertOnError: false }),
|
||||||
const state = new ImportCsvState(params.path, notetypes, decks, metadata);
|
]);
|
||||||
return { state };
|
const state = new ImportCsvState(params.path, notetypes, decks, metadata);
|
||||||
|
return { state };
|
||||||
|
} catch (error: any) {
|
||||||
|
const rawMsg = error?.message ?? String(error ?? "");
|
||||||
|
return { initialError: new Error(rawMsg) };
|
||||||
|
}
|
||||||
}) satisfies PageLoad;
|
}) satisfies PageLoad;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue