Skip to content

Commit c45967c

Browse files
committed
feat: toggle fixing user search navigation
1 parent 22e7ca1 commit c45967c

File tree

3 files changed

+55
-41
lines changed

3 files changed

+55
-41
lines changed

atcoder-problems-frontend/src/App.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ 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";
3435

3536
const App: React.FC = () => {
3637
return (
@@ -41,6 +42,16 @@ const App: React.FC = () => {
4142
<NavigationBar />
4243
</div>
4344

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>
54+
4455
<Container
4556
className="my-5"
4657
style={{ width: "100%", maxWidth: "90%" }}

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { NavLink as RouterLink, Route } from "react-router-dom";
2+
import { NavLink as RouterLink } from "react-router-dom";
33
import {
44
Collapse,
55
DropdownItem,
@@ -17,7 +17,6 @@ import { useLoginState } from "../api/InternalAPIClient";
1717
import { useLoginLink } from "../utils/Url";
1818
import { ACCOUNT_INFO } from "../utils/RouterPath";
1919
import * as UserState from "../utils/UserState";
20-
import { UserSearchBar } from "./UserSearchBar";
2120
import { ThemeSelector } from "./ThemeSelector";
2221

2322
export const NavigationBar = () => {
@@ -168,16 +167,6 @@ export const NavigationBar = () => {
168167
</Nav>
169168
</Collapse>
170169
</Navbar>
171-
172-
<Route
173-
path={[
174-
"/user/:userIds([a-zA-Z0-9_]+)+",
175-
"/table/:userIds([a-zA-Z0-9_]*)*",
176-
"/list/:userIds([a-zA-Z0-9_]*)*",
177-
]}
178-
>
179-
<UserSearchBar isOpen={isOpen} />
180-
</Route>
181170
</>
182171
);
183172
};

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

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from "react";
1+
import React, { useState } from "react";
2+
import { GoPin } from "react-icons/go";
23
import {
34
NavLink as RouterLink,
45
useLocation,
@@ -7,11 +8,13 @@ import {
78
import {
89
Button,
910
ButtonGroup,
11+
Col,
1012
Form,
1113
Input,
1214
Nav,
1315
Navbar,
14-
Collapse,
16+
NavItem,
17+
Row,
1518
} from "reactstrap";
1619
import { useLoginState } from "../api/InternalAPIClient";
1720
import { extractRivalsParam, normalizeUserId } from "../utils";
@@ -43,10 +46,6 @@ const extractUserIds = (
4346
return { userId, rivalIdString };
4447
};
4548

46-
interface Props {
47-
isOpen: boolean;
48-
}
49-
5049
const generatePath = (
5150
kind: PageKind,
5251
userId: string,
@@ -56,7 +55,7 @@ const generatePath = (
5655
return "/" + kind + "/" + users.join("/");
5756
};
5857

59-
export const UserSearchBar = (props: Props) => {
58+
export const UserSearchBar = () => {
6059
const { pathname } = useLocation();
6160
const loginState = useLoginState().data;
6261
const pageKind = extractPageKind(pathname);
@@ -67,6 +66,8 @@ export const UserSearchBar = (props: Props) => {
6766

6867
const loggedInUserId = UserState.loggedInUserId(loginState) ?? "";
6968

69+
const [userSearchBarIsFixed, setUserSearchBarIsFixed] = useState(false);
70+
7071
const [userId, setUserId] = React.useState(pathUserId ?? "");
7172
const [rivalIdString, setRivalIdString] = React.useState(
7273
pathRivalIdString ?? ""
@@ -105,11 +106,11 @@ export const UserSearchBar = (props: Props) => {
105106
color="light"
106107
light
107108
expand="md"
108-
className="border-bottom"
109+
className={`${userSearchBarIsFixed ? "sticky-top" : ""} border-bottom`}
109110
style={{ padding: 0 }}
110111
>
111-
<Collapse isOpen={props.isOpen} navbar>
112-
<Nav navbar style={{ padding: "0.5rem 1rem" }}>
112+
<Nav navbar style={{ padding: "0.5rem 1rem", width: "100%" }}>
113+
<NavItem>
113114
<Form inline>
114115
<Input
115116
className="mt-2 mr-2 mt-lg-0 mt-md-0"
@@ -126,7 +127,6 @@ export const UserSearchBar = (props: Props) => {
126127
placeholder={loggedInUserId ? loggedInUserId : "User ID"}
127128
onChange={(e): void => setUserId(e.target.value)}
128129
/>
129-
130130
<Input
131131
className="mt-2 mr-2 mt-lg-0 mt-md-0"
132132
style={{ width: 160 }}
@@ -142,28 +142,42 @@ export const UserSearchBar = (props: Props) => {
142142
placeholder="Rival ID, ..."
143143
onChange={(e): void => setRivalIdString(e.target.value)}
144144
/>
145-
146-
<ButtonGroup className="mt-2 mb-0 mt-lg-0 mt-md-0">
147-
<Button tag={RouterLink} to={tablePath} color="light">
148-
Table
149-
</Button>
150-
151-
<Button tag={RouterLink} to={listPath} color="light">
152-
List
153-
</Button>
154-
145+
</Form>
146+
</NavItem>
147+
<NavItem style={{ flexGrow: 1 }}>
148+
<Row className="justify-content-between align-items-center">
149+
<Col className="col-auto">
150+
<ButtonGroup className="mt-2 mb-0 mt-lg-0 mt-md-0">
151+
<Button tag={RouterLink} to={tablePath} color="light">
152+
Table
153+
</Button>
154+
155+
<Button tag={RouterLink} to={listPath} color="light">
156+
List
157+
</Button>
158+
159+
<Button
160+
disabled={userId.length === 0 && loggedInUserId.length === 0}
161+
tag={RouterLink}
162+
to={userPath}
163+
color="light"
164+
>
165+
User
166+
</Button>
167+
</ButtonGroup>
168+
</Col>
169+
<Col className="col-auto">
155170
<Button
156-
disabled={userId.length === 0 && loggedInUserId.length === 0}
157-
tag={RouterLink}
158-
to={userPath}
159171
color="light"
172+
active={userSearchBarIsFixed}
173+
onClick={() => setUserSearchBarIsFixed((e) => !e)}
160174
>
161-
User
175+
<GoPin />
162176
</Button>
163-
</ButtonGroup>
164-
</Form>
165-
</Nav>
166-
</Collapse>
177+
</Col>
178+
</Row>
179+
</NavItem>
180+
</Nav>
167181
</Navbar>
168182
);
169183
};

0 commit comments

Comments
 (0)