Skip to content

Commit

Permalink
Refactor media picker
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowCait committed Oct 13, 2023
1 parent 6d88c73 commit c109649
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 1 addition & 13 deletions web/src/routes/editor/MediaPicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,16 @@
import { createEventDispatcher } from 'svelte';
import IconPhoto from '@tabler/icons-svelte/dist/svelte/icons/IconPhoto.svelte';
export let mediaFiles: File[] = [];
let input: HTMLInputElement | undefined;
let files: FileList;
const dispatch = createEventDispatcher();
function upload() {
dispatch('pick', files);
console.log('[media upload]', files);
for (const file of files) {
console.log('[media upload file]', file);
mediaFiles.push(file);
mediaFiles = mediaFiles;
}
}
</script>

<button on:click|preventDefault={() => input?.click()} class="clear">
<IconPhoto size="30" />
</button>
<input type="file" bind:this={input} bind:files on:change={upload} accept="image/*" hidden>
<input type="file" bind:this={input} bind:files on:change={() => dispatch('pick', files)} accept="image/*" hidden>

<style>
button {
Expand Down
15 changes: 14 additions & 1 deletion web/src/routes/editor/NoteEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
}
const file = files[files.length - 1];
console.log('[media file]', file);
try {
const media = new NostrcheckMe();
const { url } = await media.upload(file);
Expand Down Expand Up @@ -374,6 +375,18 @@
$mediaFiles.push(file);
$mediaFiles = $mediaFiles;
}
async function mediaPicked({detail: files}: {detail: FileList}): Promise<void> {
console.log('[media picked]', files);
if (files.length === 0) {
return;
}
for (const file of files) {
$mediaFiles.push(file);
$mediaFiles = $mediaFiles;
}
}
</script>

<article bind:this={article} class="note-editor">
Expand All @@ -394,7 +407,7 @@
/>
<div class="actions">
<div class="options">
<MediaPicker bind:mediaFiles={$mediaFiles} />
<MediaPicker on:pick={mediaPicked} />
<EmojiPickerSlide bind:this={emojiPickerSlide} on:pick={onEmojiPick} />
<ContentWarning bind:reason={contentWarningReason} />
</div>
Expand Down

0 comments on commit c109649

Please sign in to comment.