Mutate the labels on links when setting them so they are reflected in UI

This commit is contained in:
Jackson Harper
2022-04-19 15:54:38 -07:00
parent 5d88b054c8
commit ab869a79bd
4 changed files with 9 additions and 1 deletions

View File

@ -109,6 +109,7 @@ export function ArticleActionsMenu(props: ArticleActionsMenuProps): JSX.Element
}
>
<SetLabelsControl
article={props.article}
linkId={props.article.linkId}
labels={props.article.labels}
articleActionHandler={props.articleActionHandler}

View File

@ -14,10 +14,12 @@ import { createLabelMutation } from '../../../lib/networking/mutations/createLab
import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers'
import { randomLabelColorHex } from '../../../utils/settings-page/labels/labelColorObjects'
import { useRouter } from 'next/router'
import { ArticleAttributes } from '../../../lib/networking/queries/useGetArticleQuery'
type SetLabelsControlProps = {
linkId: string
labels: Label[] | undefined
article?: ArticleAttributes
articleActionHandler: (action: string, arg?: unknown) => void
}
@ -215,7 +217,9 @@ export function SetLabelsControl(props: SetLabelsControlProps): JSX.Element {
newSelectedLabels.map((label) => label.id)
)
// props.article.labels = result
if (props.article) {
props.article.labels = result
}
props.articleActionHandler('refreshLabels', result)
revalidate()

View File

@ -1,4 +1,5 @@
import { Label } from '../../../lib/networking/fragments/labelFragment'
import { ArticleAttributes } from '../../../lib/networking/queries/useGetArticleQuery'
import { Button } from '../../elements/Button'
import { CrossIcon } from '../../elements/images/CrossIcon'
import { HStack, VStack } from '../../elements/LayoutPrimitives'
@ -14,6 +15,7 @@ import { SetLabelsControl } from './SetLabelsControl'
type SetLabelsModalProps = {
linkId: string
labels: Label[] | undefined
article?: ArticleAttributes
onOpenChange: (open: boolean) => void
articleActionHandler: (action: string, arg?: unknown) => void
}

View File

@ -253,6 +253,7 @@ export default function Home(): JSX.Element {
{showSetLabelsModal && (
<SetLabelsModal
article={article}
linkId={article.id}
labels={article.labels}
articleActionHandler={actionHandler}