Skip to content

Commit

Permalink
Merge pull request #87 from martis-git/feature/search-page
Browse files Browse the repository at this point in the history
Add search page
  • Loading branch information
azinit authored Nov 18, 2020
2 parents 462dc13 + e2af4ce commit 219364c
Show file tree
Hide file tree
Showing 28 changed files with 549 additions and 89 deletions.
19 changes: 16 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
"graphql": "^15.3.0",
"node-sass": "^4.14.1",
"normalize.css": "^8.0.1",
"query-string": "^6.13.6",
"query-string": "^6.13.7",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"tailwindcss": "^1.9.5",
"typescript": "^3.7.5"
"typescript": "^3.7.5",
"use-query-params": "^1.1.9"
},
"scripts": {
"start": "react-scripts start",
Expand Down
20 changes: 19 additions & 1 deletion src/app/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from "react";
import { Layout, Input } from "antd";
import * as qs from "query-string";
import { Auth } from "features";
import ImgLogo from "./logo.png";
import "./index.scss";

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

return (
<Layout.Header className="header">
Expand All @@ -15,7 +20,20 @@ const Header = () => {
<img className="header__logo" src={ImgLogo} alt="logo" width={48} height={48} />
{!isAuth && <span className="gc-app__title text-white m-4">GITHUB-CLIENT</span>}
</a>
{isAuth && <Input className="header__search" placeholder="Search..." />}
{isAuth && (
<Input
className="header__search"
placeholder="Search..."
defaultValue={search}
onKeyDown={({ key, target }) => {
// @ts-ignore FIXME: specify types
if (key === "Enter" && target.value) {
// @ts-ignore FIXME: specify types
window.location.replace(`/search?q=${target.value}`);
}
}}
/>
)}
</div>
<Auth.User />
</Layout.Header>
Expand Down
1 change: 1 addition & 0 deletions src/app/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "~tailwindcss/dist/utilities.css";
@import "./vars.scss";
@import "./normalize.scss";
@import "./utils.scss";

.gc-app {
display: flex;
Expand Down
5 changes: 5 additions & 0 deletions src/app/utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.text-title {
font-family: var(--ff-secondary);
font-size: 20px;
font-weight: var(--fw--medium);
}
24 changes: 14 additions & 10 deletions src/features/auth/router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { lazy, Suspense } from "react";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import { QueryParamProvider } from "use-query-params";
import { Spin } from "antd";
import { useAuth } from "../hooks";

Expand All @@ -16,16 +17,19 @@ const Router = ({ children }: Props) => {
return (
<BrowserRouter>
<Suspense fallback={<Spin />}>
<Switch>
{isAuth && children}
{!isAuth && (
<>
<Route exact path="/" component={HomePage} />
<Route exact path="/auth" component={AuthPage} />
{/* <Redirect to="/" /> */}
</>
)}
</Switch>
{/* FIXME: wrap not on this level */}
<QueryParamProvider ReactRouterRoute={Route}>
<Switch>
{isAuth && children}
{!isAuth && (
<>
<Route exact path="/" component={HomePage} />
<Route exact path="/auth" component={AuthPage} />
{/* <Redirect to="/" /> */}
</>
)}
</Switch>
</QueryParamProvider>
</Suspense>
</BrowserRouter>
);
Expand Down
15 changes: 8 additions & 7 deletions src/features/repo-list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import React from "react";
import { Repo, Tabs } from "shared/components";
import { useReposQuery } from "./queries.gen";
import Tab from "./tab";
import RepoItem from "./repo-item";
import "./index.scss";

type Props = {
username: string;
};

// FIXME: rename to UserRepoList? (coz - user as dep)

const RepoList = ({ username }: Props) => {
const { data } = useReposQuery({
variables: { login: username },
});

return (
<div className="repo-list">
<div className="repo-list__tabs">
<Tab name="Repositories" />
</div>
<Tabs className="repo-list__tabs">
<Tabs.Item name="Repositories" />
</Tabs>
<div className="repo-list__items">
{data?.user?.repositories.edges?.map((edge) => (
{data?.user?.repositories.edges?.map((edge, index) => (
// FIXME: destruct more elegant later
<RepoItem key={edge?.node?.id} {...edge?.node} />
<Repo key={index} {...edge?.node} />
))}
</div>
</div>
Expand Down
28 changes: 0 additions & 28 deletions src/features/repo-list/repo-item/index.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/features/repo-list/tab/index.scss

This file was deleted.

12 changes: 0 additions & 12 deletions src/features/repo-list/tab/index.tsx

This file was deleted.

Loading

0 comments on commit 219364c

Please sign in to comment.