diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 727579f..5cfa997 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -15,6 +15,7 @@ import { useSwipeable } from "react-swipeable"; import { Ico, Icon } from "./Ico"; import { OrderableList } from "./Inputs/OrderableList"; import { Select } from "./Inputs/Select"; +import { TextInput } from "./Inputs/TextInput"; import { MainPanel } from "./Panels/MainPanel"; import { Popup } from "./Popup"; import { PreviewCard } from "./PreviewCard"; @@ -484,16 +485,11 @@ export function AppLayout(props: Immutable): JSX.Element {

{langui.player_name}

- - appLayout.setPlayerName( - (event.target as HTMLInputElement).value - ) - } - value={appLayout.playerName} + state={appLayout.playerName} + setState={appLayout.setPlayerName} />
@@ -507,16 +503,11 @@ export function AppLayout(props: Immutable): JSX.Element {
{/* TODO: add to langui */}

{"Search"}

- { - const input = event.target as HTMLInputElement; - setSearchQuery(input.value); - }} + state={searchQuery} + setState={setSearchQuery} />
{/* TODO: add to langui */} diff --git a/src/components/Inputs/TextInput.tsx b/src/components/Inputs/TextInput.tsx new file mode 100644 index 0000000..2fd7785 --- /dev/null +++ b/src/components/Inputs/TextInput.tsx @@ -0,0 +1,43 @@ +import { Ico, Icon } from "components/Ico"; +import { Immutable } from "helpers/types"; +import { Dispatch, SetStateAction } from "react"; + +interface Props { + state: string | undefined; + setState: + | Dispatch> + | Dispatch>; + className?: string; + name?: string; + placeholder?: string; +} + +export function TextInput(props: Immutable): JSX.Element { + const { state, setState, className, name, placeholder } = props; + + return ( +
+ { + setState(event.target.value); + }} + /> +
+ {state && ( + { + setState(""); + }} + /> + )} +
+
+ ); +} diff --git a/src/pages/contents/index.tsx b/src/pages/contents/index.tsx index 55d5f4c..ab3b477 100644 --- a/src/pages/contents/index.tsx +++ b/src/pages/contents/index.tsx @@ -18,6 +18,8 @@ import { GetStaticPropsContext } from "next"; import { Fragment, useEffect, useState } from "react"; import { Icon } from "components/Ico"; import { WithLabel } from "components/Inputs/WithLabel"; +import { Button } from "components/Inputs/Button"; +import { TextInput } from "components/Inputs/TextInput"; interface Props extends AppStaticProps { contents: NonNullable["data"]; @@ -25,16 +27,29 @@ interface Props extends AppStaticProps { type GroupContentItems = Map>; +const defaultFiltersState = { + groupingMethod: -1, + keepInfoVisible: false, + combineRelatedContent: true, + searchName: "", +}; + export default function Contents(props: Immutable): JSX.Element { const { langui, contents } = props; - const [groupingMethod, setGroupingMethod] = useState(-1); - const [keepInfoVisible, setKeepInfoVisible] = useState(false); + const [groupingMethod, setGroupingMethod] = useState( + defaultFiltersState.groupingMethod + ); + const [keepInfoVisible, setKeepInfoVisible] = useState( + defaultFiltersState.keepInfoVisible + ); + const [combineRelatedContent, setCombineRelatedContent] = useState( + defaultFiltersState.combineRelatedContent + ); + const [searchName, setSearchName] = useState(defaultFiltersState.searchName); - const [combineRelatedContent, setCombineRelatedContent] = useState(true); const [effectiveCombineRelatedContent, setEffectiveCombineRelatedContent] = useState(true); - const [searchName, setSearchName] = useState(""); const [filteredItems, setFilteredItems] = useState( filterContents(contents, combineRelatedContent, searchName) @@ -72,16 +87,11 @@ export default function Contents(props: Immutable): JSX.Element { description={langui.contents_description} /> - { - const input = event.target as HTMLInputElement; - setSearchName(input.value); - }} + state={searchName} + setState={setSearchName} /> ): JSX.Element { label={langui.always_show_info} input={} /> + + {/* TODO: Add to Langui */} +