Skip to content

Commit 0da2dcc

Browse files
authored
Merge pull request #1075 from appare45/issue1054
ユーザー検索画面を固定できるように
2 parents 22e7ca1 + 220d46b commit 0da2dcc

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

atcoder-problems-frontend/src/App.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ const App: React.FC = () => {
3737
<ThemeProvider>
3838
<Router>
3939
<div>
40-
<div className="sticky-top">
41-
<NavigationBar />
42-
</div>
40+
<NavigationBar />
4341

4442
<Container
4543
className="my-5"

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import { NavLink as RouterLink, Route } from "react-router-dom";
33
import {
44
Collapse,
@@ -17,8 +17,8 @@ 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";
21+
import { UserSearchBar } from "./UserSearchBar";
2222

2323
export const NavigationBar = () => {
2424
const loginState = useLoginState().data;
@@ -28,8 +28,10 @@ export const NavigationBar = () => {
2828

2929
const [isOpen, setIsOpen] = React.useState(false);
3030

31+
const [isNavigationFixed, setIsNavigationFixed] = useState(true);
32+
3133
return (
32-
<>
34+
<div className={isNavigationFixed ? "sticky-top" : ""}>
3335
<Navbar color="dark" dark expand="lg">
3436
<NavbarBrand tag={RouterLink} to="/" className="mb-0 h1">
3537
AtCoder Problems
@@ -176,8 +178,11 @@ export const NavigationBar = () => {
176178
"/list/:userIds([a-zA-Z0-9_]*)*",
177179
]}
178180
>
179-
<UserSearchBar isOpen={isOpen} />
181+
<UserSearchBar
182+
isNavigationFixed={isNavigationFixed}
183+
setIsNavigationFixed={() => setIsNavigationFixed((e) => !e)}
184+
/>
180185
</Route>
181-
</>
186+
</div>
182187
);
183188
};

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

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React 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";
@@ -44,7 +47,8 @@ const extractUserIds = (
4447
};
4548

4649
interface Props {
47-
isOpen: boolean;
50+
isNavigationFixed: boolean;
51+
setIsNavigationFixed: () => void;
4852
}
4953

5054
const generatePath = (
@@ -108,8 +112,8 @@ export const UserSearchBar = (props: Props) => {
108112
className="border-bottom"
109113
style={{ padding: 0 }}
110114
>
111-
<Collapse isOpen={props.isOpen} navbar>
112-
<Nav navbar style={{ padding: "0.5rem 1rem" }}>
115+
<Nav navbar style={{ padding: "0.5rem 1rem", width: "100%" }}>
116+
<NavItem>
113117
<Form inline>
114118
<Input
115119
className="mt-2 mr-2 mt-lg-0 mt-md-0"
@@ -126,7 +130,6 @@ export const UserSearchBar = (props: Props) => {
126130
placeholder={loggedInUserId ? loggedInUserId : "User ID"}
127131
onChange={(e): void => setUserId(e.target.value)}
128132
/>
129-
130133
<Input
131134
className="mt-2 mr-2 mt-lg-0 mt-md-0"
132135
style={{ width: 160 }}
@@ -142,28 +145,42 @@ export const UserSearchBar = (props: Props) => {
142145
placeholder="Rival ID, ..."
143146
onChange={(e): void => setRivalIdString(e.target.value)}
144147
/>
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-
148+
</Form>
149+
</NavItem>
150+
<NavItem style={{ flexGrow: 1 }}>
151+
<Row className="justify-content-between align-items-center">
152+
<Col className="col-auto">
153+
<ButtonGroup className="mt-2 mb-0 mt-lg-0 mt-md-0">
154+
<Button tag={RouterLink} to={tablePath} color="light">
155+
Table
156+
</Button>
157+
158+
<Button tag={RouterLink} to={listPath} color="light">
159+
List
160+
</Button>
161+
162+
<Button
163+
disabled={userId.length === 0 && loggedInUserId.length === 0}
164+
tag={RouterLink}
165+
to={userPath}
166+
color="light"
167+
>
168+
User
169+
</Button>
170+
</ButtonGroup>
171+
</Col>
172+
<Col className="col-auto">
155173
<Button
156-
disabled={userId.length === 0 && loggedInUserId.length === 0}
157-
tag={RouterLink}
158-
to={userPath}
159174
color="light"
175+
active={props.isNavigationFixed}
176+
onClick={props.setIsNavigationFixed}
160177
>
161-
User
178+
<GoPin />
162179
</Button>
163-
</ButtonGroup>
164-
</Form>
165-
</Nav>
166-
</Collapse>
180+
</Col>
181+
</Row>
182+
</NavItem>
183+
</Nav>
167184
</Navbar>
168185
);
169186
};

0 commit comments

Comments
 (0)