diff --git a/apps/client/src/features/page-history/components/history-modal-mobile.tsx b/apps/client/src/features/page-history/components/history-modal-mobile.tsx index 64e3bdfc..84e51cde 100644 --- a/apps/client/src/features/page-history/components/history-modal-mobile.tsx +++ b/apps/client/src/features/page-history/components/history-modal-mobile.tsx @@ -2,14 +2,12 @@ import { ActionIcon, Box, Button, - Combobox, Group, - InputBase, Paper, ScrollArea, + Select, Switch, Text, - useCombobox, } from "@mantine/core"; import { useAtom } from "jotai"; import { @@ -21,11 +19,7 @@ import { } from "@/features/page-history/atoms/history-atoms"; import HistoryView from "@/features/page-history/components/history-view"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { - IconChevronDown, - IconChevronUp, - IconSelector, -} from "@tabler/icons-react"; +import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react"; import { useTranslation } from "react-i18next"; import { usePageHistoryListQuery, @@ -54,9 +48,6 @@ interface Props { export default function HistoryModalMobile({ pageId, pageTitle }: Props) { const { t } = useTranslation(); - const combobox = useCombobox({ - onDropdownClose: () => combobox.resetSelectedOption(), - }); const [activeHistoryId, setActiveHistoryId] = useAtom(activeHistoryIdAtom); const [, setActiveHistoryPrevId] = useAtom(activeHistoryPrevIdAtom); @@ -75,6 +66,16 @@ export default function HistoryModalMobile({ pageId, pageTitle }: Props) { [pageHistoryData], ); + const selectData = useMemo( + () => + historyItems.map((item) => ({ + value: item.id, + label: formattedDate(new Date(item.createdAt)), + userName: item.lastUpdatedBy?.name, + })), + [historyItems], + ); + const [mainEditor] = useAtom(pageEditorAtom); const [mainEditorTitle] = useAtom(titleEditorAtom); @@ -141,15 +142,15 @@ export default function HistoryModalMobile({ pageId, pageTitle }: Props) { }; const handleSelectVersion = useCallback( - (id: string) => { - const index = historyItems.findIndex((item) => item.id === id); + (value: string | null) => { + if (!value) return; + const index = historyItems.findIndex((item) => item.id === value); if (index >= 0) { - setActiveHistoryId(id); + setActiveHistoryId(value); setActiveHistoryPrevId(historyItems[index + 1]?.id ?? ""); } - combobox.closeDropdown(); }, - [historyItems, combobox], + [historyItems], ); const confirmRestore = () => @@ -183,24 +184,6 @@ export default function HistoryModalMobile({ pageId, pageTitle }: Props) { } }, [activeHistoryData, mainEditor, mainEditorTitle, setHistoryModalOpen, t]); - const selectedItem = historyItems.find((item) => item.id === activeHistoryId); - - const options = historyItems.map((item) => ( - - - {formattedDate(new Date(item.createdAt))} - - {item.lastUpdatedBy?.name} - - - - )); - if (isLoading) { return null; } @@ -208,39 +191,26 @@ export default function HistoryModalMobile({ pageId, pageTitle }: Props) { return ( - - - } - rightSectionPointerEvents="none" - onClick={() => combobox.toggleDropdown()} - className={classes.selector} - > - {selectedItem ? ( - - {formattedDate(new Date(selectedItem.createdAt))} + ( + + + {option.label} + + {(option as { userName?: string }).userName} - ) : ( - - {t("Select version")} - - )} - - - - - - {options} - - - + + {checked && } + + )} + comboboxProps={{ withinPortal: false }} + />