1
1
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket" ;
2
2
import type { FullIndexation } from "~dumili-services/indexation/types" ;
3
- import type { issueSuggestion , storySuggestion } from "~prisma/client_dumili" ;
3
+ import type { issueSuggestion } from "~prisma/client_dumili" ;
4
+ import { ui } from "./ui" ;
4
5
5
6
export const suggestions = defineStore ( "suggestions" , ( ) => {
6
7
const { indexationSocket, setIndexationSocketFromId } = inject (
7
8
dumiliSocketInjectionKey ,
8
9
) ! ;
9
- const indexation = ref < FullIndexation > ( ) ,
10
- acceptedStories = ref < Record < number , storySuggestion | undefined > > ( { } ) ;
10
+ const indexation = ref < FullIndexation > ( ) ;
11
11
12
12
const loadIndexation = async ( indexationId ?: string ) => {
13
13
setIndexationSocketFromId ( indexationId || indexation . value ! . id ) ;
14
+ const currentEntryId = ui ( ) . currentEntry ?. id ;
14
15
const data = await indexationSocket . value ! . services . loadIndexation ( ) ;
15
16
if ( "error" in data ) {
16
17
console . error ( data . error ) ;
17
18
return ;
18
19
}
19
20
indexation . value = data . indexation ;
21
+ if ( currentEntryId ) {
22
+ ui ( ) . currentEntry = indexation . value ! . entries . find (
23
+ ( { id } ) => id === currentEntryId ,
24
+ ) ;
25
+ }
20
26
} ;
21
27
22
28
const createIssueSuggestion = async (
@@ -26,48 +32,18 @@ export const suggestions = defineStore("suggestions", () => {
26
32
> ,
27
33
) => indexationSocket . value ! . services . createIssueSuggestion ( suggestion ) ;
28
34
29
- watch (
30
- ( ) => indexation . value ?. entries ,
31
- async ( entries ) => {
32
- acceptedStories . value = { } ;
33
- for ( const {
34
- id,
35
- storySuggestions,
36
- acceptedStorySuggestionId,
37
- } of entries || [ ] ) {
38
- const acceptedStory = storySuggestions . find (
39
- ( suggestion ) => suggestion . id === acceptedStorySuggestionId ,
40
- ) ;
41
-
42
- if ( acceptedStory ) {
43
- acceptedStories . value [ id ] = acceptedStory ;
44
- }
45
- }
46
- } ,
47
- ) ;
48
-
49
35
const acceptedIssue = computed ( {
50
36
get : ( ) => indexation . value ?. acceptedIssueSuggestion ,
51
37
set : ( value ) => ( indexation . value ! . acceptedIssueSuggestion = value ! ) ,
52
38
} ) ;
53
39
54
- watch ( acceptedIssue , async ( acceptedIssue ) => {
55
- indexationSocket . value ! . services . acceptIssueSuggestion (
56
- acceptedIssue ?. id || null ,
57
- ) ;
58
- } ) ;
59
-
60
40
return {
61
41
indexation,
62
42
loadIndexation,
63
43
createIssueSuggestion,
64
44
hasPendingIssueSuggestions : computed (
65
- ( ) => false , //pendingIssueSuggestions.value.length > 0
45
+ ( ) => false , //pendingIssueSuggestions.value.length
66
46
) ,
67
47
acceptedIssue,
68
- acceptedStories,
69
- acceptedStoryKinds : computed ( ( ) =>
70
- indexation . value ?. entries . groupBy ( "id" , "acceptedStoryKind" ) ,
71
- ) ,
72
48
} ;
73
49
} ) ;
0 commit comments