Skip to content

Commit 219364c

Browse files
authored
Merge pull request #87 from martis-git/feature/search-page
Add search page
2 parents 462dc13 + e2af4ce commit 219364c

File tree

28 files changed

+549
-89
lines changed

28 files changed

+549
-89
lines changed

package-lock.json

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"graphql": "^15.3.0",
2020
"node-sass": "^4.14.1",
2121
"normalize.css": "^8.0.1",
22-
"query-string": "^6.13.6",
22+
"query-string": "^6.13.7",
2323
"react": "^16.14.0",
2424
"react-dom": "^16.14.0",
2525
"react-router": "^5.2.0",
2626
"react-router-dom": "^5.2.0",
2727
"react-scripts": "3.4.3",
2828
"tailwindcss": "^1.9.5",
29-
"typescript": "^3.7.5"
29+
"typescript": "^3.7.5",
30+
"use-query-params": "^1.1.9"
3031
},
3132
"scripts": {
3233
"start": "react-scripts start",

src/app/header/index.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import React from "react";
22
import { Layout, Input } from "antd";
3+
import * as qs from "query-string";
34
import { Auth } from "features";
45
import ImgLogo from "./logo.png";
56
import "./index.scss";
67

78
const Header = () => {
89
const { isAuth } = Auth.useAuth();
10+
// !!! FIXME: limit scope of query-params literals
11+
// TODO: (wrap in QueryParamProvider) - wrap app with header instead of only content?
12+
// const [search] = useQueryParam("q", StringParam);
13+
const search = (qs.parse(window.location.search).q as string) || "";
914

1015
return (
1116
<Layout.Header className="header">
@@ -15,7 +20,20 @@ const Header = () => {
1520
<img className="header__logo" src={ImgLogo} alt="logo" width={48} height={48} />
1621
{!isAuth && <span className="gc-app__title text-white m-4">GITHUB-CLIENT</span>}
1722
</a>
18-
{isAuth && <Input className="header__search" placeholder="Search..." />}
23+
{isAuth && (
24+
<Input
25+
className="header__search"
26+
placeholder="Search..."
27+
defaultValue={search}
28+
onKeyDown={({ key, target }) => {
29+
// @ts-ignore FIXME: specify types
30+
if (key === "Enter" && target.value) {
31+
// @ts-ignore FIXME: specify types
32+
window.location.replace(`/search?q=${target.value}`);
33+
}
34+
}}
35+
/>
36+
)}
1937
</div>
2038
<Auth.User />
2139
</Layout.Header>

src/app/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import "~tailwindcss/dist/utilities.css";
33
@import "./vars.scss";
44
@import "./normalize.scss";
5+
@import "./utils.scss";
56

67
.gc-app {
78
display: flex;

src/app/utils.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.text-title {
2+
font-family: var(--ff-secondary);
3+
font-size: 20px;
4+
font-weight: var(--fw--medium);
5+
}

src/features/auth/router/index.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { lazy, Suspense } from "react";
22
import { BrowserRouter, Route, Switch } from "react-router-dom";
3+
import { QueryParamProvider } from "use-query-params";
34
import { Spin } from "antd";
45
import { useAuth } from "../hooks";
56

@@ -16,16 +17,19 @@ const Router = ({ children }: Props) => {
1617
return (
1718
<BrowserRouter>
1819
<Suspense fallback={<Spin />}>
19-
<Switch>
20-
{isAuth && children}
21-
{!isAuth && (
22-
<>
23-
<Route exact path="/" component={HomePage} />
24-
<Route exact path="/auth" component={AuthPage} />
25-
{/* <Redirect to="/" /> */}
26-
</>
27-
)}
28-
</Switch>
20+
{/* FIXME: wrap not on this level */}
21+
<QueryParamProvider ReactRouterRoute={Route}>
22+
<Switch>
23+
{isAuth && children}
24+
{!isAuth && (
25+
<>
26+
<Route exact path="/" component={HomePage} />
27+
<Route exact path="/auth" component={AuthPage} />
28+
{/* <Redirect to="/" /> */}
29+
</>
30+
)}
31+
</Switch>
32+
</QueryParamProvider>
2933
</Suspense>
3034
</BrowserRouter>
3135
);

src/features/repo-list/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import React from "react";
2+
import { Repo, Tabs } from "shared/components";
23
import { useReposQuery } from "./queries.gen";
3-
import Tab from "./tab";
4-
import RepoItem from "./repo-item";
54
import "./index.scss";
65

76
type Props = {
87
username: string;
98
};
109

10+
// FIXME: rename to UserRepoList? (coz - user as dep)
11+
1112
const RepoList = ({ username }: Props) => {
1213
const { data } = useReposQuery({
1314
variables: { login: username },
1415
});
1516

1617
return (
1718
<div className="repo-list">
18-
<div className="repo-list__tabs">
19-
<Tab name="Repositories" />
20-
</div>
19+
<Tabs className="repo-list__tabs">
20+
<Tabs.Item name="Repositories" />
21+
</Tabs>
2122
<div className="repo-list__items">
22-
{data?.user?.repositories.edges?.map((edge) => (
23+
{data?.user?.repositories.edges?.map((edge, index) => (
2324
// FIXME: destruct more elegant later
24-
<RepoItem key={edge?.node?.id} {...edge?.node} />
25+
<Repo key={index} {...edge?.node} />
2526
))}
2627
</div>
2728
</div>

src/features/repo-list/repo-item/index.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/features/repo-list/tab/index.scss

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/features/repo-list/tab/index.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)