mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Persist home page sorting order in app context and set default value
This commit is contained in:
@@ -7,18 +7,32 @@ import Button from "../components/button.tsx";
|
|||||||
import {MdInfoOutline} from "react-icons/md";
|
import {MdInfoOutline} from "react-icons/md";
|
||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import {useNavigate} from "react-router";
|
import {useNavigate} from "react-router";
|
||||||
|
import {useAppContext} from "../components/AppContext.tsx";
|
||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = app.appName;
|
document.title = app.appName;
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const [order, setOrder] = useState(RSort.TimeDesc)
|
|
||||||
|
|
||||||
const {t} = useTranslation()
|
const {t} = useTranslation()
|
||||||
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const appContext = useAppContext()
|
||||||
|
|
||||||
|
const [order, setOrder] = useState(() => {
|
||||||
|
if (appContext && appContext.get("home_page_order") !== undefined) {
|
||||||
|
return appContext.get("home_page_order");
|
||||||
|
}
|
||||||
|
return RSort.TimeDesc;
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (appContext && order !== RSort.TimeDesc) {
|
||||||
|
appContext.set("home_page_order", order);
|
||||||
|
}
|
||||||
|
}, [appContext, order]);
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<div className={"flex p-4 items-center"}>
|
<div className={"flex p-4 items-center"}>
|
||||||
<select value={order} className="select w-52 select-info" onInput={(e) => {
|
<select value={order} className="select w-52 select-info" onInput={(e) => {
|
||||||
|
Reference in New Issue
Block a user