Skip to content

Commit 5429169

Browse files
committed
Merge branch 'dev' into feature/enchance/misc
# Conflicts: # src/features/repo-explorer/components/index.tsx
2 parents 9e36e7a + 9b03a64 commit 5429169

File tree

20 files changed

+184
-101
lines changed

20 files changed

+184
-101
lines changed

src/app/header/hooks.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { KeyboardEventHandler } from "react";
2+
import { StringParam, useQueryParams } from "use-query-params";
3+
import { useHistory, useLocation } from "react-router-dom";
4+
import * as qs from "query-string";
5+
6+
// FIXME: get from `pages`?
7+
const SEARCH_URL = "/search";
8+
9+
/**
10+
* @hook Логика обработки инпута поиска
11+
*/
12+
export const useSearchInput = () => {
13+
// !!! FIXME: limit scope of query-params literals
14+
const [query] = useQueryParams({
15+
q: StringParam,
16+
type: StringParam,
17+
s: StringParam,
18+
o: StringParam,
19+
});
20+
const location = useLocation();
21+
const history = useHistory();
22+
23+
/**
24+
* Обработка инпута поиска
25+
*/
26+
const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = ({ key, currentTarget }) => {
27+
if (key === "Enter" && currentTarget.value) {
28+
const q = currentTarget.value;
29+
history.push(`${SEARCH_URL}?${qs.stringify({ ...query, q })}`);
30+
}
31+
};
32+
/**
33+
* Поисковой запрос
34+
* @remark Если не страница поиска - обнуляем инпут
35+
*/
36+
const searchValue = location.pathname === SEARCH_URL ? query.q ?? "" : "";
37+
38+
return { handleKeyDown, searchValue };
39+
};

src/app/header/index.tsx

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
1-
import React, { KeyboardEventHandler } from "react";
1+
import React from "react";
22
import { Layout, Input } from "antd";
3-
import { Link, useHistory, useLocation } from "react-router-dom";
4-
import { StringParam, useQueryParams } from "use-query-params";
5-
import * as qs from "query-string";
3+
import { Link } from "react-router-dom";
64
import { GITHUB_MAIN, GITHUB_FEEDBACK } from "shared/get-env";
75
import { Auth } from "features";
86
import { ReactComponent as IcLogo } from "./logo.svg";
7+
import { useSearchInput } from "./hooks";
98
import "./index.scss";
109

11-
// FIXME: get from `pages`?
12-
const SEARCH_URL = "/search";
13-
14-
/**
15-
* @hook Логика обработки инпута поиска
16-
*/
17-
const useSearchInput = () => {
18-
// !!! FIXME: limit scope of query-params literals
19-
const [query] = useQueryParams({
20-
q: StringParam,
21-
type: StringParam,
22-
s: StringParam,
23-
o: StringParam,
24-
});
25-
const location = useLocation();
26-
const history = useHistory();
27-
28-
/**
29-
* Обработка инпута поиска
30-
*/
31-
const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = ({ key, currentTarget }) => {
32-
if (key === "Enter" && currentTarget.value) {
33-
const q = currentTarget.value;
34-
history.push(`${SEARCH_URL}?${qs.stringify({ ...query, q })}`);
35-
}
36-
};
37-
/**
38-
* Поисковой запрос
39-
* @remark Если не страница поиска - обнуляем инпут
40-
*/
41-
const searchValue = location.pathname === SEARCH_URL ? query.q ?? "" : "";
42-
43-
return { handleKeyDown, searchValue };
44-
};
45-
4610
/**
4711
* Хедер приложения
4812
* @remark Содержит поисковой инпут с базовой логикой
@@ -66,10 +30,20 @@ const Header = () => {
6630
onKeyDown={handleKeyDown}
6731
/>
6832
)}
69-
<a className="m-4 text-gray-600" href={GITHUB_MAIN}>
33+
<a
34+
className="m-4 text-gray-600"
35+
href={GITHUB_MAIN}
36+
target="_blank"
37+
rel="noopener noreferrer"
38+
>
7039
GitHub
7140
</a>
72-
<a className="m-4 text-gray-600" href={GITHUB_FEEDBACK}>
41+
<a
42+
className="m-4 text-gray-600"
43+
href={GITHUB_FEEDBACK}
44+
target="_blank"
45+
rel="noopener noreferrer"
46+
>
7347
Feedback
7448
</a>
7549
</div>

src/app/index.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// NOTE: Временно используем вспомогательные utilities-классы, на время разработки прототипа приложения
22
@import "~tailwindcss/dist/utilities.css";
3-
@import "./vars.scss";
4-
@import "./normalize.scss";
5-
@import "./normalize-antd.scss";
6-
@import "./utils.scss";
3+
// css-переменные проекта
4+
@import "./styles/vars.scss";
5+
// нормализация стилей проекта
6+
@import "./styles/normalize.scss";
7+
// нормализация стилей antd компонентов
8+
@import "./styles/normalize-antd.scss";
9+
// классы-утилиты
10+
@import "./styles/utils.scss";
711

812
.gc-app {
913
display: flex;

src/features/auth/user/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import { Button } from "antd";
3+
import { Link } from "react-router-dom";
34
import { useAuth } from "../hooks";
45
import { routes } from "../consts";
56

@@ -18,9 +19,9 @@ const User = () => {
1819
{isAuth && (
1920
<>
2021
{/* FIXME: use h3 instead */}
21-
<a className="m-4 text-white" href={`/${viewer?.username}`}>
22+
<Link className="m-4 text-white" to={`/${viewer?.username}`}>
2223
{viewer?.username}
23-
</a>
24+
</Link>
2425
<Button className="m-4" href={routes.logout} onClick={logout}>
2526
Logout
2627
</Button>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { BranchIdentity, RepoIdentity } from "models";
2+
import { RepoBranchInfoQuery, useRepoDefaultBranchQuery } from "../queries.gen";
3+
4+
type Props = {
5+
repo: RepoIdentity;
6+
};
7+
8+
/**
9+
* @hook Получение текущей ветки репозитория
10+
*/
11+
export const useBranch = (repo: Props["repo"]) => {
12+
const { data } = useRepoDefaultBranchQuery({
13+
variables: {
14+
name: repo.name,
15+
owner: repo.owner,
16+
},
17+
});
18+
const branch = repo.branch || data?.repository?.defaultBranchRef?.name || "master";
19+
return { branch };
20+
};
21+
22+
/**
23+
* @hook Получение нужных полей по сфетченным данным по репозиторию
24+
*/
25+
export const useRepoDetails = (repoInfo: RepoBranchInfoQuery | undefined) => {
26+
const { repository } = repoInfo || {};
27+
const branches = (repository?.refs?.nodes || []).filter(
28+
(branch): branch is BranchIdentity => !!branch,
29+
);
30+
const files = Array.from(repository?.object?.entries ?? []).sort((a, b) =>
31+
b.type.localeCompare(a.type),
32+
);
33+
const target = repository?.ref?.target;
34+
const lastCommit =
35+
(target && {
36+
message: target.messageHeadline,
37+
login: target.author?.user?.login,
38+
avatarUrl: target.author?.user?.avatarUrl,
39+
name: target.author?.name,
40+
date: target.author?.date,
41+
}) ||
42+
undefined;
43+
44+
// Приходится фетчить файл по двум вариантам наименования, т.к. GitHub не умеет в insensitive case =(
45+
const readme = repository?.contentLower?.text || repository?.contentUpper?.text || "";
46+
return {
47+
branches,
48+
files,
49+
lastCommit,
50+
readme,
51+
};
52+
};

src/features/repo-explorer/components/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
22
import { RepoIdentity } from "models";
3-
import { useBranch, useRepoDetails } from "../hooks";
43
import { useRepoBranchInfoQuery } from "../queries.gen";
54
import RepoToolbar from "./toolbar";
65
import EntriesView from "./entries-view";
76
import RepoReadme from "./readme";
7+
import { useBranch, useRepoDetails } from "./hooks";
88

99
type Props = {
1010
repo: RepoIdentity;

0 commit comments

Comments
 (0)