Skip to content

Commit

Permalink
fix: preserve favorites when deleting source items during merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoung19 committed Nov 30, 2024
1 parent d26bbb5 commit 8ed71a5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion popup/components/modals/MergeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import {
} from "@mantine/core";
import { modals } from "@mantine/modals";
import { IconArrowsSort } from "@tabler/icons-react";
import { useAtomValue } from "jotai";
import { forwardRef, useMemo, useState, type CSSProperties } from "react";
import { createPortal } from "react-dom";
import { Controller, useForm } from "react-hook-form";
import { FixedSizeList } from "react-window";
import { z } from "zod";

import { favoriteEntryIdsSetAtom } from "~popup/states/atoms";
import { updateClipboardSnapshot } from "~storage/clipboardSnapshot";
import type { Entry } from "~types/entry";
import { createEntry, deleteEntries } from "~utils/storage";
Expand Down Expand Up @@ -86,6 +88,8 @@ const DraggableMergeItemRenderer = ({
};

export const MergeModalContent = ({ initialEntries }: Props) => {
const favoriteEntryIdsSet = useAtomValue(favoriteEntryIdsSetAtom);

const {
control,
handleSubmit,
Expand Down Expand Up @@ -119,7 +123,10 @@ export const MergeModalContent = ({ initialEntries }: Props) => {

await createEntry(content);
if (deleteSourceItems) {
await deleteEntries(entries.map(({ id }) => id));
await deleteEntries(
// Map entries to ids and filter out favorites.
entries.flatMap(({ id }) => (favoriteEntryIdsSet.has(id) ? [] : id)),
);
}

// Same action as clicking a row.
Expand Down

0 comments on commit 8ed71a5

Please sign in to comment.