draft-remove-fix

This commit is contained in:
Untone 2024-02-03 00:52:04 +03:00
parent 5f47bf161c
commit c158532cc1
3 changed files with 12 additions and 8 deletions

View File

@ -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) => {

View File

@ -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)

View File

@ -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 },