-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <GoToPresentCommand /> | ||
} | ||
|
||
return <GoToArchiveCommand /> | ||
} | ||
|
||
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 ( | ||
<CommandItem onSelect={handleGoToPresent} keywords={COMMAND_KEYWORDS}> | ||
🕰️ View current folder in the present | ||
</CommandItem> | ||
) | ||
} | ||
|
||
function GoToArchiveCommand() { | ||
const handleOpenArchive = () => { | ||
NiceModal.hide(CommandsDialog) | ||
NiceModal.show(ViewArchiveDialog) | ||
} | ||
|
||
return ( | ||
<CommandItem onSelect={handleOpenArchive} keywords={COMMAND_KEYWORDS}> | ||
🕰️ View current folder in the past | ||
</CommandItem> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<CommandDialog handler={modalHandler}> | ||
<VisuallyHidden> | ||
<DialogTitle> | ||
<DialogDescription>Command dialog</DialogDescription> | ||
</DialogTitle> | ||
</VisuallyHidden> | ||
<CommandInput placeholder="Search archive year..." /> | ||
<CommandList> | ||
<CommandEmpty>No results found.</CommandEmpty> | ||
{archivedYears.map((year) => { | ||
return ( | ||
<CommandItem | ||
onSelect={() => { | ||
handleSelection(year) | ||
}} | ||
key={year} | ||
value={year} | ||
> | ||
{year} | ||
</CommandItem> | ||
) | ||
})} | ||
</CommandList> | ||
</CommandDialog> | ||
) | ||
}) |