Skip to content

Commit c09a0fb

Browse files
committed
api: Add event to retrieve issues from a publication code
edgecreator: Call the new event
1 parent 4f295ba commit c09a0fb

File tree

10 files changed

+133
-68
lines changed

10 files changed

+133
-68
lines changed

apps/edgecreator/src/components/TopBar.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,30 @@
109109
</b-row>
110110
<b-row align="center" class="pb-1">
111111
<b-col v-if="publicationName" align-self="center">
112-
<issue :issuecode="issuecodes[0]" hide-condition no-wrap>
112+
<issue
113+
:issue="
114+
publicationIssues!.find(
115+
({ issuecode }) => issuecode === issuecodes[0],
116+
)
117+
"
118+
hide-condition
119+
no-wrap
120+
>
113121
<template v-if="isEditingMultiple" #title-suffix>
114122
<template v-if="mainStore.isRange">
115123
{{ $t("to") }}
116-
{{ issuecodes[issuecodes.length - 1] }}
124+
{{ publicationIssues!.find(
125+
({ issuecode }) => issuecode === issuecodes[issuecodes.length - 1],
126+
)!.issuenumber }}
117127
</template>
118128
<template v-else-if="issuecodes.length > 1">
119129
<span
120130
v-for="otherIssuecode in issuecodes.slice(1)"
121131
:key="`other-${otherIssuecode}`"
122-
>, {{ otherIssuecode }}</span
132+
>,
133+
{{ publicationIssues!.find(
134+
({ issuecode }) => issuecode === issuecodes[issuecodes.length - 1],
135+
)!.issuenumber }}</span
123136
>
124137
</template>
125138
</template>
@@ -264,8 +277,13 @@ const { showPreviousEdge, showNextEdge } = surroundingEdge();
264277
const { dimensions: editingDimensions } = storeToRefs(editingStep());
265278
const { hasRole } = webStores.collection();
266279
const stepStore = step();
267-
const { issuecodes, photoUrls, edgeIssuecodesAfter, edgeIssuecodesBefore } =
268-
storeToRefs(mainStore);
280+
const {
281+
issuecodes,
282+
publicationIssues,
283+
photoUrls,
284+
edgeIssuecodesAfter,
285+
edgeIssuecodesBefore,
286+
} = storeToRefs(mainStore);
269287
270288
interface ModelToClone {
271289
editMode: string;

apps/edgecreator/src/pages/edit/[...all].vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
<i-bi-pencil />
5252
</div>
5353
<div>
54-
{{ issuecodeDetails[issuecode].issuenumber }}
54+
{{
55+
publicationIssues!.find(
56+
(issue) => issue.issuecode === issuecode,
57+
)!.issuenumber
58+
}}
5559
</div>
5660
</th>
5761
<th
@@ -147,12 +151,13 @@ import type { Dimensions, Options } from "~/stores/step";
147151
import { step } from "~/stores/step";
148152
import { ui } from "~/stores/ui";
149153
import { stores as webStores } from "~web";
150-
import { coa } from "~web/src/stores/coa";
151154
152155
const route = useRoute();
153156
const uiStore = ui();
157+
154158
const mainStore = main();
155-
const { issuecodeDetails } = storeToRefs(coa());
159+
const { publicationIssues } = storeToRefs(mainStore);
160+
156161
const stepStore = step();
157162
const editingStepStore = editingStep();
158163
const { showPreviousEdge, showNextEdge } = useSurroundingEdge();
@@ -182,10 +187,8 @@ const dimensionsPerIssuecode = computed(() =>
182187
);
183188
184189
const getActualIssuecode = (issuecode: string) => {
185-
const actualIssuecode = Object.values(issuecodeDetails.value).find(
186-
({ publicationcode: thisPublicationcode, issuenumber }) =>
187-
thisPublicationcode === publicationcode.value &&
188-
issuenumber === issuecode.split(/[ ]+/)[1],
190+
const actualIssuecode = publicationIssues.value!.find(
191+
({ issuenumber }) => issuenumber === issuecode.split(/[ ]+/)[1],
189192
)?.issuecode;
190193
191194
if (actualIssuecode === undefined) {
@@ -230,7 +233,6 @@ try {
230233
publicationcode.value = issuecodeParts[0];
231234
232235
await mainStore.loadPublicationIssues();
233-
234236
firstIssuecode = getActualIssuecode(firstIssuecode);
235237
if (lastIssuecode) {
236238
lastIssuecode = getActualIssuecode(lastIssuecode);

apps/edgecreator/src/stores/main.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ export const main = defineStore("main", () => {
2525
warnings = ref<string[]>([]),
2626
country = computed(() => publicationcode.value?.split("/")[0]),
2727
magazine = computed(() => publicationcode.value?.split("/")[1]),
28-
publicationIssuecodes = computed(
28+
publicationIssues = computed(
2929
() =>
3030
(publicationcode.value &&
31-
webStores.coa().issuecodesByPublicationcode[publicationcode.value]) ||
32-
[],
31+
publicationcode.value in webStores.coa().issuesByPublicationcode &&
32+
webStores.coa().issuesByPublicationcode[publicationcode.value]) ||
33+
undefined,
3334
),
3435
publicationElementsForGallery = computed(
3536
() =>
@@ -91,26 +92,32 @@ export const main = defineStore("main", () => {
9192
lastIssuecode?: string,
9293
otherIssuecodes?: string[],
9394
) => {
94-
const firstIssueIndex = publicationIssuecodes.value.findIndex(
95-
(issuecode) => issuecode === firstIssuecode,
95+
if (!publicationIssues.value) {
96+
console.error("Publication issues not loaded");
97+
return;
98+
}
99+
const firstIssueIndex = publicationIssues.value.findIndex(
100+
({ issuecode }) => issuecode === firstIssuecode,
96101
);
97102
if (lastIssuecode === undefined) {
98103
issuecodes.value = [firstIssuecode, ...(otherIssuecodes || [])];
99104
} else {
100105
isRange.value = true;
101-
let lastIssueIndex = publicationIssuecodes.value.findIndex(
102-
(issuecode) => issuecode === lastIssuecode,
106+
let lastIssueIndex = publicationIssues.value.findIndex(
107+
({ issuecode }) => issuecode === lastIssuecode,
103108
);
104109
if (lastIssueIndex === -1) {
105-
lastIssueIndex = publicationIssuecodes.value.length - 1;
110+
lastIssueIndex = publicationIssues.value.length - 1;
106111
console.warn(
107-
`Issue ${lastIssuecode} doesn't exist, falling back to ${publicationIssuecodes.value[lastIssueIndex]}`,
112+
`Issue ${lastIssuecode} doesn't exist, falling back to ${publicationIssues.value[lastIssueIndex]}`,
108113
);
109114
}
110115

111-
issuecodes.value = publicationIssuecodes.value.filter(
112-
(_, index) => index >= firstIssueIndex && index <= lastIssueIndex,
113-
);
116+
issuecodes.value = publicationIssues.value
117+
.filter(
118+
(_, index) => index >= firstIssueIndex && index <= lastIssueIndex,
119+
)
120+
.map(({ issuecode }) => issuecode);
114121
}
115122
},
116123
loadItems = async ({ itemType }: { itemType: "elements" | "photos" }) => {
@@ -128,9 +135,7 @@ export const main = defineStore("main", () => {
128135
}
129136
},
130137
loadPublicationIssues = async () =>
131-
webStores
132-
.coa()
133-
.fetchIssuecodesByPublicationcode([publicationcode.value!]),
138+
webStores.coa().fetchIssuesByPublicationcode(publicationcode.value!),
134139
getEdgePublicationStates = (issuecodes: string[]) =>
135140
Object.keys(edgeCatalog().publishedEdges)
136141
.filter((issuecode) => issuecodes.includes(issuecode))
@@ -141,42 +146,47 @@ export const main = defineStore("main", () => {
141146
);
142147

143148
const firstIssueIndex = computed(() =>
144-
publicationIssuecodes.value.findIndex(
145-
(issue) => issue === issuecodes.value[0],
149+
publicationIssues.value?.findIndex(
150+
({ issuecode }) => issuecode === issuecodes.value[0],
146151
),
147152
);
148153
const lastIssueIndex = computed(() =>
149-
publicationIssuecodes.value.findIndex(
150-
(issue) => issue === issuecodes.value[issuecodes.value.length - 1],
154+
publicationIssues.value?.findIndex(
155+
({ issuecode }) =>
156+
issuecode === issuecodes.value[issuecodes.value.length - 1],
151157
),
152158
);
153159

154160
const edgeIssuecodesBefore = computed(() => {
155-
if (!edgeCatalog().isCatalogLoaded) {
161+
if (!edgeCatalog().isCatalogLoaded || !publicationIssues.value) {
156162
return [];
157163
}
158-
const issuesBefore = publicationIssuecodes.value.filter(
164+
const issuesBefore = publicationIssues.value.filter(
159165
(_, index) =>
160166
firstIssueIndex.value !== -1 &&
161-
index >= firstIssueIndex.value - 10 &&
162-
index < firstIssueIndex.value,
167+
index >= firstIssueIndex.value! - 10 &&
168+
index < firstIssueIndex.value!,
163169
);
164170

165-
return getEdgePublicationStates(issuesBefore);
171+
return getEdgePublicationStates(
172+
issuesBefore.map(({ issuecode }) => issuecode),
173+
);
166174
});
167175

168176
const edgeIssuecodesAfter = computed(() => {
169-
if (!edgeCatalog().isCatalogLoaded) {
177+
if (!edgeCatalog().isCatalogLoaded || !publicationIssues.value) {
170178
return [];
171179
}
172-
const issuesAfter = publicationIssuecodes.value.filter(
180+
const issuesAfter = publicationIssues.value.filter(
173181
(_, index) =>
174182
lastIssueIndex.value !== -1 &&
175-
index > lastIssueIndex.value &&
176-
index <= lastIssueIndex.value + 10,
183+
index > lastIssueIndex.value! &&
184+
index <= lastIssueIndex.value! + 10,
177185
);
178186

179-
return getEdgePublicationStates(issuesAfter);
187+
return getEdgePublicationStates(
188+
issuesAfter.map(({ issuecode }) => issuecode),
189+
);
180190
});
181191
return {
182192
publicationcode,
@@ -189,7 +199,7 @@ export const main = defineStore("main", () => {
189199
publicationElements,
190200
publicationPhotos,
191201
warnings,
192-
publicationIssuecodes,
202+
publicationIssues,
193203
publicationElementsForGallery,
194204
publicationPhotosForGallery,
195205
addContributor,

apps/web/src/components/Issue.vue

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,40 @@
2020

2121
<script setup lang="ts">
2222
const {
23-
issuecode,
23+
issuecode = undefined,
24+
issue: propIssue = undefined,
2425
clickable = false,
2526
hideCondition = false,
2627
noWrap = true,
2728
flex = true,
2829
isPublic = false,
29-
} = defineProps<{
30-
issuecode: string;
31-
clickable?: boolean;
32-
hideCondition?: boolean;
33-
noWrap?: boolean;
34-
flex?: boolean;
35-
isPublic?: boolean;
36-
}>();
30+
} = defineProps<
31+
(
32+
| {
33+
issuecode: string;
34+
issue: undefined;
35+
}
36+
| {
37+
issue: {
38+
issuecode: string;
39+
publicationcode: string;
40+
issuenumber: string;
41+
};
42+
issuecode: undefined;
43+
}
44+
) & {
45+
clickable?: boolean;
46+
hideCondition?: boolean;
47+
noWrap?: boolean;
48+
flex?: boolean;
49+
isPublic?: boolean;
50+
}
51+
>();
3752
3853
const store = coa();
39-
const issue = computed(() => store.issuecodeDetails?.[issuecode]);
54+
const issue = computed(() =>
55+
issuecode ? store.issuecodeDetails?.[issuecode] : propIssue!,
56+
);
4057
const publicationname = computed(
4158
() =>
4259
issue.value?.publicationcode &&

apps/web/src/composables/useDmSocket.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ const defaultExport = (options: {
9898
namespaces.PRESENTATION_TEXT,
9999
),
100100
edges: socket.addNamespace<EdgesEvents>(namespaces.EDGES, {}),
101-
coa: socket.addNamespace<CoaEvents>(namespaces.COA, {
102-
cache: {
103-
storage: cacheStorage,
104-
ttl: until4am(),
105-
},
106-
}),
101+
coa: socket.addNamespace<CoaEvents>(namespaces.COA),
107102
globalStats: socket.addNamespace<GlobalStatsEvents>(
108103
namespaces.GLOBAL_STATS,
109104
{

apps/web/src/stores/coa.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ export const coa = defineStore("coa", () => {
6161
EventOutput<CoaClientEvents, "getIssuePopularities">
6262
>({}),
6363
issuecodesByPublicationcode = ref<
64-
EventOutput<CoaClientEvents, "getIssuesByPublicationcodes">
64+
EventOutput<CoaClientEvents, "getIssuecodesByPublicationcodes">
65+
>({}),
66+
issuesByPublicationcode = ref<
67+
Record<string, EventOutput<CoaClientEvents, "getIssuesByPublicationcode">>
6568
>({}),
6669
issueQuotations = ref<
6770
SuccessfulEventOutput<
@@ -244,15 +247,18 @@ export const coa = defineStore("coa", () => {
244247
);
245248

246249
if (newPublicationcodes.length) {
247-
const issuesByPublicationcode =
248-
await events.getIssuesByPublicationcodes(newPublicationcodes);
249-
250250
Object.assign(
251251
issuecodesByPublicationcode.value,
252-
issuesByPublicationcode,
252+
await events.getIssuecodesByPublicationcodes(newPublicationcodes),
253253
);
254254
}
255255
},
256+
fetchIssuesByPublicationcode = async (publicationcode: string) => {
257+
if (!(publicationcode in issuesByPublicationcode.value)) {
258+
issuesByPublicationcode.value[publicationcode] =
259+
await events.getIssuesByPublicationcode(publicationcode);
260+
}
261+
},
256262
fetchRecentIssues = () => events.getRecentIssues(),
257263
fetchCoverUrls = (publicationcode: string) =>
258264
events.getIssueCoverDetailsByPublicationcode(publicationcode),
@@ -279,6 +285,7 @@ export const coa = defineStore("coa", () => {
279285
fetchCoverUrlsByIssuecodes,
280286
fetchIssuecodeDetails,
281287
fetchIssuecodesByPublicationcode,
288+
fetchIssuesByPublicationcode,
282289
fetchIssuePopularities,
283290
fetchIssueQuotations,
284291
fetchIssueUrls,
@@ -296,6 +303,7 @@ export const coa = defineStore("coa", () => {
296303
issuePopularities: issuePopularities,
297304
issuecodes,
298305
issueQuotations,
306+
issuesByPublicationcode,
299307
personNames,
300308
publicationNames,
301309
publicationNamesFullCountries,

packages/api/eslint.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ export default tseslint.config(
4646
},
4747
{
4848
files: ["**/*.ts"]
49-
});
49+
}
50+
);

packages/api/services/coa/issues/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export default {
1212
.then((data) => data.groupBy("issuecode"));
1313
},
1414

15-
getIssuesByPublicationcodes: async (publicationcodes: string[]) =>
15+
getIssuecodesByPublicationcodes: async (publicationcodes: string[]) =>
1616
prismaCoa.inducks_issue
1717
.findMany({
1818
select: {
1919
publicationcode: true,
20-
issuecode: true,
20+
issuecode: true
2121
},
2222
where: {
2323
publicationcode: {
@@ -27,6 +27,19 @@ export default {
2727
})
2828
.then((data) => data.groupBy("publicationcode", "issuecode[]")),
2929

30+
getIssuesByPublicationcode: async (publicationcode: string) =>
31+
prismaCoa.inducks_issue
32+
.findMany({
33+
select: {
34+
publicationcode: true,
35+
issuecode: true,
36+
issuenumber: true,
37+
},
38+
where: {
39+
publicationcode
40+
},
41+
}),
42+
3043
getIssuesByStorycode: async (storycode: string) =>
3144
prismaCoa.$queryRaw<IssueWithIssuecodeOnly[]>`
3245
SELECT publicationcode, issuenumber, issuecode

0 commit comments

Comments
 (0)