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,22 +5,30 @@ import showToast from "../components/toast.ts";
|
|||||||
import Loading from "../components/loading.tsx";
|
import Loading from "../components/loading.tsx";
|
||||||
import Badge from "../components/badge.tsx";
|
import Badge from "../components/badge.tsx";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
|
import { useAppContext } from "../components/AppContext.tsx";
|
||||||
|
|
||||||
export default function TagsPage() {
|
export default function TagsPage() {
|
||||||
const [tags, setTags] = useState<TagWithCount[] | null>(null);
|
const [tags, setTags] = useState<TagWithCount[] | null>(null);
|
||||||
|
const context = useAppContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
network.getAllTags().then((res) => {
|
const storageKey = "tags_list";
|
||||||
if (res.success) {
|
if (context.get(storageKey)) {
|
||||||
setTags(res.data!);
|
setTags(context.get(storageKey));
|
||||||
} else {
|
} else {
|
||||||
showToast({
|
network.getAllTags().then((res) => {
|
||||||
type: "error",
|
if (res.success) {
|
||||||
message: res.message || "Failed to load tags",
|
setTags(res.data!);
|
||||||
});
|
context.set(storageKey, res.data!);
|
||||||
}
|
} else {
|
||||||
});
|
showToast({
|
||||||
}, []);
|
type: "error",
|
||||||
|
message: res.message || "Failed to load tags",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [context]);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user