-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #550 from ParkSohyunee/part3-박소현-week15
[박소현] week15
- Loading branch information
Showing
9 changed files
with
138 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import useSWR from "swr"; | ||
import * as S from "./HeroStyles"; | ||
import { Owner } from "@/types/user"; | ||
|
||
import { SharedFolderData } from "@/types/folder"; | ||
import { User } from "@/types/user"; | ||
import Loading from "@/components/Loading"; | ||
|
||
interface HeroProps { | ||
folder: string; | ||
profile: Owner; | ||
folder: SharedFolderData; | ||
} | ||
|
||
export default function Hero({ folder, profile }: HeroProps) { | ||
export default function Hero({ folder }: HeroProps) { | ||
const { data, isLoading } = useSWR<{ data: User[] }>(`/api/users/${folder.user_id}`); | ||
|
||
return ( | ||
<> | ||
<S.Profile> | ||
<S.Image src={profile?.profileImageSource} alt="avatar" /> | ||
<S.Name>{profile?.name}</S.Name> | ||
</S.Profile> | ||
<S.Title>{folder}</S.Title> | ||
</> | ||
<S.HeroContainer> | ||
{isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<> | ||
<S.Profile> | ||
<S.Image src={data?.data[0].image_source} alt="avatar" /> | ||
<S.Name>{data?.data[0].name}</S.Name> | ||
</S.Profile> | ||
<S.Title>{folder?.name}</S.Title> | ||
</> | ||
)} | ||
</S.HeroContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import useSWR from "swr"; | ||
import { useEffect, useState } from "react"; | ||
import { DOMAIN_URL } from "@/common/constants"; | ||
|
||
export function useFolder(url: string) { | ||
const [accessToken, setAccessToken] = useState<string | null>(); | ||
|
||
// accessToken 없을때 401 에러나는 로직 | ||
// const fetcher = (url: string) => | ||
// fetch(`${DOMAIN_URL}${url}`, { | ||
// headers: { Authorization: `Bearer ${accessToken}` }, | ||
// }).then((res) => res.json()); | ||
|
||
const fetcher = (url: string) => { | ||
if (accessToken) { | ||
return fetch(`${DOMAIN_URL}${url}`, { | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
}).then((res) => res.json()); | ||
} | ||
}; | ||
|
||
const { data, isLoading, mutate } = useSWR(url, fetcher); | ||
|
||
useEffect(() => { | ||
if (localStorage.getItem("accessToken") !== null) { | ||
setAccessToken(localStorage.getItem("accessToken")); | ||
mutate(); | ||
} | ||
}, [mutate, accessToken]); | ||
|
||
return { | ||
data, | ||
isLoading, | ||
mutate, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters