mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 07:12:36 -05:00
User page fix bug with not being
able to change page from one user to another
This commit is contained in:
@@ -36,14 +36,20 @@ const ProfilePage = (props: Props) => {
|
||||
const router = useRouter();
|
||||
const [showProfileModal, setShowProfileModal] = useState(false);
|
||||
const [buildToEdit, setBuildToEdit] = useState<boolean | Build>(false);
|
||||
const [userId, setUserId] = useState<number | undefined>(undefined);
|
||||
|
||||
const apiUrl = () => {
|
||||
if (userId || (!!props.user?.id && props.user.id === loggedInUser?.id)) {
|
||||
return `/api/users/${userId}`;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const [loggedInUser] = useUser();
|
||||
const { data } = useSWR<GetUserByIdentifierData>(
|
||||
!!props.user?.id && props.user.id === loggedInUser?.id
|
||||
? `/api/users/${props.user.id}`
|
||||
: null,
|
||||
{ initialData: props.user }
|
||||
);
|
||||
const { data } = useSWR<GetUserByIdentifierData>(apiUrl(), {
|
||||
initialData: props.user,
|
||||
});
|
||||
|
||||
const user = data ? data : props.user!;
|
||||
|
||||
@@ -75,6 +81,10 @@ const ProfilePage = (props: Props) => {
|
||||
history.replaceState({}, "", `/u/${user.profile.customUrlPath}`);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setUserId(props.user.id);
|
||||
}, [props.user.id]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<MyHead title={user.username} />
|
||||
|
||||
Reference in New Issue
Block a user