-
Notifications
You must be signed in to change notification settings - Fork 0
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
通知が1回のみ表示されるようにした #107
通知が1回のみ表示されるようにした #107
Changes from 2 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 |
---|---|---|
|
@@ -28,7 +28,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { | |
|
||
// 未ログインの場合 | ||
// エラーメッセージを取得 | ||
const data = { error: session.get('loginError') }; | ||
const data = { error: session.get('error') }; | ||
|
||
return json<LoaderData>(data, { | ||
headers: { | ||
|
@@ -49,9 +49,11 @@ export const action = async ({ request }: ActionFunctionArgs) => { | |
|
||
// ログインに成功した場合 | ||
if (response.status === 200) { | ||
session.flash('loginSuccess', 'ログインに成功しました'); | ||
session.set('userId', response.data.id.toString()); | ||
session.set('sessionToken', response.data.sessionToken!); | ||
// FIXME: homeのloaderで読み出してもCookieが削除されない | ||
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. これはまだ解決してないの? 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. そのコメントは消しておかねば |
||
session.flash('success', 'ログインに成功しました'); | ||
|
||
return redirect('/home/mypage', { | ||
headers: { | ||
'Set-Cookie': await commitSession(session), | ||
|
@@ -63,20 +65,20 @@ export const action = async ({ request }: ActionFunctionArgs) => { | |
switch (response.status) { | ||
case 400: | ||
// prettier-ignore | ||
session.flash('loginError', 'メールアドレスまたはパスワードが間違っています'); | ||
session.flash('error', 'メールアドレスまたはパスワードが間違っています'); | ||
break; | ||
case 401: | ||
// prettier-ignore | ||
session.flash('loginError', 'メールアドレスまたはパスワードが間違っています'); | ||
session.flash('error', 'メールアドレスまたはパスワードが間違っています'); | ||
break; | ||
case 404: | ||
session.flash('loginError', 'ユーザーが見つかりません'); | ||
session.flash('error', 'ユーザーが見つかりません'); | ||
break; | ||
case 500: | ||
session.flash('loginError', 'サーバーエラーが発生しました'); | ||
session.flash('error', 'サーバーエラーが発生しました'); | ||
break; | ||
default: | ||
session.flash('loginError', 'エラーが発生しました'); | ||
session.flash('error', 'エラーが発生しました'); | ||
} | ||
|
||
return redirect('/auth/login', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,14 @@ export const loader = async ({ request }: LoaderFunctionArgs) => { | |
const session = await getSession(request.headers.get('Cookie')); | ||
|
||
const userId = session.get('userId'); | ||
const success = session.get('logoutSuccess'); | ||
const error = session.get('logoutError'); | ||
const success = session.get('success'); | ||
const error = session.get('error'); | ||
|
||
return json<LoaderData>( | ||
{ | ||
userId: userId, | ||
success: success, | ||
error: success ? undefined : error, | ||
error: error, | ||
}, | ||
{ | ||
headers: { | ||
|
@@ -54,14 +54,16 @@ export const action = async ({ request }: ActionFunctionArgs) => { | |
if (response.status === 204) { | ||
session.unset('userId'); | ||
session.unset('sessionToken'); | ||
session.flash('logoutSuccess', 'ログアウトに成功しました'); | ||
session.flash('success', 'ログアウトに成功しました'); | ||
|
||
return redirect('/home', { | ||
headers: { | ||
'Set-Cookie': await commitSession(session), | ||
}, | ||
}); | ||
} else { | ||
session.flash('logoutError', 'ログアウトに失敗しました'); | ||
session.flash('error', 'ログアウトに失敗しました'); | ||
|
||
return redirect('/home', { | ||
headers: { | ||
'Set-Cookie': await commitSession(session), | ||
|
@@ -92,13 +94,20 @@ const Home = () => { | |
} else { | ||
setUser(undefined); | ||
} | ||
if (success) { | ||
successNotification(success); | ||
} else if (error) { | ||
errorNotification(error); | ||
} | ||
} | ||
}, [navigation.state]); | ||
}, [userId]); | ||
|
||
useEffect(() => { | ||
if (success) { | ||
successNotification(success); | ||
} | ||
}, [success]); | ||
|
||
useEffect(() => { | ||
if (error) { | ||
errorNotification(error); | ||
} | ||
}, [error]); | ||
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. 結局このやり方にしたんか 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. ログイン画面ではerrorではなくnavigation.stateを依存関係にしているので、エラーが発生した回数だけ通知が表示される 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. 他の画面ではおなじerrorは連続で呼ばれないだろってイメージ? 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. なるほど、ログイン画面以外で同じエラーが連続して発生したときにちゃんと通知がでるんか?ってことだね 通知がでてから一度loaderが走れば、errorがundefinedになるので、同じエラーでも通知が出てくれると思う 手元の環境で試してみる。エラーは再現が難しいので、本の削除を2回繰り返したときに、成功の通知が2回とも出るか?を確かめてみる。 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. 2回は出なかった 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.
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. ならマージして良いよ! |
||
|
||
return ( | ||
<AppShell header={{ height: 70 }} padding={{ default: 'md', sm: 'sm' }}> | ||
|
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.
sessionは一律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.
異なるrouteが同じflashを読み出さないように、flashの種類を分けてたんだけど、エラーメッセージの増加に伴って管理コストが増大するので、1つに絞ることにした