Skip to content

Commit b37821d

Browse files
committed
dumili: wip
1 parent e4028d7 commit b37821d

File tree

12 files changed

+187
-196
lines changed

12 files changed

+187
-196
lines changed

apps/dumili/api/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ model storyKindSuggestion {
7272

7373
model storySuggestion {
7474
id Int @id @default(autoincrement())
75-
storycode String? @db.VarChar(19)
75+
storycode String @db.VarChar(19)
7676
entryId Int @map("entry_id")
7777
ocrDetailsId Int? @map("ocr_details_id")
7878
acceptedOnEntries entry[] @relation("entry_accepted_story_suggested_idTostory_suggestion")

apps/dumili/api/services/indexation/index.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ export default (io: Server) => {
186186
suggestionId === null
187187
? { disconnect: true }
188188
: {
189-
connect: {
190-
id: suggestionId,
191-
indexationId: indexationSocket.data.indexation.id,
192-
},
189+
connect: {
190+
id: suggestionId,
191+
indexationId: indexationSocket.data.indexation.id,
193192
},
193+
},
194194
},
195195
where: {
196196
id: indexationSocket.data.indexation.id,
@@ -236,10 +236,10 @@ export default (io: Server) => {
236236

237237
indexationSocket.on(
238238
"acceptStorySuggestion",
239-
async (storySuggestionId, callback) => {
239+
async (entryId, storySuggestionId, callback) => {
240240
const entry = indexationSocket.data.indexation.entries.find(
241-
({ storySuggestions }) =>
242-
storySuggestions.some(({ id }) => id === storySuggestionId),
241+
({ id, storySuggestions }) =>
242+
entryId === id && storySuggestionId === null || storySuggestions.some(({ id }) => id === storySuggestionId),
243243
);
244244
if (!entry) {
245245
callback({
@@ -451,14 +451,7 @@ const acceptStorySuggestion = async (
451451
) =>
452452
prisma.entry.update({
453453
data: {
454-
acceptedStoryKind:
455-
suggestionId === null
456-
? { disconnect: true }
457-
: {
458-
connect: {
459-
id: suggestionId,
460-
},
461-
},
454+
acceptedStorySuggestionId: suggestionId
462455
},
463456
where: {
464457
id: entryId,
@@ -471,14 +464,7 @@ const acceptStoryKindSuggestion = (
471464
) =>
472465
prisma.entry.update({
473466
data: {
474-
acceptedStoryKind:
475-
suggestionId === null
476-
? { disconnect: true }
477-
: {
478-
connect: {
479-
id: suggestionId,
480-
},
481-
},
467+
acceptedStoryKindSuggestionId: suggestionId,
482468
},
483469
where: {
484470
id: entryId,

apps/dumili/api/services/indexation/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default abstract class {
8585
) => void;
8686

8787
abstract acceptStorySuggestion: (
88+
entryId: entry["id"],
8889
storySuggestionId: storySuggestion["id"] | null,
8990
callback: (
9091
data: Errorable<

apps/dumili/src/components/DumiliBook.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
>
3333
<div
3434
v-if="hoveredEntry"
35-
:class="`position-absolute start-0 w-100 h-100 striped kind-${acceptedStoryKinds?.[hoveredEntry!.id]?.kind}`"
35+
:class="`position-absolute start-0 w-100 h-100 striped kind-${hoveredEntry?.acceptedStoryKind?.kind}`"
3636
></div>
3737
<template v-if="displayRatioCropped && naturalToDisplayRatio">
3838
<div
@@ -144,7 +144,7 @@ const coverWidth = ref<number | null>(null);
144144
const coverHeight = ref<number | null>(null);
145145
const currentPage = ref(0);
146146
147-
const { indexation, acceptedStoryKinds } = storeToRefs(suggestions());
147+
const { indexation } = storeToRefs(suggestions());
148148
const { hoveredEntry } = storeToRefs(ui());
149149
150150
const isSinglePage = computed(() => indexation.value?.pages.length === 1);

apps/dumili/src/components/Entry.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ watch(
150150
entry.value.brokenpagedenominator,
151151
]),
152152
() => {
153-
debugger;
154153
const { entirepages, brokenpagenumerator, brokenpagedenominator } =
155154
entry.value;
156155
indexationSocket.value!.services.updateEntryLength(entry.value.id, {
@@ -161,14 +160,11 @@ watch(
161160
},
162161
);
163162
164-
const { acceptedStories } = storeToRefs(suggestions());
165163
const { storyDetails } = storeToRefs(coa());
166164
const { showAiDetectionsOn } = storeToRefs(ui());
167165
168166
const pages = computed(() => getEntryPages(indexation.value!, entry.value.id));
169167
170-
const acceptedStory = computed(() => acceptedStories.value[entry.value.id]);
171-
172168
const storyKindAiSuggestion = computed(() =>
173169
entry.value.storyKindSuggestions.find(({ isChosenByAi }) => isChosenByAi),
174170
);
@@ -177,7 +173,7 @@ const storyAiSuggestions = computed(() =>
177173
entry.value.storySuggestions.filter(({ ocrDetailsId }) => ocrDetailsId),
178174
);
179175
180-
const storycode = computed(() => acceptedStory.value?.storycode);
176+
const storycode = computed(() => entry.value.acceptedStory?.storycode);
181177
const title = computed(() => entry.value.title || $t("Sans titre"));
182178
183179
const urlEncodedStorycode = computed(

apps/dumili/src/components/IssueSuggestionList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ const createAndAcceptIssueSuggestion = async (data: {
5454
};
5555
5656
watch(
57-
() => indexation.value!.acceptedIssueSuggestion,
58-
(suggestion) => {
57+
() => indexation.value?.acceptedIssueSuggestion?.id,
58+
(suggestionId) => {
5959
indexationSocket.value!.services.acceptIssueSuggestion(
60-
suggestion?.id || null,
60+
suggestionId || null,
6161
);
6262
},
6363
);

apps/dumili/src/components/StorySuggestionList.vue

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@toggle-customize-form="showEntrySelect = $event"
88
>
99
<template #item="suggestion">
10-
<Story v-if="suggestion.storycode" :storycode="suggestion.storycode">
10+
<Story :storycode="suggestion.storycode">
1111
<template #suffix>
1212
<span
1313
title="Le type de l'histoire sélectionnée ne correspond pas au type de l'entrée"
@@ -51,35 +51,44 @@ const { indexation } = storeToRefs(suggestions());
5151
const showEntrySelect = ref(false);
5252
const { storyDetails, storyversionDetails } = storeToRefs(coa());
5353
54-
const acceptStory = async (storycode: storySuggestion["storycode"]) => {
55-
let storySuggestionId = entry.value.storySuggestions.find(
54+
const acceptStory = async (storycode: storySuggestion["storycode"] | null) => {
55+
let storySuggestion = entry.value.storySuggestions.find(
5656
(s) => s.storycode === storycode,
57-
)?.id;
58-
debugger;
59-
if (!storySuggestionId) {
57+
);
58+
if (!storySuggestion && storycode) {
6059
const result = await indexationSocket.value!.services.createStorySuggestion(
6160
{
6261
entryId: entry.value.id,
63-
storycode: storycode!,
62+
storycode,
6463
},
6564
);
66-
if ("error" in result) {
67-
console.error(result.error);
68-
return;
69-
}
65+
storySuggestion = result.createdStorySuggestion;
7066
}
71-
if (entry.value.acceptedStory?.storycode !== storycode) {
72-
await indexationSocket.value!.services.acceptStorySuggestion(
73-
storySuggestionId || null,
67+
await indexationSocket.value!.services.acceptStorySuggestion(
68+
entry.value.id,
69+
storySuggestion?.id || null,
70+
);
71+
if (storySuggestion?.id) {
72+
const correspondingStoryKindId = entry.value.storyKindSuggestions.find(
73+
({ kind }) =>
74+
kind ===
75+
storyversionDetails.value[
76+
storyDetails.value[storySuggestion.storycode]
77+
.originalstoryversioncode!
78+
].kind,
79+
)!.id;
80+
indexationSocket.value!.services.acceptStoryKindSuggestion(
81+
entry.value.id,
82+
correspondingStoryKindId,
7483
);
75-
await loadIndexation(indexation.value!.id);
7684
}
85+
await loadIndexation(indexation.value!.id);
7786
};
7887
7988
watch(
80-
() => entry.value.acceptedStory,
81-
async (story) => {
82-
acceptStory(story!.storycode);
89+
() => entry.value.acceptedStory?.storycode || null,
90+
async (storycode) => {
91+
acceptStory(storycode);
8392
},
8493
);
8594
</script>

apps/dumili/src/components/TableOfContents.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
:grid="[1, pageHeight]"
7777
:h="entry.entirepages * pageHeight"
7878
:min-height="pageHeight - 1"
79-
:class-name="`entry col w-100 kind-${acceptedStoryKinds?.[entry.id]?.kind} ${hoveredEntry === entry && 'striped'} ${currentEntry?.id === entry.id && 'current'}`"
79+
:class-name="`entry col w-100 kind-${entry.acceptedStoryKind?.kind} ${hoveredEntry === entry && 'striped'} ${currentEntry?.id === entry.id && 'current'}`"
8080
:title="`${entry.title || 'Inconnu'} (${getUserFriendlyPageCount(
8181
entry,
8282
)})`"
@@ -143,8 +143,7 @@ defineProps<{
143143
const { indexationSocket } = inject(dumiliSocketInjectionKey)!;
144144
145145
const { loadIndexation } = suggestions();
146-
const { acceptedStoryKinds } = storeToRefs(suggestions());
147-
const { hoveredEntry, selectedPageNumber } = storeToRefs(ui());
146+
const { hoveredEntry, currentEntry, selectedPageNumber } = storeToRefs(ui());
148147
const indexation = storeToRefs(suggestions()).indexation as Ref<FullIndexation>;
149148
const currentPage = defineModel<number>();
150149
@@ -156,8 +155,6 @@ const { status: aiStatus } = useAi();
156155
157156
const pageHeight = 50;
158157
159-
const currentEntry = ref<FullEntry>(getEntryFromPage(indexation.value!, 0)!);
160-
161158
const issueAiSuggestion = computed(() =>
162159
indexation.value.issueSuggestions.find(({ isChosenByAi }) => isChosenByAi),
163160
);

apps/dumili/src/components/TextEditor.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}}</b-alert
77
>
88
<b-form-textarea
9+
v-if="acceptedStories"
910
v-model="textContent"
1011
:rows="Object.keys(acceptedStories).length + 1"
1112
readonly
@@ -19,6 +20,7 @@ const { t: $t } = useI18n();
1920
2021
import { suggestions } from "~/stores/suggestions";
2122
import { getEntryPages } from "~dumili-utils/entryPages";
23+
import { storySuggestion } from "~prisma/client_dumili";
2224
import { socketInjectionKey as dmSocketInjectionKey } from "~web/src/composables/useDmSocket";
2325
2426
const { storyDetails } = storeToRefs(coa());
@@ -30,17 +32,24 @@ const {
3032
} = inject(dmSocketInjectionKey)!;
3133
3234
const textContentError = ref("");
33-
const { acceptedStories, acceptedIssue: issue } = storeToRefs(suggestions());
35+
const { acceptedIssue: issue } = storeToRefs(suggestions());
36+
37+
const acceptedStories = computed(() =>
38+
indexation.value?.entries
39+
.map((entry) => entry.acceptedStory)
40+
.filter((story): story is storySuggestion => story !== null),
41+
);
3442
3543
const storiesWithDetails =
3644
ref<Awaited<ReturnType<typeof getStoriesWithDetails>>>();
3745
38-
const getStoriesWithDetails = async (
39-
stories: (typeof acceptedStories)["value"],
40-
) =>
46+
const getStoriesWithDetails = async (stories: storySuggestion[]) =>
4147
await Promise.all(
4248
Object.values(stories)
43-
.filter((story) => story !== undefined)
49+
.filter(
50+
(story): story is storySuggestion & { storycode: string } =>
51+
story !== undefined && story.storycode !== null,
52+
)
4453
.map(async (story) => ({
4554
...story,
4655
...storyDetails.value[story!.storycode],
@@ -93,7 +102,7 @@ const textContent = computed(() => {
93102
watch(
94103
acceptedStories,
95104
async (value) => {
96-
if (issue.value?.issuecode) {
105+
if (value && issue.value?.issuecode) {
97106
storiesWithDetails.value = await getStoriesWithDetails(value);
98107
}
99108
},

apps/dumili/src/stores/suggestions.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket";
22
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";
45

56
export const suggestions = defineStore("suggestions", () => {
67
const { indexationSocket, setIndexationSocketFromId } = inject(
78
dumiliSocketInjectionKey,
89
)!;
9-
const indexation = ref<FullIndexation>(),
10-
acceptedStories = ref<Record<number, storySuggestion | undefined>>({});
10+
const indexation = ref<FullIndexation>();
1111

1212
const loadIndexation = async (indexationId?: string) => {
1313
setIndexationSocketFromId(indexationId || indexation.value!.id);
14+
const currentEntryId = ui().currentEntry?.id;
1415
const data = await indexationSocket.value!.services.loadIndexation();
1516
if ("error" in data) {
1617
console.error(data.error);
1718
return;
1819
}
1920
indexation.value = data.indexation;
21+
if (currentEntryId) {
22+
ui().currentEntry = indexation.value!.entries.find(
23+
({ id }) => id === currentEntryId,
24+
);
25+
}
2026
};
2127

2228
const createIssueSuggestion = async (
@@ -26,48 +32,18 @@ export const suggestions = defineStore("suggestions", () => {
2632
>,
2733
) => indexationSocket.value!.services.createIssueSuggestion(suggestion);
2834

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-
4935
const acceptedIssue = computed({
5036
get: () => indexation.value?.acceptedIssueSuggestion,
5137
set: (value) => (indexation.value!.acceptedIssueSuggestion = value!),
5238
});
5339

54-
watch(acceptedIssue, async (acceptedIssue) => {
55-
indexationSocket.value!.services.acceptIssueSuggestion(
56-
acceptedIssue?.id || null,
57-
);
58-
});
59-
6040
return {
6141
indexation,
6242
loadIndexation,
6343
createIssueSuggestion,
6444
hasPendingIssueSuggestions: computed(
65-
() => false, //pendingIssueSuggestions.value.length > 0
45+
() => false, //pendingIssueSuggestions.value.length
6646
),
6747
acceptedIssue,
68-
acceptedStories,
69-
acceptedStoryKinds: computed(() =>
70-
indexation.value?.entries.groupBy("id", "acceptedStoryKind"),
71-
),
7248
};
7349
});

0 commit comments

Comments
 (0)