User page fix bug with not being

able to change page from one user to another
This commit is contained in:
Kalle (Sendou)
2021-06-14 21:37:35 +03:00
parent 75ef398cc7
commit 30a019a064

View File

@@ -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} />