-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from ieedan/update-readme
- Loading branch information
Showing
10 changed files
with
283 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<script lang="ts"> | ||
import { Button } from '$lib/components/ui/button'; | ||
import { | ||
displaySize, | ||
FileDropZone, | ||
MEGABYTE, | ||
type FileDropZoneProps | ||
} from '$lib/components/ui/file-drop-zone'; | ||
import { Progress } from '$lib/components/ui/progress'; | ||
import { sleep } from '$lib/utils/sleep'; | ||
import { X } from 'lucide-svelte'; | ||
import { onDestroy } from 'svelte'; | ||
import { toast } from 'svelte-sonner'; | ||
import { SvelteDate } from 'svelte/reactivity'; | ||
const onUpload: FileDropZoneProps['onUpload'] = async (files) => { | ||
await Promise.allSettled(files.map((file) => uploadFile(file))); | ||
}; | ||
const onFileRejected: FileDropZoneProps['onFileRejected'] = async ({ reason, file }) => { | ||
toast.error(`${file.name} failed to upload!`, { description: reason }); | ||
}; | ||
const uploadFile = async (file: File) => { | ||
// don't upload duplicate files | ||
if (files.find((f) => f.name === file.name)) return; | ||
const urlPromise = new Promise<string>((resolve) => { | ||
// add some fake loading time | ||
sleep(1000).then(() => resolve(URL.createObjectURL(file))); | ||
}); | ||
files.push({ | ||
name: file.name, | ||
type: file.type, | ||
size: file.size, | ||
uploadedAt: Date.now(), | ||
url: urlPromise | ||
}); | ||
// we await since we don't want the onUpload to be complete until the files are actually uploaded | ||
await urlPromise; | ||
}; | ||
type UploadedFile = { | ||
name: string; | ||
type: string; | ||
size: number; | ||
uploadedAt: number; | ||
url: Promise<string>; | ||
}; | ||
let files = $state<UploadedFile[]>([]); | ||
let date = new SvelteDate(); | ||
onDestroy(async () => { | ||
for (const file of files) { | ||
URL.revokeObjectURL(await file.url); | ||
} | ||
}); | ||
$effect(() => { | ||
const interval = setInterval(() => { | ||
date.setTime(Date.now()); | ||
}, 10); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}); | ||
</script> | ||
|
||
<div class="flex w-full flex-col gap-2"> | ||
<FileDropZone | ||
{onUpload} | ||
{onFileRejected} | ||
maxFileSize={2 * MEGABYTE} | ||
accept="image/*" | ||
maxFiles={4} | ||
fileCount={files.length} | ||
/> | ||
<div class="flex flex-col gap-2"> | ||
{#each files as file, i} | ||
<div | ||
class="flex place-items-center justify-between gap-2 rounded-md border border-border p-2" | ||
> | ||
<div class="flex place-items-center gap-2"> | ||
{#await file.url then src} | ||
<div class="relative size-9 overflow-clip"> | ||
<img | ||
{src} | ||
alt={file.name} | ||
class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 overflow-clip" | ||
/> | ||
</div> | ||
{/await} | ||
<div class="flex flex-col"> | ||
<span class="text-nowrap">{file.name}</span> | ||
<span class="text-xs text-muted-foreground">{displaySize(file.size)}</span> | ||
</div> | ||
</div> | ||
{#await file.url} | ||
<Progress | ||
class="h-2 w-full flex-grow" | ||
value={((date.getTime() - file.uploadedAt) / 1000) * 100} | ||
max={100} | ||
/> | ||
{:then url} | ||
<Button | ||
variant="outline" | ||
size="icon" | ||
onclick={() => { | ||
URL.revokeObjectURL(url); | ||
files = [...files.slice(0, i), ...files.slice(i + 1)]; | ||
}} | ||
> | ||
<X /> | ||
</Button> | ||
{/await} | ||
</div> | ||
{/each} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script lang="ts"> | ||
import { PMCommand } from '$lib/components/ui/pm-command'; | ||
</script> | ||
|
||
<PMCommand command="execute" args={['jsrepo', 'add', 'ui/pm-command']} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script lang="ts"> | ||
import * as Terminal from '$lib/components/ui/terminal'; | ||
</script> | ||
|
||
<Terminal.Loop delay={5000}> | ||
<Terminal.Root class="h-[275px] leading-5"> | ||
<Terminal.TypingAnimation>jsrepo add ui/terminal</Terminal.TypingAnimation> | ||
<br /> | ||
<Terminal.AnimatedSpan delay={1400}> | ||
<span class="text-muted-foreground">┌</span> | ||
<span class="bg-yellow-400 px-2 text-black">jsrepo</span> | ||
<span class="text-muted-foreground">v1.0.0</span> | ||
</Terminal.AnimatedSpan> | ||
|
||
<Terminal.AnimatedSpan delay={1450} class="text-muted-foreground">│</Terminal.AnimatedSpan> | ||
|
||
<Terminal.Loading delay={1500}> | ||
{#snippet loadingMessage()} | ||
Fetching manifest from <span class="text-cyan-500">shadcn-svelte-extras</span> | ||
{/snippet} | ||
{#snippet completeMessage()} | ||
<span class="text-green-500">◇</span> Fetched manifest from | ||
<span class="text-cyan-500">shadcn-svelte-extras</span> | ||
{/snippet} | ||
</Terminal.Loading> | ||
|
||
<Terminal.AnimatedSpan delay={2650} class="text-muted-foreground">│</Terminal.AnimatedSpan> | ||
|
||
<Terminal.Loading delay={2750}> | ||
{#snippet loadingMessage()} | ||
Adding <span class="text-cyan-500">ui/terminal</span> | ||
{/snippet} | ||
{#snippet completeMessage()} | ||
<span class="text-green-500">◇</span> Added | ||
<span class="text-cyan-500">ui/terminal</span> | ||
{/snippet} | ||
</Terminal.Loading> | ||
<Terminal.AnimatedSpan delay={3850} class="text-muted-foreground">│</Terminal.AnimatedSpan> | ||
<Terminal.AnimatedSpan delay={3900} class="text-green-500"> | ||
<span class="text-muted-foreground">└</span> | ||
✓ All done! | ||
</Terminal.AnimatedSpan> | ||
</Terminal.Root> | ||
</Terminal.Loop> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.