Skip to content

Commit

Permalink
dumili: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Nov 4, 2024
1 parent 0e6d010 commit fdfad78
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
30 changes: 12 additions & 18 deletions apps/dumili/api/services/indexation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NamespaceWithData, SessionDataWithIndexation } from "~/index";
import { prisma } from "~/index";
import CoaServices from "~dm-services/coa/types";
import { storyKinds } from "~dumili-types/storyKinds";
import { getEntryPages } from "~dumili-utils/entryPages";
import { getEntryFromPage, getEntryPages } from "~dumili-utils/entryPages";
import type {
entry,
page,
Expand Down Expand Up @@ -89,12 +89,6 @@ export default (io: Server) => {
.use(RequiredAuthMiddleware)
.use(getIndexationMiddleware)
.on("connection", (indexationSocket) => {
const getEntryFromPage = async (pageId: page["id"]) =>
indexationSocket.data.indexation.entries.find(({ id }) =>
getEntryPages(indexationSocket.data.indexation, id).some(
({ id }) => id === pageId,
),
);

const setInferredEntryStoryKind = async (entryId: entry["id"]) => {
const indexation = indexationSocket.data.indexation;
Expand Down Expand Up @@ -192,11 +186,11 @@ export default (io: Server) => {
suggestionId === null
? { disconnect: true }
: {
connect: {
id: suggestionId,
indexationId: indexationSocket.data.indexation.id,
},
connect: {
id: suggestionId,
indexationId: indexationSocket.data.indexation.id,
},
},
},
where: {
id: indexationSocket.data.indexation.id,
Expand Down Expand Up @@ -318,7 +312,7 @@ export default (io: Server) => {
const page = indexation.pages.find(({ id }) => id === pageId)!;

await setKumikoInferredPageStoryKinds([page]);
const entry = (await getEntryFromPage(pageId))!;
const entry = (getEntryFromPage(indexation, pageId))!;
await setInferredEntryStoryKind(entry.id);

callback({ status: "OK" });
Expand Down Expand Up @@ -461,10 +455,10 @@ const acceptStorySuggestion = async (
suggestionId === null
? { disconnect: true }
: {
connect: {
id: suggestionId,
},
connect: {
id: suggestionId,
},
},
},
where: {
id: entryId,
Expand All @@ -481,10 +475,10 @@ const acceptStoryKindSuggestion = (
suggestionId === null
? { disconnect: true }
: {
connect: {
id: suggestionId,
},
connect: {
id: suggestionId,
},
},
},
where: {
id: entryId,
Expand Down
34 changes: 19 additions & 15 deletions apps/dumili/src/components/TableOfContents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
onEntryResizeStop(idx, height)
"
@click="
if (entry !== currentEntry)
currentPage = getFirstPageOfEntry(indexation.entries, idx);
currentPage = getFirstPageOfEntry(indexation.entries, entry.id)
"
></vue-draggable-resizable>
<b-button
Expand Down Expand Up @@ -139,7 +138,10 @@
<script setup lang="ts">
import useAi from "~/composables/useAi";
import { dumiliSocketInjectionKey } from "~/composables/useDumiliSocket";
import { getFirstPageOfEntry } from "~dumili-utils/entryPages";
import {
getEntryFromPage,
getFirstPageOfEntry,
} from "~dumili-utils/entryPages";
import { suggestions } from "~/stores/suggestions";
import { ui } from "~/stores/ui";
import { FullEntry, FullIndexation } from "~dumili-services/indexation/types";
Expand Down Expand Up @@ -204,15 +206,12 @@ watch(
currentPage,
(value) => {
if (value !== undefined) {
let pagesSoFar = 0;
currentEntry.value = indexation.value.entries.find((entry) => {
if (pagesSoFar >= value) {
return true;
}
pagesSoFar +=
entry.entirepages +
entry.brokenpagenumerator / entry.brokenpagedenominator;
})!;
currentEntry.value = getEntryFromPage(
indexation.value!,
indexation.value!.pages.find(
({ pageNumber }) => pageNumber === value + 1,
)!.id,
)!;
}
},
{ immediate: true },
Expand Down Expand Up @@ -276,9 +275,14 @@ watch(
}
}
.page,
:deep(.resizable) {
box-shadow: 1px 1px #000;
:deep(.entry) {
outline: 1px solid black;
margin-top: 1px;
cursor: pointer;
&:first-child {
margin-top: 0;
}
}
:deep(.resizable .handle) {
Expand Down
10 changes: 9 additions & 1 deletion apps/dumili/utils/entryPages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FullIndexation } from "~dumili-services/indexation/types";
import type { entry } from "~prisma/client_dumili";
import type { entry, page } from "~prisma/client_dumili";

export const getFirstPageOfEntry = (entries: entry[], entryId: number) =>
Math.floor(
Expand All @@ -23,3 +23,11 @@ export const getEntryPages = (
firstPageOfEntry + entry.entirepages - 1,
);
};

export const getEntryFromPage = (
{ entries, pages }: Pick<FullIndexation, "entries" | "pages">,
pageId: page["id"],
) =>
entries.find(({ id }) =>
getEntryPages({ entries, pages }, id).some(({ id }) => id === pageId),
);

0 comments on commit fdfad78

Please sign in to comment.