mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 20:27:23 +00:00
Add pre-fetch data handling for resources, users, and comments
This commit is contained in:
@@ -90,14 +90,19 @@ export default function ResourcePage() {
|
||||
if (location.state) {
|
||||
setResource(location.state.resource);
|
||||
} else {
|
||||
network.getResourceDetails(id).then((res) => {
|
||||
if (res.success) {
|
||||
setResource(res.data!);
|
||||
document.title = res.data!.title;
|
||||
} else {
|
||||
showToast({ message: res.message, type: "error" });
|
||||
}
|
||||
});
|
||||
const preFetchData = app.getPreFetchData();
|
||||
if (preFetchData?.resource?.id === id) {
|
||||
setResource(preFetchData.resource);
|
||||
} else {
|
||||
network.getResourceDetails(id).then((res) => {
|
||||
if (res.success) {
|
||||
setResource(res.data!);
|
||||
document.title = res.data!.title;
|
||||
} else {
|
||||
showToast({ message: res.message, type: "error" });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [id, location.state]);
|
||||
|
Reference in New Issue
Block a user