User profile request caching

This commit is contained in:
2025-10-15 11:13:58 +02:00
parent f5aca7434f
commit a183974d20
6 changed files with 91 additions and 20 deletions
+10 -9
View File
@@ -34,6 +34,7 @@ import { StringMap } from "@/types/typeUtils";
import SettingsDialog from "./settings/SettingsDialog";
import Link from "next/link";
import axios from "axios";
import { get, Response } from "@/lib/request";
export default function AppSidebar({
children,
@@ -327,15 +328,15 @@ function getUser(
) {
if (userList[id]) return userList[id];
axios
.get(`/api/profile/?id=${id}`)
?.then((res) => {
console.log("Fetched user", res.data);
setUserList((prev) => {
prev[id] = res.data as UserProfile;
return prev;
});
})
const onResponse = (res: Response<UserProfile>) => {
setUserList((prev) => {
prev[id] = res.data as UserProfile;
return prev;
});
};
get(`/api/profile/?id=${id}`, onResponse)
?.then(onResponse)
.catch((e) => {
console.error(e);
});