mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
Implement caching for tags list in TagsPage component
This commit is contained in:
@@ -5,14 +5,21 @@ import showToast from "../components/toast.ts";
|
||||
import Loading from "../components/loading.tsx";
|
||||
import Badge from "../components/badge.tsx";
|
||||
import { useNavigate } from "react-router";
|
||||
import { useAppContext } from "../components/AppContext.tsx";
|
||||
|
||||
export default function TagsPage() {
|
||||
const [tags, setTags] = useState<TagWithCount[] | null>(null);
|
||||
const context = useAppContext();
|
||||
|
||||
useEffect(() => {
|
||||
const storageKey = "tags_list";
|
||||
if (context.get(storageKey)) {
|
||||
setTags(context.get(storageKey));
|
||||
} else {
|
||||
network.getAllTags().then((res) => {
|
||||
if (res.success) {
|
||||
setTags(res.data!);
|
||||
context.set(storageKey, res.data!);
|
||||
} else {
|
||||
showToast({
|
||||
type: "error",
|
||||
@@ -20,7 +27,8 @@ export default function TagsPage() {
|
||||
});
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
}, [context]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
|
Reference in New Issue
Block a user