feat: add nsfw toggle
This commit is contained in:
1 parent
dbc0f6f5bb
commit
bca08af577
5 files changed
+95
-19
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.7.2",
|
"version": "0.7.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
|
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||||
|
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||||
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
|
import { uploadImage } from '$lib/lemmy.js'
|
||||||
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
|
||||||
|
export let open: boolean
|
||||||
|
export let image: FileList | null = null
|
||||||
|
let loading = false
|
||||||
|
|
||||||
|
const dispatcher = createEventDispatcher<{ upload: string }>()
|
||||||
|
|
||||||
|
async function upload() {
|
||||||
|
if (!$profile?.jwt || image == null) return
|
||||||
|
|
||||||
|
loading = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const uploaded = await uploadImage(image[0])
|
||||||
|
|
||||||
|
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||||
|
|
||||||
|
dispatcher('upload', uploaded)
|
||||||
|
loading = false
|
||||||
|
} catch (err) {
|
||||||
|
toast({
|
||||||
|
content: err as any,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
loading = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal bind:open>
|
||||||
|
<span slot="title">Upload image</span>
|
||||||
|
<form class="flex flex-col gap-4" on:submit|preventDefault={upload}>
|
||||||
|
<FileInput
|
||||||
|
accept="image/jpeg,image/png,image/webp"
|
||||||
|
image
|
||||||
|
bind:files={image}
|
||||||
|
/>
|
||||||
|
<Button {loading} disabled={loading} submit color="primary" size="lg">
|
||||||
|
Upload
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
@@ -8,10 +8,11 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||||
import SearchInput from '$lib/components/input/SearchInput.svelte'
|
import SearchInput from '$lib/components/input/SearchInput.svelte'
|
||||||
import { Check, Icon } from 'svelte-hero-icons'
|
import { Check, Icon, Photo } from 'svelte-hero-icons'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { placeholders } from '$lib/util.js'
|
import { placeholders } from '$lib/util.js'
|
||||||
|
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||||
|
|
||||||
export let edit = false
|
export let edit = false
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
body: string
|
body: string
|
||||||
image: FileList | null
|
image: FileList | null
|
||||||
url: string | undefined
|
url: string | undefined
|
||||||
|
nsfw: boolean
|
||||||
loading: boolean
|
loading: boolean
|
||||||
} = {
|
} = {
|
||||||
community: null,
|
community: null,
|
||||||
@@ -40,6 +42,7 @@
|
|||||||
body: '',
|
body: '',
|
||||||
image: null,
|
image: null,
|
||||||
url: undefined,
|
url: undefined,
|
||||||
|
nsfw: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@
|
|||||||
body: data.body,
|
body: data.body,
|
||||||
url: data.url || undefined,
|
url: data.url || undefined,
|
||||||
post_id: editingPost.id,
|
post_id: editingPost.id,
|
||||||
|
nsfw: data.nsfw,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!post) throw new Error('Failed to edit post')
|
if (!post) throw new Error('Failed to edit post')
|
||||||
@@ -120,6 +124,7 @@
|
|||||||
name: data.title,
|
name: data.title,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
url: data.url,
|
url: data.url,
|
||||||
|
nsfw: data.nsfw,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!post) throw new Error('Failed to upload post')
|
if (!post) throw new Error('Failed to upload post')
|
||||||
@@ -134,8 +139,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let communitySearch = ''
|
let communitySearch = ''
|
||||||
|
|
||||||
|
let uploadingImage = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if uploadingImage}
|
||||||
|
{#await import('$lib/components/lemmy/modal/ImageUploadModal.svelte') then { default: UploadModal }}
|
||||||
|
<UploadModal
|
||||||
|
bind:open={uploadingImage}
|
||||||
|
on:upload={(e) => {
|
||||||
|
if (e.detail) data.url = e.detail
|
||||||
|
uploadingImage = false
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/await}
|
||||||
|
{/if}
|
||||||
|
|
||||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4">
|
<form on:submit|preventDefault={submit} class="flex flex-col gap-4">
|
||||||
<slot name="formtitle">
|
<slot name="formtitle">
|
||||||
<h1 class="font-bold text-xl">
|
<h1 class="font-bold text-xl">
|
||||||
@@ -192,26 +211,29 @@
|
|||||||
bind:value={data.title}
|
bind:value={data.title}
|
||||||
placeholder={placeholders.get('post')}
|
placeholder={placeholders.get('post')}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<div class="flex gap-2 w-full items-end">
|
||||||
label="URL"
|
<TextInput
|
||||||
bind:value={data.url}
|
label="URL"
|
||||||
placeholder={placeholders.get('url')}
|
bind:value={data.url}
|
||||||
/>
|
placeholder={placeholders.get('url')}
|
||||||
|
class="w-full"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="square-md"
|
||||||
|
on:click={() => (uploadingImage = !uploadingImage)}
|
||||||
|
style="width: 46px !important; height: 42px; padding: 0;"
|
||||||
|
>
|
||||||
|
<Icon src={Photo} size="18" mini slot="icon" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
rows={9}
|
rows={8}
|
||||||
label="Body"
|
label="Body"
|
||||||
bind:value={data.body}
|
bind:value={data.body}
|
||||||
placeholder={placeholders.get('post')}
|
placeholder={placeholders.get('post')}
|
||||||
previewButton
|
previewButton
|
||||||
/>
|
/>
|
||||||
<div>
|
<Checkbox bind:checked={data.nsfw}>NSFW</Checkbox>
|
||||||
<span class="block my-1 font-bold text-sm">Image</span>
|
|
||||||
<FileInput
|
|
||||||
accept="image/jpeg,image/png,image/webp"
|
|
||||||
image
|
|
||||||
bind:files={data.image}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<Button
|
<Button
|
||||||
submit
|
submit
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
class="break-words
|
class="break-words
|
||||||
{getColor(cardColor)} rounded-md {clazz}"
|
{getColor(cardColor)} rounded-md {clazz}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
|
on:click|stopPropagation
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
@@ -22,11 +22,13 @@ flex flex-col items-center justify-center bg-black/50 backdrop-blur-sm box-borde
|
|||||||
>
|
>
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<div
|
<div
|
||||||
on:click|stopPropagation={() => {}}
|
|
||||||
transition:scale={{ start: 0.9, easing: expoOut }}
|
transition:scale={{ start: 0.9, easing: expoOut }}
|
||||||
class="overflow-y-auto {$$props.class} rounded-xl max-w-full box-border"
|
class="overflow-y-auto {$$props.class} rounded-xl max-w-full box-border w-full"
|
||||||
>
|
>
|
||||||
<Card class="w-full dark:!bg-zinc-950 rounded-xl max-w-xl box-border">
|
<Card
|
||||||
|
class="w-full dark:!bg-zinc-950 rounded-xl max-w-xl box-border mx-auto"
|
||||||
|
on:click={() => {}}
|
||||||
|
>
|
||||||
<div class="p-6 flex flex-col gap-4 w-full">
|
<div class="p-6 flex flex-col gap-4 w-full">
|
||||||
<div class="flex flex-row max-w-full">
|
<div class="flex flex-row max-w-full">
|
||||||
<h1 class="font-bold text-2xl w-max max-w-full">
|
<h1 class="font-bold text-2xl w-max max-w-full">
|
||||||
|
|||||||
Reference in new issue
Block a user