draft-remove-fix
This commit is contained in:
parent
5f47bf161c
commit
c158532cc1
|
@ -22,8 +22,8 @@ export const DraftsView = () => {
|
|||
}
|
||||
}
|
||||
|
||||
createEffect(async () => {
|
||||
if (isSessionLoaded()) await loadDrafts()
|
||||
createEffect(() => {
|
||||
if (isSessionLoaded()) loadDrafts()
|
||||
})
|
||||
|
||||
const {
|
||||
|
@ -32,7 +32,9 @@ export const DraftsView = () => {
|
|||
|
||||
const handleDraftDelete = async (shout: Shout) => {
|
||||
const result = deleteShout(shout.id)
|
||||
if (result) await loadDrafts()
|
||||
if (result) {
|
||||
setDrafts((ddd) => ddd.filter((d) => d.id !== shout.id))
|
||||
}
|
||||
}
|
||||
|
||||
const handleDraftPublish = (shout: Shout) => {
|
||||
|
|
|
@ -9,7 +9,7 @@ import { apiClient } from '../graphql/client/core'
|
|||
import { Topic, TopicInput } from '../graphql/schema/core.gen'
|
||||
import { router, useRouter } from '../stores/router'
|
||||
import { slugify } from '../utils/slugify'
|
||||
|
||||
import { addArticles } from '../stores/zine/articles'
|
||||
import { useLocalize } from './localize'
|
||||
import { useSnackbar } from './snackbar'
|
||||
|
||||
|
@ -197,11 +197,11 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
|
|||
|
||||
const publishShoutById = async (shout_id: number) => {
|
||||
try {
|
||||
await apiClient.updateArticle({
|
||||
const newShout = await apiClient.updateArticle({
|
||||
shout_id,
|
||||
publish: true,
|
||||
})
|
||||
|
||||
addArticles([newShout])
|
||||
openPage(router, 'feed')
|
||||
} catch (error) {
|
||||
console.error('[publishShoutById]', error)
|
||||
|
|
|
@ -64,12 +64,14 @@ const topCommentedArticles = createLazyMemo(() => {
|
|||
})
|
||||
|
||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||
const addArticles = (...args: Shout[][]) => {
|
||||
export const addArticles = (...args: Shout[][]) => {
|
||||
const allArticles = args.flatMap((articles) => articles || [])
|
||||
|
||||
const newArticleEntities = allArticles.reduce(
|
||||
(acc, article) => {
|
||||
acc[article.slug] = article
|
||||
if (!acc[article.slug]) {
|
||||
acc[article.slug] = article
|
||||
}
|
||||
return acc
|
||||
},
|
||||
{} as { [articleSLug: string]: Shout },
|
||||
|
|
Loading…
Reference in New Issue
Block a user