-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/138/profile card #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,9 +44,26 @@ export default function GatheringListSection({ id }: GatheringListSectionProps) | |||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // TODO: μΆν μλ¬, λ‘λ© μμ | ||||||||||||||||||||||||||||||||||||||||||||
| if (isLoading) return <p>λ‘λ© μ€...</p>; | ||||||||||||||||||||||||||||||||||||||||||||
| if (error) return <p>λ°μ΄ν°λ₯Ό λΆλ¬μ€λ λ° μ€ν¨νμ΅λλ€</p>; | ||||||||||||||||||||||||||||||||||||||||||||
| if (!gatheringList || gatheringList.length === 0) return <p>λ°μ΄ν°κ° μμ΅λλ€.</p>; | ||||||||||||||||||||||||||||||||||||||||||||
| if (isLoading) | ||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||
| <div className="flex items-center justify-center"> | ||||||||||||||||||||||||||||||||||||||||||||
| <p>λ‘λ© μ€...</p> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (error) | ||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||
| <div className="flex items-center justify-center"> | ||||||||||||||||||||||||||||||||||||||||||||
| <p>λ°μ΄ν°λ₯Ό λΆλ¬μ€λ λ° μ€ν¨νμ΅λλ€</p> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion μλ¬ μν μ²λ¦¬ κ°μ νμ μλ¬ λ©μμ§κ° λ무 μΌλ°μ μ΄λ©°, μ¬μ©μμκ² μΆ©λΆν μ 보λ ν΄κ²° λ°©λ²μ μ 곡νμ§ μμ΅λλ€. λ€μκ³Ό κ°μ κ°μ μ μ μλ립λλ€: - <div className="flex items-center justify-center">
- <p>λ°μ΄ν°λ₯Ό λΆλ¬μ€λ λ° μ€ν¨νμ΅λλ€</p>
+ <div className="flex items-center justify-center min-h-[200px]">
+ <div className="flex flex-col items-center gap-4">
+ <p className="text-red-500">λ°μ΄ν°λ₯Ό λΆλ¬μ€λ λ° μ€ν¨νμ΅λλ€</p>
+ <p className="text-sm text-gray-600">{error instanceof Error ? error.message : 'μ μ μλ μ€λ₯κ° λ°μνμ΅λλ€'}</p>
+ <button
+ onClick={() => window.location.reload()}
+ className="px-4 py-2 bg-primary text-white rounded-md hover:bg-primary-dark"
+ >
+ λ€μ μλ
+ </button>
+ </div>
+ </div>π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (!gatheringList || gatheringList.length === 0) | ||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||
| <div className="flex items-center justify-center"> | ||||||||||||||||||||||||||||||||||||||||||||
| <p>λ°μ΄ν°κ° μμ΅λλ€.</p> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,44 +15,31 @@ import ProfileCardPresenter from './presenter'; | |
| export default function ProfileCard() { | ||
| const router = useRouter(); | ||
| const { isAuth } = useAuth(); | ||
| const { data: user } = useUser(); | ||
|
|
||
| // const { rehydrated, setUser } = useAuthStore(); | ||
| // const [user, setLocalUser] = useState<User | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
| const { data: user, isLoading: userLoading, refetch: refetchUser } = useUser(); | ||
| const [profileImageUrl, setProfileImageUrl] = useState<string>(''); | ||
| const [isAuthChecked, setIsAuthChecked] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| const checkAuthAndLoadUser = async () => { | ||
| // if (!rehydrated) return; // μν 볡μμ΄ μλ£λμ§ μμμΌλ©΄ λκΈ° | ||
|
|
||
| if (!isAuth) { | ||
| router.push('/login'); // μΈμ¦λμ§ μμ κ²½μ° λ¦¬λλ μ | ||
| return; | ||
| } | ||
| if (userLoading) return; | ||
|
|
||
| setIsLoading(true); | ||
|
|
||
| try { | ||
| const updatedUser = await fetchUpdatedUser(); | ||
| // setLocalUser(updatedUser); | ||
| // setUser(updatedUser); | ||
| setProfileImageUrl(updatedUser.profileImageUrl); | ||
| } catch { | ||
| toast.error('μ μ μ 보λ₯Ό κ°μ Έμ€λ λ° μ€ν¨νμ΅λλ€.'); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }; | ||
| if (user) { | ||
| setIsAuthChecked(true); | ||
| } else if (!isAuth) { | ||
| toast.error('λ‘κ·ΈμΈμ΄ νμν©λλ€.'); | ||
| router.push('/login'); | ||
| } else { | ||
| setIsAuthChecked(true); | ||
| } | ||
| }, [user, userLoading, isAuth, router]); | ||
|
|
||
| checkAuthAndLoadUser(); | ||
| // }, [isAuth, rehydrated, router, setUser]); | ||
| }, [isAuth, router]); | ||
| useEffect(() => { | ||
| if (user?.profileImageUrl) { | ||
| setProfileImageUrl(user.profileImageUrl); | ||
| } | ||
| }, [user]); | ||
|
|
||
| // if (!rehydrated) return null; | ||
| if (!isAuth) return null; | ||
| if (isLoading) return <div>λ‘λ© μ€...</div>; | ||
| if (!user) return <div>μ μ μ 보λ₯Ό λΆλ¬μ€μ§ λͺ»νμ΅λλ€.</div>; | ||
| if (userLoading || !isAuthChecked) return <div>λ‘λ© μ€...</div>; | ||
| if (!user) return null; | ||
|
|
||
| const handleEdit = () => { | ||
| const input = document.createElement('input'); | ||
|
|
@@ -72,10 +59,8 @@ export default function ProfileCard() { | |
| const tempUrl = URL.createObjectURL(file); | ||
| setProfileImageUrl(tempUrl); | ||
|
|
||
| const updatedUser = await fetchUpdatedUser(); | ||
| const newProfileImageUrl = `${updatedUser.profileImageUrl}?timestamp=${new Date().getTime()}`; | ||
| setProfileImageUrl(newProfileImageUrl); | ||
| // setUser({ ...updatedUser, profileImageUrl: newProfileImageUrl }); | ||
| await refetchUser(); | ||
| toast.success('νλ‘ν μ΄λ―Έμ§κ° μ λ°μ΄νΈλμμ΅λλ€.'); | ||
|
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. νμΌ μ λ‘λ 보μμ κ°νν΄μ£ΌμΈμ. νμΌ ν¬κΈ° κ²μ¦μ μ λμ΄μμ§λ§, νμΌ νμμ λν μΆκ° κ²μ¦μ΄ νμν©λλ€. λ€μκ³Ό κ°μ΄ νμΌ νμ κ²μ¦μ μΆκ°ν΄μ£ΌμΈμ: input.onchange = async (event) => {
const file = (event.target as HTMLInputElement)?.files?.[0];
if (file) {
+ const validTypes = ['image/jpeg', 'image/png', 'image/jpg'];
+ if (!validTypes.includes(file.type)) {
+ toast.error('PNG, JPG νμμ μ΄λ―Έμ§λ§ μ
λ‘λ κ°λ₯ν©λλ€.');
+ return;
+ }
if (file.size > 5 * 1024 * 1024) {
alert('5MB μ΄νμ νμΌλ§ μ
λ‘λ κ°λ₯ν©λλ€.');
return;
}Also applies to: 75-75 |
||
| } catch (error) { | ||
| toast.error('νμΌ μ λ‘λμ μ€ν¨νμ΅λλ€.'); | ||
| } | ||
|
|
@@ -87,10 +72,8 @@ export default function ProfileCard() { | |
| const handleDeleteProfile = async () => { | ||
| try { | ||
| await resetUserProfileImage(); | ||
| const updatedUser = await fetchUpdatedUser(); | ||
| await refetchUser(); | ||
| setProfileImageUrl(''); // μ΄κΈ°νλ μ΄λ―Έμ§ λ°μ | ||
| // setLocalUser(updatedUser); | ||
| // setUser(updatedUser); | ||
| toast.success('νλ‘ν μ΄λ―Έμ§κ° μ΄κΈ°νλμμ΅λλ€.'); | ||
| } catch (error) { | ||
| toast.error('νλ‘ν μ΄λ―Έμ§ μ΄κΈ°νμ μ€ν¨νμ΅λλ€.'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
μλ¬ λ©μμ§λ₯Ό λ ꡬ체μ μΌλ‘ νμν΄μ£ΌμΈμ
νμ¬ μλ¬ λ©μμ§κ° λ무 μΌλ°μ μ λλ€. μ¬μ©μκ° λ¬Έμ λ₯Ό μ΄ν΄νκ³ λμ²ν μ μλλ‘ λ ꡬ체μ μΈ μ 보λ₯Ό μ 곡ν΄μΌ ν©λλ€.
λ€μκ³Ό κ°μ΄ κ°μ ν΄λ³΄μΈμ:
if (error) return ( <div className="flex items-center justify-center"> - <p>λ°μ΄ν°λ₯Ό λΆλ¬μ€λ λ° μ€ν¨νμ΅λλ€</p> + <div className="text-center"> + <p className="text-red-500 mb-2">λ°μ΄ν°λ₯Ό λΆλ¬μ€λ λ° μ€ν¨νμ΅λλ€</p> + <p className="text-sm text-gray-600"> + {error instanceof Error ? error.message : 'μ μ ν λ€μ μλν΄μ£ΌμΈμ'} + </p> + </div> </div> );π Committable suggestion