import { GetStaticProps } from "next"; import { useCallback, useMemo, useState } from "react"; import { useBoolean } from "usehooks-ts"; import { AppLayout, AppLayoutRequired } from "components/AppLayout"; import { NavOption } from "components/PanelComponents/NavOption"; import { PanelHeader } from "components/PanelComponents/PanelHeader"; import { SubPanel } from "components/Containers/SubPanel"; import { Icon } from "components/Ico"; import { getReadySdk } from "graphql/sdk"; import { GetWikiPageQuery, GetWikiPagesPreviewsQuery } from "graphql/generated"; import { ContentPanel, ContentPanelWidthSizes } from "components/Containers/ContentPanel"; import { HorizontalLine } from "components/HorizontalLine"; import { Button } from "components/Inputs/Button"; import { Switch } from "components/Inputs/Switch"; import { TextInput } from "components/Inputs/TextInput"; import { WithLabel } from "components/Inputs/WithLabel"; import { useDeviceSupportsHover } from "hooks/useMediaQuery"; import { filterDefined, filterHasAttributes, isDefinedAndNotEmpty } from "helpers/others"; import { SmartList } from "components/SmartList"; import { Select } from "components/Inputs/Select"; import { SelectiveNonNullable } from "types/SelectiveNonNullable"; import { prettySlug } from "helpers/formatters"; import { getOpenGraph } from "helpers/openGraph"; import { TranslatedPreviewCard } from "components/PreviewCard"; import { cIf } from "helpers/className"; import { getLangui } from "graphql/fetchLocalData"; import { sendAnalytics } from "helpers/analytics"; import { Terminal } from "components/Cli/Terminal"; import { useIsTerminalMode } from "hooks/useIsTerminalMode"; import { useLocalData } from "contexts/LocalDataContext"; import { useContainerQueries } from "contexts/ContainerQueriesContext"; /* * ╭─────────────╮ * ────────────────────────────────────────╯ CONSTANTS ╰────────────────────────────────────────── */ const DEFAULT_FILTERS_STATE = { searchName: "", keepInfoVisible: true, groupingMethod: -1, }; /* * ╭────────╮ * ──────────────────────────────────────────╯ PAGE ╰───────────────────────────────────────────── */ interface Props extends AppLayoutRequired { pages: NonNullable["data"]; } const Wiki = ({ pages, ...otherProps }: Props): JSX.Element => { const hoverable = useDeviceSupportsHover(); const { langui } = useLocalData(); const { isContentPanelAtLeast4xl } = useContainerQueries(); const isTerminalMode = useIsTerminalMode(); const [searchName, setSearchName] = useState(DEFAULT_FILTERS_STATE.searchName); const [groupingMethod, setGroupingMethod] = useState( DEFAULT_FILTERS_STATE.groupingMethod ); const { value: keepInfoVisible, toggle: toggleKeepInfoVisible, setValue: setKeepInfoVisible, } = useBoolean(DEFAULT_FILTERS_STATE.keepInfoVisible); const subPanel = useMemo( () => ( { setSearchName(name); if (isDefinedAndNotEmpty(name)) { sendAnalytics("Wiki", "Change search term"); } else { sendAnalytics("Wiki", "Clear search term"); } }} />