Handle optional highlights

This commit is contained in:
Jackson Harper
2024-08-23 14:35:48 +08:00
parent d9c3437852
commit 36e48fdd2e

View File

@ -37,7 +37,7 @@ export const useCreateHighlight = () => {
(item) => {
return {
...item,
highlights: [...item.highlights, newHighlight],
highlights: [...(item.highlights ?? []), newHighlight],
}
}
)
@ -72,7 +72,7 @@ export const useDeleteHighlight = () => {
(item) => {
return {
...item,
highlights: item.highlights.filter(
highlights: (item.highlights ?? []).filter(
(h) => h.id != deletedHighlight.id
),
}
@ -115,7 +115,9 @@ export const useUpdateHighlight = () => {
return {
...item,
highlights: [
...item.highlights.filter((h) => h.id != updatedHighlight.id),
...(item.highlights ?? []).filter(
(h) => h.id != updatedHighlight.id
),
updatedHighlight,
],
}
@ -169,7 +171,9 @@ export const useMergeHighlight = () => {
return {
...item,
highlights: [
...item.highlights.filter((h) => mergedIds.indexOf(h.id) == -1),
...(item.highlights ?? []).filter(
(h) => mergedIds.indexOf(h.id) == -1
),
newHighlight,
],
}