Skip to content

Commit d23b026

Browse files
author
Victoria Ivanova
committed
refactoring of home page; remove constants, leave const folder
1 parent 7c6c34f commit d23b026

File tree

10 files changed

+85
-81
lines changed

10 files changed

+85
-81
lines changed

frontend/src/const/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { StatusMeta } from "@/types/status";
2+
13
export enum BugStatuses {
24
IN_PROGRESS = 0,
35
READY = 1,
@@ -14,3 +16,29 @@ export enum RequestStates {
1416
DONE = 2,
1517
ERROR = 3,
1618
}
19+
20+
export const reportStatusMap: Record<number, StatusMeta> = {
21+
0: {
22+
title: "В работе",
23+
color: "badge-error",
24+
border: "border-error",
25+
},
26+
1: {
27+
title: "Решён",
28+
color: "badge-success",
29+
border: "border-success",
30+
},
31+
};
32+
33+
export const bugStatusMap: Record<number, StatusMeta> = {
34+
0: {
35+
title: "Открыт",
36+
color: "badge-error",
37+
border: "border-error",
38+
},
39+
1: {
40+
title: "Исправлен",
41+
color: "badge-success",
42+
border: "border-success",
43+
},
44+
};

frontend/src/constants/status.ts

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

frontend/src/pages/Home/Home.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.section {
2-
display: flex;
3-
flex-direction: column;
4-
gap: 1em;
5-
}
61

72
.section-title {
83
font-size: 1.5em;

frontend/src/pages/Home/Home.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
loadReportsFx,
55
$responsibleReports,
66
$participantReports,
7-
} from "../../store/reportsSummary";
8-
import ReportSummary from "./components/ReportSummary/ReportSummary";
7+
} from "@/store/reportsSummary";
8+
import Section from "./components/Section/Section";
99
import "./Home.css";
1010

1111
const Main = () => {
@@ -18,25 +18,9 @@ const Main = () => {
1818

1919
return (
2020
<div className="text-base-content auto-rows-min gap-4">
21-
<section className="flex flex-column section">
22-
<h2 className="section-title text-base-content">Ответственный</h2>
23-
<div className="reports-summary-wrapper">
24-
{!!responsibleReports.length &&
25-
responsibleReports.map((report) => (
26-
<ReportSummary key={report.id} report={report} highlight />
27-
))}
28-
</div>
29-
</section>
21+
<Section title="Ответственный" reports={responsibleReports} />
3022
<div className="divider section-divider"></div>
31-
<section className="flex flex-column section">
32-
<h2 className="section-title text-base-content">Участник</h2>
33-
<div className="reports-summary-wrapper">
34-
{!!participantReports.length &&
35-
participantReports.map((report) => (
36-
<ReportSummary key={report.id} report={report} />
37-
))}
38-
</div>
39-
</section>
23+
<Section title="Участник" reports={participantReports} />
4024
</div>
4125
);
4226
};

frontend/src/pages/Home/components/ReportSummary/ReportSummary.css

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

frontend/src/pages/Home/components/ReportSummary/ReportSummary.tsx renamed to frontend/src/pages/Home/components/Section/ReportSummary.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { useNavigate } from "react-router-dom";
2-
3-
import "./ReportSummary.css";
42
import { Report } from "@/types/report";
53

64
type ReportProps = {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Report } from "@/types/report";
2+
import ReportSummary from "./ReportSummary";
3+
4+
type Props = {
5+
title: string;
6+
reports: Report[];
7+
};
8+
9+
const Section = ({ title, reports }: Props) => {
10+
return (
11+
<section className="flex flex-col gap-3">
12+
<h2 className="section-title text-base-content">{title}</h2>
13+
<div className="reports-summary-wrapper">
14+
{!!reports.length &&
15+
reports.map((report) => (
16+
<ReportSummary key={report.id} report={report} highlight />
17+
))}
18+
</div>
19+
</section>
20+
);
21+
};
22+
23+
export default Section;

frontend/src/pages/Search/components/SearchResults/SearchResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useUnit } from "effector-react";
22
import { $searchResult } from "@/store/search";
33
import { formatDistanceToNow } from "date-fns";
44
import { ru } from "date-fns/locale";
5-
import { getStatusMeta } from "@/constants/status";
5+
import getStatusMeta from "@/utils/getStatusMeta";
66
import { useNavigate } from "react-router-dom";
77
import { ReportResponse } from "@/api/reports/models";
88

frontend/src/types/status.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type StatusMeta = {
2+
title: string;
3+
color:
4+
| "badge-success"
5+
| "badge-warning"
6+
| "badge-error"
7+
| "badge-info"
8+
| "badge-neutral";
9+
border: string;
10+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { bugStatusMap, reportStatusMap } from "@/const";
2+
import { StatusMeta } from "@/types/status";
3+
4+
type EntityType = "bug" | "report";
5+
6+
const unknownStatus: StatusMeta = {
7+
title: "Неизвестно",
8+
color: "badge-neutral",
9+
border: "border-neutral",
10+
};
11+
12+
export default function getStatusMeta(
13+
type: EntityType,
14+
status: number
15+
): StatusMeta {
16+
if (type === "report") return reportStatusMap[status] ?? unknownStatus;
17+
if (type === "bug") return bugStatusMap[status] ?? unknownStatus;
18+
return unknownStatus;
19+
}

0 commit comments

Comments
 (0)