Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyvy-vi committed Aug 8, 2023
1 parent 0b0075a commit dec284e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 7 additions & 4 deletions packages/frontend/src/model/user/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ export const useUserProfile = (): useUserProfileReturn => {
const DetailedSingleUserQuery = selectorFamily({
key: 'DetailedSingleUserQuery',
get:
(userId: string) =>
({ get }): AxiosResponse<User> | AxiosError => {
(userId: string | undefined) =>
({ get }): AxiosResponse<User> | AxiosError | undefined => {
if (!userId) return undefined;
return get(
ApiGet({
url: `/users/${userId}`,
Expand All @@ -304,8 +305,10 @@ const DetailedSingleUserQuery = selectorFamily({
* Update user cached in global state.
*/
export const useLoadSingleUserDetails = (
userId: string
): AxiosResponse<User> | AxiosError => {
username: string
): AxiosResponse<User> | AxiosError | undefined => {
const userId = useRecoilValue(SingleUser(username))?._id;

const response = useRecoilValue(DetailedSingleUserQuery(userId));
const user = useRecoilValue(SingleUser(userId));
const setUser = useSetRecoilState(SingleUser(userId));
Expand Down
8 changes: 3 additions & 5 deletions packages/frontend/src/pages/UserDetails/UserDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ const UserDetailsPage = (): JSX.Element | null => {
const dialogRef = React.useRef(null);
const { userName } = useParams<SingleUserByUsernameParams>();

useLoadSingleUserDetails(userName);
const user = useRecoilValue(SingleUserByUsername(userName));

if (!user) return null;

useLoadSingleUserDetails(user?._id);


const [isDialogOpen, setIsDialogOpen] = React.useState<boolean>(false);

const pageViews = {
Expand All @@ -45,6 +41,8 @@ const UserDetailsPage = (): JSX.Element | null => {

const [view, setView] = useState<number>(pageViews.receivedPraiseView);

if (!user) return null;

return (
<Page>
<BreadCrumb name="Profile" icon={faUser} />
Expand Down

0 comments on commit dec284e

Please sign in to comment.