From 6fb55649461de9bfc20a121167312eea6c1e0953 Mon Sep 17 00:00:00 2001 From: Oleksii Nazarenko Date: Mon, 4 Nov 2024 15:18:20 +0000 Subject: [PATCH] view archived year command --- src/features/command/ViewArchiveCommand.tsx | 67 ++++++++++++++++ .../shared/dialogs/CommandsDialog.tsx | 2 + .../shared/dialogs/ViewArchiveDialog.tsx | 78 +++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 src/features/command/ViewArchiveCommand.tsx create mode 100644 src/features/shared/dialogs/ViewArchiveDialog.tsx diff --git a/src/features/command/ViewArchiveCommand.tsx b/src/features/command/ViewArchiveCommand.tsx new file mode 100644 index 0000000..acdf8f1 --- /dev/null +++ b/src/features/command/ViewArchiveCommand.tsx @@ -0,0 +1,67 @@ +import NiceModal from "@ebay/nice-modal-react" +import { + convertUrlSegmentsToUrl, + extractUrlSegments, +} from "@src/features/files" +import { getSegmentType } from "@src/features/router/getSegmentType" +import useSmoothRouter from "@src/features/router/useSmoothRouter" +import CommandsDialog from "@src/features/shared/dialogs/CommandsDialog" +import ViewArchiveDialog from "@src/features/shared/dialogs/ViewArchiveDialog" +import { CommandItem } from "../../components/ui/command" + +const COMMAND_KEYWORDS = [ + "time", + "travel", + "archive", + "back", + "previous", + "go", + "history", +] + +export default function ViewArchiveCommand() { + const currentUrl = window.location.toString() + const currentUrlSegments = extractUrlSegments(currentUrl) + + if ( + currentUrlSegments[0] && + getSegmentType(currentUrlSegments[0]) === "archive" + ) { + return + } + + return +} + +function GoToPresentCommand() { + const { navigateToPage } = useSmoothRouter() + + const currentUrl = window.location.toString() + const currentUrlSegments = extractUrlSegments(currentUrl) + + const handleGoToPresent = () => { + currentUrlSegments.splice(0, 1) + navigateToPage(convertUrlSegmentsToUrl(currentUrlSegments)) + + NiceModal.hide(CommandsDialog) + } + + return ( + + 🕰️ View current folder in the present + + ) +} + +function GoToArchiveCommand() { + const handleOpenArchive = () => { + NiceModal.hide(CommandsDialog) + NiceModal.show(ViewArchiveDialog) + } + + return ( + + 🕰️ View current folder in the past + + ) +} diff --git a/src/features/shared/dialogs/CommandsDialog.tsx b/src/features/shared/dialogs/CommandsDialog.tsx index 7f6d164..baf0d44 100644 --- a/src/features/shared/dialogs/CommandsDialog.tsx +++ b/src/features/shared/dialogs/CommandsDialog.tsx @@ -15,6 +15,7 @@ import ClearVersionTrackingDataCommand from "@src/features/command/ClearVersionT import SaveQuickLinkCommand from "@src/features/command/SaveQuickLinkCommand" import { ToggleEnhancePageCommand } from "@src/features/command/ToggleEnhancePageCommand" import ToggleThemeCommand from "@src/features/command/ToggleThemeCommand" +import ViewArchiveCommand from "@src/features/command/ViewArchiveCommand" import { getModuleEmoji } from "@src/features/contentEnhancers/emoji/modules" import { BASE_URL, @@ -112,6 +113,7 @@ export default NiceModal.create(() => { + {commandsData && diff --git a/src/features/shared/dialogs/ViewArchiveDialog.tsx b/src/features/shared/dialogs/ViewArchiveDialog.tsx new file mode 100644 index 0000000..a439b01 --- /dev/null +++ b/src/features/shared/dialogs/ViewArchiveDialog.tsx @@ -0,0 +1,78 @@ +import NiceModal, { useModal } from "@ebay/nice-modal-react" +import { VisuallyHidden } from "@radix-ui/react-visually-hidden" +import { + CommandDialog, + CommandEmpty, + CommandInput, + CommandItem, + CommandList, +} from "@src/components/ui/command" +import { DialogDescription, DialogTitle } from "@src/components/ui/dialog" +import { + convertUrlSegmentsToUrl, + extractUrlSegments, +} from "@src/features/files" +import useSmoothRouter from "@src/features/router/useSmoothRouter" + +function generateArchivedYears() { + const now = new Date() + + const STUDRES_ARCHIVE_YEAR_START = 2009 + const STUDRES_ARCHIVE_YEAR_END = now.getFullYear() + + const result = [] + + for ( + let current = STUDRES_ARCHIVE_YEAR_START; + current < STUDRES_ARCHIVE_YEAR_END; + current++ + ) { + result.push(current + "_" + (current + 1)) + } + + return result.reverse() +} + +export default NiceModal.create(() => { + const { navigateToPage } = useSmoothRouter() + const modalHandler = useModal() + + const archivedYears = generateArchivedYears() + + const handleSelection = (archiveYear: string) => { + const currentUrl = window.location.toString() + const currentUrlSegments = extractUrlSegments(currentUrl) + + currentUrlSegments.unshift(archiveYear) + + navigateToPage(convertUrlSegmentsToUrl(currentUrlSegments)) + modalHandler.hide() + } + + return ( + + + + Command dialog + + + + + No results found. + {archivedYears.map((year) => { + return ( + { + handleSelection(year) + }} + key={year} + value={year} + > + {year} + + ) + })} + + + ) +})