Skip to content

Commit 2df7e7c

Browse files
committed
Merge branch 'main' into search
2 parents 499d24d + bd7142b commit 2df7e7c

File tree

3 files changed

+77
-114
lines changed

3 files changed

+77
-114
lines changed

web/app/chat/page.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import RoomList from "~/components/chat/RoomList";
88
import { RoomWindow } from "~/components/chat/RoomWindow";
99
import FullScreenCircularProgress from "~/components/common/FullScreenCircularProgress";
1010

11+
export default function Chat() {
12+
return (
13+
<Suspense fallback={<FullScreenCircularProgress />}>
14+
<ChatListContent />
15+
</Suspense>
16+
);
17+
}
18+
1119
function ChatListContent() {
1220
const searchParams = useSearchParams();
1321

@@ -28,11 +36,3 @@ function ChatListContent() {
2836
<RoomList roomsData={state.data} />
2937
);
3038
}
31-
32-
export default function Chat() {
33-
return (
34-
<Suspense fallback={<FullScreenCircularProgress />}>
35-
<ChatListContent />
36-
</Suspense>
37-
);
38-
}

web/components/BottomBar.tsx

Lines changed: 56 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,67 @@
1-
import ChatIcon from "@mui/icons-material/Chat";
2-
import HomeIcon from "@mui/icons-material/Home";
3-
import PeopleIcon from "@mui/icons-material/People";
4-
import SearchIcon from "@mui/icons-material/Search";
5-
import SettingsIcon from "@mui/icons-material/Settings";
6-
import { BottomNavigation, BottomNavigationAction, Box } from "@mui/material";
71
import Link from "next/link";
2+
import { MdHome } from "react-icons/md";
3+
import { MdPeople } from "react-icons/md";
4+
import { MdChat } from "react-icons/md";
5+
import { MdSettings } from "react-icons/md";
86

97
type Props = {
108
activeTab: "0_home" | "1_friends" | "2_chat" | "3_settings" | "4_search";
119
};
1210

11+
function BottomBarCell({
12+
label,
13+
href,
14+
iconComponent,
15+
isActive,
16+
}: {
17+
label: string;
18+
href: string;
19+
iconComponent: React.ReactNode;
20+
isActive: boolean;
21+
}) {
22+
return (
23+
<Link
24+
href={href}
25+
className={`focus:bg-gray-300 ${isActive ? "active text-primary" : "text-secondary"}`}
26+
>
27+
{iconComponent}
28+
<span
29+
className={`text-xs ${isActive ? "text-primary" : "text-gray-500"}`}
30+
>
31+
{label}
32+
</span>
33+
</Link>
34+
);
35+
}
36+
1337
export default function BottomBar(props: Props) {
1438
const { activeTab } = props;
1539
return (
16-
<Box sx={{ position: "fixed", bottom: 0, left: 0, right: 0 }}>
17-
{/* TODO: 単に Viewer として BottomNavigation を使用しているので Box 等で置き換える */}
18-
<BottomNavigation
19-
showLabels
20-
value={activeTab}
21-
sx={{
22-
width: "100%",
23-
bottom: 0,
24-
borderTop: "1px solid",
25-
borderColor: "primary.main",
26-
}}
27-
>
28-
<BottomNavigationAction
29-
component={Link}
30-
href="/home"
31-
label="Home"
32-
icon={
33-
<HomeIcon
34-
sx={{
35-
color:
36-
activeTab === "0_home" ? "primary.main" : "secondary.main",
37-
}}
38-
/>
39-
}
40-
/>
41-
<BottomNavigationAction
42-
component={Link}
43-
href="/friends"
44-
label="Friends"
45-
icon={
46-
<PeopleIcon
47-
sx={{
48-
color:
49-
activeTab === "1_friends" ? "primary.main" : "secondary.main",
50-
}}
51-
/>
52-
}
53-
/>
54-
<BottomNavigationAction
55-
component={Link}
56-
href="/chat"
57-
label="Chat"
58-
icon={
59-
<ChatIcon
60-
sx={{
61-
color:
62-
activeTab === "2_chat" ? "#primary.main" : "secondary.main",
63-
}}
64-
/>
65-
}
66-
/>
67-
<BottomNavigationAction
68-
component={Link}
69-
href="/settings"
70-
label="Settings"
71-
icon={
72-
<SettingsIcon
73-
sx={{
74-
color:
75-
activeTab === "3_settings"
76-
? "primary.main"
77-
: "secondary.main",
78-
}}
79-
/>
80-
}
81-
/>
82-
<BottomNavigationAction
83-
component={Link}
84-
href="/search"
85-
label="Search"
86-
icon={
87-
<SearchIcon
88-
sx={{
89-
color:
90-
activeTab === "4_search" ? "primary.main" : "secondary.main",
91-
}}
92-
/>
93-
}
94-
/>
95-
</BottomNavigation>
96-
</Box>
40+
<div className="btm-nav flex max-h-14 w-full flex-row">
41+
<BottomBarCell
42+
label="Home"
43+
href="/home"
44+
isActive={activeTab === "0_home"}
45+
iconComponent={<MdHome className="text-2xl" />}
46+
/>
47+
<BottomBarCell
48+
label="Friends"
49+
href="/friends"
50+
isActive={activeTab === "1_friends"}
51+
iconComponent={<MdPeople className="text-2xl" />}
52+
/>
53+
<BottomBarCell
54+
label="Chat"
55+
href="/chat"
56+
isActive={activeTab === "2_chat"}
57+
iconComponent={<MdChat className="text-2xl" />}
58+
/>
59+
<BottomBarCell
60+
label="Settings"
61+
href="/settings"
62+
isActive={activeTab === "3_settings"}
63+
iconComponent={<MdSettings className="text-2xl" />}
64+
/>
65+
</div>
9766
);
9867
}

web/firebase/auth/lib.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,19 @@ import { app } from "../config";
55

66
export class ErrUnauthorized extends Error {}
77

8-
let user: User;
9-
let token: string;
10-
118
const auth = getAuth(app);
12-
onAuthStateChanged(auth, async (u: User | null) => {
13-
if (u != null) {
14-
user = u;
15-
token = await user.getIdToken();
16-
}
17-
});
189

19-
async function refreshToken() {
20-
token = await user.getIdToken(true);
21-
}
10+
// 認証状態の完了を待機するためのPromiseを作成
11+
const token = new Promise<string>((resolve) => {
12+
onAuthStateChanged(auth, async (u: User | null) => {
13+
if (u != null) {
14+
resolve(await u.getIdToken());
15+
}
16+
});
17+
});
2218

2319
export async function getIdToken(): Promise<IDToken> {
24-
if (token) return token;
25-
await refreshToken();
26-
return token;
20+
return await token;
2721
}
2822

2923
type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
@@ -39,19 +33,19 @@ export async function credFetch(
3933
path: string,
4034
body?: unknown,
4135
): Promise<Response> {
42-
const idToken = await getIdToken();
36+
let idToken = await getIdToken();
4337
const init: RequestInit = { method };
4438
if (body) {
4539
init.body = JSON.stringify(body);
4640
init.headers = {
4741
"Content-Type": "application/json",
4842
};
4943
}
50-
5144
let res = await fetch(`${path}?token=${idToken}`, init);
45+
5246
if (res.status === 401) {
53-
await refreshToken();
54-
res = await fetch(`${path}?token=${idToken}`);
47+
idToken = await getIdToken();
48+
res = await fetch(`${path}?token=${idToken}`, init);
5549
}
5650

5751
return res;

0 commit comments

Comments
 (0)