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 () => { createEffect(() => {
if (isSessionLoaded()) await loadDrafts() if (isSessionLoaded()) loadDrafts()
}) })
const { const {
@ -32,7 +32,9 @@ export const DraftsView = () => {
const handleDraftDelete = async (shout: Shout) => { const handleDraftDelete = async (shout: Shout) => {
const result = deleteShout(shout.id) const result = deleteShout(shout.id)
if (result) await loadDrafts() if (result) {
setDrafts((ddd) => ddd.filter((d) => d.id !== shout.id))
}
} }
const handleDraftPublish = (shout: Shout) => { 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 { Topic, TopicInput } from '../graphql/schema/core.gen'
import { router, useRouter } from '../stores/router' import { router, useRouter } from '../stores/router'
import { slugify } from '../utils/slugify' import { slugify } from '../utils/slugify'
import { addArticles } from '../stores/zine/articles'
import { useLocalize } from './localize' import { useLocalize } from './localize'
import { useSnackbar } from './snackbar' import { useSnackbar } from './snackbar'
@ -197,11 +197,11 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
const publishShoutById = async (shout_id: number) => { const publishShoutById = async (shout_id: number) => {
try { try {
await apiClient.updateArticle({ const newShout = await apiClient.updateArticle({
shout_id, shout_id,
publish: true, publish: true,
}) })
addArticles([newShout])
openPage(router, 'feed') openPage(router, 'feed')
} catch (error) { } catch (error) {
console.error('[publishShoutById]', error) console.error('[publishShoutById]', error)

View File

@ -64,12 +64,14 @@ const topCommentedArticles = createLazyMemo(() => {
}) })
// eslint-disable-next-line sonarjs/cognitive-complexity // eslint-disable-next-line sonarjs/cognitive-complexity
const addArticles = (...args: Shout[][]) => { export const addArticles = (...args: Shout[][]) => {
const allArticles = args.flatMap((articles) => articles || []) const allArticles = args.flatMap((articles) => articles || [])
const newArticleEntities = allArticles.reduce( const newArticleEntities = allArticles.reduce(
(acc, article) => { (acc, article) => {
if (!acc[article.slug]) {
acc[article.slug] = article acc[article.slug] = article
}
return acc return acc
}, },
{} as { [articleSLug: string]: Shout }, {} as { [articleSLug: string]: Shout },