feat: add nsfw toggle

This commit is contained in:
Xyphyn committed 2023-08-12 16:38:33 -07:00
1 parent dbc0f6f5bb
commit bca08af577
5 files changed
+95 -19

No files matched your search

@@ -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>
+37 -15
View File
@@ -8,10 +8,11 @@
import Button from '$lib/components/input/Button.svelte'
import { toast } from '$lib/components/ui/toasts/toasts.js'
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 MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders } from '$lib/util.js'
import Checkbox from '$lib/components/input/Checkbox.svelte'
export let edit = false
@@ -33,6 +34,7 @@
body: string
image: FileList | null
url: string | undefined
nsfw: boolean
loading: boolean
} = {
community: null,
@@ -40,6 +42,7 @@
body: '',
image: null,
url: undefined,
nsfw: false,
loading: false,
}
@@ -104,6 +107,7 @@
body: data.body,
url: data.url || undefined,
post_id: editingPost.id,
nsfw: data.nsfw,
})
if (!post) throw new Error('Failed to edit post')
@@ -120,6 +124,7 @@
name: data.title,
body: data.body,
url: data.url,
nsfw: data.nsfw,
})
if (!post) throw new Error('Failed to upload post')
@@ -134,8 +139,22 @@
}
let communitySearch = ''
let uploadingImage = false
</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">
<slot name="formtitle">
<h1 class="font-bold text-xl">
@@ -192,26 +211,29 @@
bind:value={data.title}
placeholder={placeholders.get('post')}
/>
<TextInput
label="URL"
bind:value={data.url}
placeholder={placeholders.get('url')}
/>
<div class="flex gap-2 w-full items-end">
<TextInput
label="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
rows={9}
rows={8}
label="Body"
bind:value={data.body}
placeholder={placeholders.get('post')}
previewButton
/>
<div>
<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>
<Checkbox bind:checked={data.nsfw}>NSFW</Checkbox>
<Button
submit
color="primary"
+1
View File
@@ -23,6 +23,7 @@
class="break-words
{getColor(cardColor)} rounded-md {clazz}"
{...$$restProps}
on:click|stopPropagation
>
<slot />
</div>
+5 -3
View File
@@ -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 -->
<div
on:click|stopPropagation={() => {}}
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="flex flex-row max-w-full">
<h1 class="font-bold text-2xl w-max max-w-full">