1+ import { useEffect } from "react" ;
2+
3+ import { formatDistanceToNow } from "date-fns" ;
4+ import { ru } from "date-fns/locale" ;
5+ import { useUnit } from "effector-react" ;
6+ import { useParams , useNavigate } from "react-router-dom" ;
7+
18import { useReportPageSocket } from "@/hooks/useReportPageSocket" ;
29import { useSocketEvent } from "@/hooks/useSocketEvent" ;
10+ import { $combinedBugsStore } from "@/store" ;
11+ import { createLocalBugEvent } from "@/store/localBugs" ;
312import {
413 $initialReportStore ,
514 $titleStore ,
@@ -10,38 +19,16 @@ import {
1019 updateReportPathIdEvent ,
1120} from "@/store/report" ;
1221import { SocketEvent } from "@/webSocketApi/models" ;
13- import { formatDistanceToNow } from "date-fns" ;
14- import { ru } from "date-fns/locale" ;
15- import { useUnit , useStoreMap } from "effector-react" ;
16- import { useEffect } from "react" ;
17- import { useParams , useNavigate } from "react-router-dom" ;
18- import Bug from "./components/Bug/Bug" ;
19- import { $bugsData } from "@/store/bugs" ;
20- import { BugEntity } from "@/types/bug" ;
2122
22- function sortBugsByDate ( a : BugEntity , b : BugEntity ) {
23- return new Date ( b . createdAt ) . getTime ( ) - new Date ( a . createdAt ) . getTime ( ) ;
24- }
23+ import Bug from "./components/Bug/Bug" ;
2524
2625const ReportPage = ( ) => {
2726 const navigate = useNavigate ( ) ;
2827 const { reportId } = useParams ( ) ;
2928 const initialReport = useUnit ( $initialReportStore ) ;
3029 const title = useUnit ( $titleStore ) ;
3130 const creatorUserName = useUnit ( $creatorUserNameStore ) ;
32-
33- const bugs = useStoreMap ( {
34- store : $bugsData ,
35- keys : [ reportId ] ,
36- fn : ( { bugs, reportBugs } , [ currentReportId ] ) => {
37- if ( ! currentReportId ) return [ ] ;
38- const bugIds = reportBugs [ Number ( currentReportId ) ] || [ ] ;
39- return bugIds
40- . map ( ( id ) => bugs [ id ] )
41- . filter ( Boolean )
42- . sort ( sortBugsByDate ) ;
43- } ,
44- } ) ;
31+ const allBugs = useUnit ( $combinedBugsStore ) ;
4532
4633 useReportPageSocket ( ) ;
4734 useSocketEvent ( SocketEvent . ReportPatch , ( patch ) =>
@@ -51,7 +38,7 @@ const ReportPage = () => {
5138 // состояние страницы
5239 useEffect ( ( ) => {
5340 if ( reportId ) {
54- updateReportPathIdEvent ( parseInt ( reportId ) ) ;
41+ updateReportPathIdEvent ( Number ( reportId ) ) ;
5542 } else {
5643 updateReportPathIdEvent ( null ) ;
5744 }
@@ -64,6 +51,10 @@ const ReportPage = () => {
6451 }
6552 } , [ initialReport ?. id , reportId , navigate ] ) ;
6653
54+ const handleAddBugClick = ( ) => {
55+ createLocalBugEvent ( { reportId : Number ( reportId ) } ) ;
56+ } ;
57+
6758 return (
6859 < >
6960 < input
@@ -85,9 +76,15 @@ const ReportPage = () => {
8576 пользователем < strong > { creatorUserName || "Загрузка..." } </ strong >
8677 </ div >
8778 < div className = "flex flex-col gap-2" >
88- { bugs ? .map ( ( bug ) => (
89- < Bug key = { bug . id } bug = { bug } />
79+ { allBugs . map ( ( bug ) => (
80+ < Bug key = { bug . clientId } bug = { bug } />
9081 ) ) }
82+ < button
83+ className = "btn btn-outline btn-primary font-normal ml-auto"
84+ onClick = { handleAddBugClick }
85+ >
86+ Добавить баг
87+ </ button >
9188 </ div >
9289 </ >
9390 ) ;
0 commit comments