Skip to content

Commit fd4e436

Browse files
committed
fix: fix all navigation
1 parent c45967c commit fd4e436

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

atcoder-problems-frontend/src/App.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,13 @@ import { ACCOUNT_INFO } from "./utils/RouterPath";
3131
import { ThemeProvider } from "./components/ThemeProvider";
3232
import { caseInsensitiveUserId } from "./utils";
3333
import { PROBLEM_ID_SEPARATE_SYMBOL } from "./utils/QueryString";
34-
import { UserSearchBar } from "./components/UserSearchBar";
3534

3635
const App: React.FC = () => {
3736
return (
3837
<ThemeProvider>
3938
<Router>
4039
<div>
41-
<div className="sticky-top">
42-
<NavigationBar />
43-
</div>
44-
45-
<Route
46-
path={[
47-
"/user/:userIds([a-zA-Z0-9_]+)+",
48-
"/table/:userIds([a-zA-Z0-9_]*)*",
49-
"/list/:userIds([a-zA-Z0-9_]*)*",
50-
]}
51-
>
52-
<UserSearchBar />
53-
</Route>
40+
<NavigationBar />
5441

5542
<Container
5643
className="my-5"

atcoder-problems-frontend/src/components/NavigationBar.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from "react";
2-
import { NavLink as RouterLink } from "react-router-dom";
1+
import React, { useState } from "react";
2+
import { NavLink as RouterLink, Route } from "react-router-dom";
33
import {
44
Collapse,
55
DropdownItem,
@@ -18,6 +18,7 @@ import { useLoginLink } from "../utils/Url";
1818
import { ACCOUNT_INFO } from "../utils/RouterPath";
1919
import * as UserState from "../utils/UserState";
2020
import { ThemeSelector } from "./ThemeSelector";
21+
import { UserSearchBar } from "./UserSearchBar";
2122

2223
export const NavigationBar = () => {
2324
const loginState = useLoginState().data;
@@ -27,8 +28,10 @@ export const NavigationBar = () => {
2728

2829
const [isOpen, setIsOpen] = React.useState(false);
2930

31+
const [isNavigationFixed, setIsNavigationFixed] = useState(true);
32+
3033
return (
31-
<>
34+
<div className={isNavigationFixed ? "sticky-top" : ""}>
3235
<Navbar color="dark" dark expand="lg">
3336
<NavbarBrand tag={RouterLink} to="/" className="mb-0 h1">
3437
AtCoder Problems
@@ -167,6 +170,19 @@ export const NavigationBar = () => {
167170
</Nav>
168171
</Collapse>
169172
</Navbar>
170-
</>
173+
174+
<Route
175+
path={[
176+
"/user/:userIds([a-zA-Z0-9_]+)+",
177+
"/table/:userIds([a-zA-Z0-9_]*)*",
178+
"/list/:userIds([a-zA-Z0-9_]*)*",
179+
]}
180+
>
181+
<UserSearchBar
182+
isNavigationFixed={isNavigationFixed}
183+
setIsNavigationFixed={() => setIsNavigationFixed((e) => !e)}
184+
/>
185+
</Route>
186+
</div>
171187
);
172188
};

atcoder-problems-frontend/src/components/UserSearchBar.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React from "react";
22
import { GoPin } from "react-icons/go";
33
import {
44
NavLink as RouterLink,
@@ -46,6 +46,11 @@ const extractUserIds = (
4646
return { userId, rivalIdString };
4747
};
4848

49+
type Props = {
50+
isNavigationFixed: boolean;
51+
setIsNavigationFixed: () => void;
52+
};
53+
4954
const generatePath = (
5055
kind: PageKind,
5156
userId: string,
@@ -55,7 +60,7 @@ const generatePath = (
5560
return "/" + kind + "/" + users.join("/");
5661
};
5762

58-
export const UserSearchBar = () => {
63+
export const UserSearchBar = (props: Props) => {
5964
const { pathname } = useLocation();
6065
const loginState = useLoginState().data;
6166
const pageKind = extractPageKind(pathname);
@@ -66,8 +71,6 @@ export const UserSearchBar = () => {
6671

6772
const loggedInUserId = UserState.loggedInUserId(loginState) ?? "";
6873

69-
const [userSearchBarIsFixed, setUserSearchBarIsFixed] = useState(false);
70-
7174
const [userId, setUserId] = React.useState(pathUserId ?? "");
7275
const [rivalIdString, setRivalIdString] = React.useState(
7376
pathRivalIdString ?? ""
@@ -106,7 +109,7 @@ export const UserSearchBar = () => {
106109
color="light"
107110
light
108111
expand="md"
109-
className={`${userSearchBarIsFixed ? "sticky-top" : ""} border-bottom`}
112+
className="border-bottom"
110113
style={{ padding: 0 }}
111114
>
112115
<Nav navbar style={{ padding: "0.5rem 1rem", width: "100%" }}>
@@ -169,8 +172,8 @@ export const UserSearchBar = () => {
169172
<Col className="col-auto">
170173
<Button
171174
color="light"
172-
active={userSearchBarIsFixed}
173-
onClick={() => setUserSearchBarIsFixed((e) => !e)}
175+
active={props.isNavigationFixed}
176+
onClick={props.setIsNavigationFixed}
174177
>
175178
<GoPin />
176179
</Button>

0 commit comments

Comments
 (0)