feat: add post drafts
This commit is contained in:
1 parent
4906f338d5
commit
ac9421e8c7
3 files changed
+30
-4
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.7.3",
|
"version": "0.7.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher, onMount } from 'svelte'
|
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||||
import { getClient, uploadImage } from '$lib/lemmy.js'
|
import { getClient, uploadImage } from '$lib/lemmy.js'
|
||||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
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'
|
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||||
|
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
||||||
|
|
||||||
export let edit = false
|
export let edit = false
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@
|
|||||||
loading: false,
|
loading: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let saveDraft = edit ? false : true
|
||||||
|
|
||||||
let communities: Community[] = []
|
let communities: Community[] = []
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
||||||
@@ -70,10 +73,22 @@
|
|||||||
|
|
||||||
communities = list.communities.map((c) => c.community)
|
communities = list.communities.map((c) => c.community)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const draft = getSessionStorage('postDraft')
|
||||||
|
if (draft && !edit) {
|
||||||
|
// @ts-ignore
|
||||||
|
draft.loading = false
|
||||||
|
// @ts-ignore
|
||||||
|
data = draft
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (saveDraft) setSessionStorage('postDraft', data)
|
||||||
})
|
})
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!data.community && !edit) {
|
if ((!data.community || communitySearch == '') && !edit) {
|
||||||
toast({
|
toast({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
content: 'You need to set a community.',
|
content: 'You need to set a community.',
|
||||||
@@ -131,6 +146,7 @@
|
|||||||
|
|
||||||
console.log(`Uploaded post ${post?.post_view.post.id}`)
|
console.log(`Uploaded post ${post?.post_view.post.id}`)
|
||||||
|
|
||||||
|
saveDraft = false
|
||||||
dispatcher('submit', post.post_view)
|
dispatcher('submit', post.post_view)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
+11
-1
@@ -4,7 +4,17 @@ interface SessionStorage {
|
|||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
} | undefined
|
} | undefined
|
||||||
postData: {}
|
postDraft:
|
||||||
|
| {
|
||||||
|
community: number | null
|
||||||
|
title: string
|
||||||
|
body: string
|
||||||
|
image: FileList | null
|
||||||
|
url: string | undefined
|
||||||
|
nsfw: boolean
|
||||||
|
loading: boolean
|
||||||
|
}
|
||||||
|
| undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setSessionStorage = (
|
export const setSessionStorage = (
|
||||||
|
|||||||
Reference in new issue
Block a user