mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: file upload error
This commit is contained in:
parent
0b36b96802
commit
42c297d9d5
4 changed files with 39 additions and 6 deletions
|
|
@ -2,16 +2,25 @@
|
|||
import { fetchSubmProgress } from '$lib/stores/portfolio';
|
||||
import { apiUploadCoverLetter } from '$lib/@api/candidate';
|
||||
import DashboardUploadCard from './DashboardUploadCard.svelte';
|
||||
import type { ApiError } from '$lib/@api';
|
||||
|
||||
let error: string | null = null;
|
||||
|
||||
const onFileDrop = async (detail: any) => {
|
||||
const file = detail.file;
|
||||
const callback = detail.callback;
|
||||
await apiUploadCoverLetter(file, callback);
|
||||
try {
|
||||
await apiUploadCoverLetter(file, callback);
|
||||
error = null;
|
||||
} catch (e) {
|
||||
error = (e as ApiError).msg;
|
||||
}
|
||||
await fetchSubmProgress();
|
||||
};
|
||||
</script>
|
||||
|
||||
<DashboardUploadCard
|
||||
{error}
|
||||
on:filedrop={(e) => onFileDrop(e.detail)}
|
||||
title="Motivační dopis"
|
||||
filetype="PDF"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let error: string | null = null;
|
||||
|
||||
export let title: string;
|
||||
export let filetype: 'PDF' | 'ZIP';
|
||||
export let filesize: number;
|
||||
|
|
@ -105,7 +107,7 @@
|
|||
<StatusNotificationDot {status} />
|
||||
</div>
|
||||
</div>
|
||||
{#if fileDropped}
|
||||
{#if fileDropped && error === null}
|
||||
<div class="body uploaded flex content-around items-center justify-between">
|
||||
<div class="w-24">
|
||||
<img
|
||||
|
|
@ -161,8 +163,12 @@
|
|||
on:mouseleave={dashAnimationStop}
|
||||
style={`background-image: url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' rx='9' ry='9' stroke-opacity='50%' stroke='%23406280' stroke-width='4' stroke-dasharray='10' stroke-dashoffset='${dashAnimationProgress}' stroke-linecap='square'/%3e%3c/svg%3e");`}
|
||||
>
|
||||
<span class="text-[#406280]">Sem přetáhněte,</span>
|
||||
<span class="text-sspsGray">nebo nahrajte {placeholder}</span>
|
||||
{#if error}
|
||||
<span class="font-semibold text-red-600">{error}</span>
|
||||
{:else}
|
||||
<span class="text-[#406280]">Sem přetáhněte,</span>
|
||||
<span class="text-sspsGray">nebo nahrajte {placeholder}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,26 @@
|
|||
<script lang="ts">
|
||||
import type { ApiError } from '$lib/@api';
|
||||
import { fetchSubmProgress } from '$lib/stores/portfolio';
|
||||
import { apiUploadPortfolioLetter } from '../../@api/candidate';
|
||||
import DashboardUploadCard from './DashboardUploadCard.svelte';
|
||||
|
||||
let error: string | null = null;
|
||||
|
||||
const onFileDrop = async (detail: any) => {
|
||||
const file = detail.file;
|
||||
const callback = detail.callback;
|
||||
await apiUploadPortfolioLetter(file, callback);
|
||||
try {
|
||||
await apiUploadPortfolioLetter(file, callback);
|
||||
error = null;
|
||||
} catch (e) {
|
||||
error = (e as ApiError).msg;
|
||||
}
|
||||
await fetchSubmProgress();
|
||||
};
|
||||
</script>
|
||||
|
||||
<DashboardUploadCard
|
||||
{error}
|
||||
on:filedrop={(e) => onFileDrop(e.detail)}
|
||||
title="Portfolio"
|
||||
filetype="PDF"
|
||||
|
|
|
|||
|
|
@ -2,16 +2,25 @@
|
|||
import { fetchSubmProgress } from '$lib/stores/portfolio';
|
||||
import { apiUploadPortfolioZip } from '$lib/@api/candidate';
|
||||
import DashboardUploadCard from './DashboardUploadCard.svelte';
|
||||
import type { ApiError } from '$lib/@api';
|
||||
|
||||
let error: string | null = null;
|
||||
|
||||
const onFileDrop = async (detail: any) => {
|
||||
const file = detail.file;
|
||||
const callback = detail.callback;
|
||||
await apiUploadPortfolioZip(file, callback);
|
||||
try {
|
||||
await apiUploadPortfolioZip(file, callback);
|
||||
error = null;
|
||||
} catch (e) {
|
||||
error = (e as ApiError).msg;
|
||||
}
|
||||
await fetchSubmProgress();
|
||||
};
|
||||
</script>
|
||||
|
||||
<DashboardUploadCard
|
||||
{error}
|
||||
on:filedrop={(e) => onFileDrop(e.detail)}
|
||||
title="Další data"
|
||||
filetype="ZIP"
|
||||
|
|
|
|||
Loading…
Reference in a new issue