draft-remove-fix
This commit is contained in:
parent
5f47bf161c
commit
c158532cc1
|
@ -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) => {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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) => {
|
||||||
acc[article.slug] = article
|
if (!acc[article.slug]) {
|
||||||
|
acc[article.slug] = article
|
||||||
|
}
|
||||||
return acc
|
return acc
|
||||||
},
|
},
|
||||||
{} as { [articleSLug: string]: Shout },
|
{} as { [articleSLug: string]: Shout },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user