User profile request caching
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user