@@ -2,12 +2,12 @@ import { useEffect } from "react";
22
33import { formatDistanceToNow } from "date-fns" ;
44import { ru } from "date-fns/locale" ;
5- import { useUnit , useStoreMap } from "effector-react" ;
5+ import { useUnit } from "effector-react" ;
66import { useParams , useNavigate } from "react-router-dom" ;
77
88import { useReportPageSocket } from "@/hooks/useReportPageSocket" ;
99import { useSocketEvent } from "@/hooks/useSocketEvent" ;
10- import { $allBugsStore } from "@/store" ;
10+ import { $combinedBugsStore } from "@/store" ;
1111import { createLocalBugEvent } from "@/store/localBugs" ;
1212import {
1313 $initialReportStore ,
@@ -18,7 +18,6 @@ import {
1818 saveTitleEvent ,
1919 updateReportPathIdEvent ,
2020} from "@/store/report" ;
21- import { BugClientEntity } from "@/types/bug" ;
2221import { SocketEvent } from "@/webSocketApi/models" ;
2322
2423import Bug from "./components/Bug/Bug" ;
@@ -29,40 +28,7 @@ const ReportPage = () => {
2928 const initialReport = useUnit ( $initialReportStore ) ;
3029 const title = useUnit ( $titleStore ) ;
3130 const creatorUserName = useUnit ( $creatorUserNameStore ) ;
32-
33- const allBugs = useStoreMap ( {
34- store : $allBugsStore ,
35- keys : [ reportId ] ,
36- fn : ( [ bugsData , localBugs ] , [ currentReportId ] ) => {
37- if ( ! currentReportId ) return [ ] ;
38-
39- const { bugs, reportBugs } = bugsData ;
40- const bugIds = reportBugs [ Number ( currentReportId ) ] || [ ] ;
41-
42- // 1) Собираем мапу bug.id → clientId для любого локального багa
43- const clientIdMap : Record < number , number > = { } ;
44- localBugs . forEach ( ( bug ) => {
45- // у вас в store и локальный, и промоушн лежат, нам нужна обоих запись
46- clientIdMap [ bug . id ] = bug . clientId ;
47- } ) ;
48-
49- // 2) Берём бекендовые баги и подставляем правильный clientId
50- const bugsFromStore = bugIds
51- . map ( ( id : number ) => bugs [ id ] )
52- . filter ( Boolean )
53- . map ( ( bug ) => ( {
54- ...bug ,
55- clientId : clientIdMap [ bug . id ] ?? bug . id , // ← вот здесь ключ сохраняется прежним
56- } ) ) ;
57-
58- // 3) К этим добавляем только ещё непромоушненные локальные
59- const pendingLocals = localBugs . filter (
60- ( bug ) => bug . reportId === Number ( currentReportId ) && bug . isLocalOnly
61- ) ;
62-
63- return [ ...bugsFromStore , ...pendingLocals ] ;
64- } ,
65- } ) ;
31+ const allBugs = useUnit ( $combinedBugsStore ) ;
6632
6733 useReportPageSocket ( ) ;
6834 useSocketEvent ( SocketEvent . ReportPatch , ( patch ) =>
@@ -110,7 +76,7 @@ const ReportPage = () => {
11076 пользователем < strong > { creatorUserName || "Загрузка..." } </ strong >
11177 </ div >
11278 < div className = "flex flex-col gap-2" >
113- { allBugs . map ( ( bug : BugClientEntity ) => (
79+ { allBugs . map ( ( bug ) => (
11480 < Bug key = { bug . clientId } bug = { bug } />
11581 ) ) }
11682 < button
0 commit comments