Skip to content

Commit

Permalink
web,api:Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Aug 31, 2024
1 parent 499387c commit d9f0775
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 106 deletions.
111 changes: 49 additions & 62 deletions apps/web/src/components/Bookcase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,55 @@
}"
>
<template v-for="edgeIndex of edgeIndexesToLoad" :key="`edge-${edgeIndex}`">
<Edge
v-if="embedded"
:id="`edge-${edgeIndex}${embedded}`"
v-bind="
(({ issuecode, issueCondition }) => ({
issue: issuecodeDetails[issuecode],
issueCondition,
}))(sortedBookcase[edgeIndex] as SimpleBookcaseEdge)
"
:orientation="orientation"
existing
embedded
@loaded="onEdgeLoaded(edgeIndex)"
><template #edge-prefix="{ edge }"
><slot
name="edge-prefix"
:edge="{
issueCondition: edge.issueCondition!,
}" /></template
></Edge>
<Edge
v-else
:id="`edge-${edgeIndex}`"
:invisible="
currentEdgeOpened === sortedBookcaseWithPopularity![edgeIndex] ||
edgeIndex > lastEdgeIndexContinuouslyLoaded
"
:highlighted="
currentEdgeHighlighted === sortedBookcaseWithPopularity![edgeIndex].id
"
v-bind="
(({
issuecode,
issueCondition,
popularity,
}: BookcaseEdgeWithPopularity) => ({
issue: issuecodeDetails[issuecode],
issueCondition,
popularity
}))(sortedBookcaseWithPopularity![edgeIndex])
"
:creation-date="
sortedBookcaseWithPopularity![edgeIndex].creationDate?.toString()
"
:existing="!!sortedBookcaseWithPopularity![edgeIndex].edgeId"
:sprite-path="
edgesUsingSprites?.[
sortedBookcaseWithPopularity![edgeIndex].edgeId
] || null
"
:orientation="orientation"
@loaded="onEdgeLoaded(edgeIndex)"
@open-book="
$emit('open-book', sortedBookcaseWithPopularity![edgeIndex])
"
><template #edge-prefix="{ edge }"
><slot
name="edge-prefix"
:edge="{
issueCondition: edge.issueCondition!,
}" /></template></Edge
<template v-if="issuecodeDetails[sortedBookcase[edgeIndex].issuecode]">
<Edge
v-if="embedded"
:id="`edge-${edgeIndex}${embedded}`"
:issuecode="sortedBookcase![edgeIndex].issuecode"
:orientation="orientation"
existing
embedded
@loaded="onEdgeLoaded(edgeIndex)"
><template #edge-prefix="{ edge }"
><slot
name="edge-prefix"
:edge="{
issueCondition: edge.issueCondition!,
}" /></template
></Edge>
<Edge
v-else
:id="`edge-${edgeIndex}`"
:invisible="
currentEdgeOpened === sortedBookcaseWithPopularity![edgeIndex] ||
edgeIndex > lastEdgeIndexContinuouslyLoaded
"
:highlighted="
currentEdgeHighlighted ===
sortedBookcaseWithPopularity![edgeIndex].id
"
:edge="sortedBookcaseWithPopularity![edgeIndex]"
:issuecode="sortedBookcaseWithPopularity![edgeIndex].issuecode"
:creation-date="
sortedBookcaseWithPopularity![edgeIndex].creationDate?.toString()
"
:existing="!!sortedBookcaseWithPopularity![edgeIndex].edgeId"
:sprite-path="
edgesUsingSprites?.[
sortedBookcaseWithPopularity![edgeIndex].edgeId
] || null
"
:orientation="orientation"
@loaded="onEdgeLoaded(edgeIndex)"
@open-book="
$emit('open-book', sortedBookcaseWithPopularity![edgeIndex])
"
><template #edge-prefix="{ edge }"
><slot
name="edge-prefix"
:edge="{
issueCondition: edge.issueCondition!,
}" /></template></Edge></template
></template>
</div>
</template>
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/components/BookcasePopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<template #content>
<Bookcase
:bookcase-textures="bookcaseTextures"
:sorted-bookcase="edges"
:sorted-bookcase="issuecodes"
embedded
/>
<b-row>
<b-col
v-for="(edge, edgeId) in edges"
:key="`bookcase-${id}-issue-${edgeId}`"
v-for="(issuecode, idx) in issuecodes"
:key="`bookcase-${id}-issue-${idx}`"
cols="6"
>
<Issue
class="issue"
:issuecode="edge.issuecode"
:issuecode="issuecode"
hide-condition
:flex="false"
/>
Expand All @@ -28,7 +28,7 @@
<script setup lang="ts">
defineProps<{
id: string;
edges: { issuecode: string }[];
issuecodes: string[];
}>();
const bookcaseTextures = {
Expand Down
27 changes: 13 additions & 14 deletions apps/web/src/components/Edge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
v-if="embedded"
:id="id"
:src="src"
:issuecode="issue.issuecode"
:issuecode="issuecode"
:sprite-path="spritePath"
:invisible="invisible"
:highlighted="highlighted"
Expand All @@ -23,12 +23,12 @@
:extra-points="popularity"
>
<template #title>
<Issue :issuecode="issue.issuecode" />
<Issue :issuecode="issuecode" />
</template>
<EdgeContents
:id="id"
:src="src"
:issuecode="issue.issuecode"
:issuecode="issuecode"
:sprite-path="spritePath"
:invisible="invisible"
:highlighted="highlighted"
Expand All @@ -41,13 +41,12 @@
</template>

<script setup lang="ts">
import type { inducks_issue } from "~prisma-schemas/schemas/coa";
import type { issue_condition } from "~prisma-schemas/schemas/dm";
const SPRITES_ROOT = "https://res.cloudinary.com/dl7hskxab/image/sprite/";
const {
creationDate = null,
issue,
issuecode,
issueCondition,
spritePath = null,
popularity = null,
Expand All @@ -57,7 +56,7 @@ const {
orientation = "vertical",
} = defineProps<{
id: string;
issue: Pick<inducks_issue, "publicationcode" | "issuecode" | "issuenumber">;
issuecode: string;
issueCondition?: issue_condition;
creationDate?: string;
popularity?: number | null;
Expand All @@ -78,17 +77,17 @@ defineSlots<{
const CLOUDINARY_ROTATED_URL =
"https://res.cloudinary.com/dl7hskxab/image/upload/a_270/edges/";
const { publicationNames } = storeToRefs(coa());
const { publicationNames, issuecodeDetails } = storeToRefs(coa());
let countryCode = $computed(() => issue.publicationcode.split("/")[0]),
magazineCode = $computed(() => issue.publicationcode.split("/")[1]),
src = $computed(() =>
spritePath && !ignoreSprite
let src = $computed(() => {
const { publicationcode, issuenumber } = issuecodeDetails.value[issuecode];
const [countrycode, magazineCode] = publicationcode.split("/");
return spritePath && !ignoreSprite
? `${SPRITES_ROOT}${spritePath}.png`
: `${orientation === "vertical" ? import.meta.env.VITE_EDGES_ROOT : CLOUDINARY_ROTATED_URL}${countryCode}/gen/${magazineCode}.${issue.issuenumber.replaceAll(
: `${orientation === "vertical" ? import.meta.env.VITE_EDGES_ROOT : CLOUDINARY_ROTATED_URL}${countrycode}/gen/${magazineCode}.${issuenumber.replaceAll(
" ",
"",
)}.png?${creationDate ? new Date(creationDate).getTime() : "default"}`,
),
)}.png?${creationDate ? new Date(creationDate).getTime() : "default"}`;
}),
ignoreSprite = $ref(false);
</script>
6 changes: 3 additions & 3 deletions apps/web/src/components/Event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@
<template v-else>&nbsp;{{ $t("a créé la tranche") }} </template>
&nbsp;<BookcasePopover
:id="`event-edges-${event.timestamp}`"
:edges="edgeEvent.edges"
:issuecodes="edgeEvent.issuecodes"
>
<span class="fw-bold" style="cursor: help">
<Issue
:issuecode="edgeEvent.edges[0].issuecode"
:issuecode="edgeEvent.issuecodes[0]"
hide-condition
:flex="false"
/>&nbsp;<OtherIssues
:number="edgeEvent.edges.length"
:number="edgeEvent.issuecodes.length"
:text-single="$t('autre tranche')"
:text-multiple="$t('autres tranches')"
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/Issue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const store = coa();
const issue = computed(() => store.issuecodeDetails?.[issuecode]);
const publicationname = computed(
() =>
issue.value.publicationcode &&
issue.value?.publicationcode &&
store.publicationNames?.[issue.value.publicationcode],
);
</script>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/IssueList.story.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import dayjs from "dayjs";
import type { issue } from "~prisma-schemas/schemas/dm";
const customIssues: (issue & { issuecode: string })[] = [
const customIssues: issue[] = [
{
id: 167808,
publicationcode: "fr/MP",
Expand Down
8 changes: 3 additions & 5 deletions apps/web/src/components/RecentEvents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const isCollectionUpdateEvent = (
const isEdgeCreationEvent = (
event: AbstractEvent,
): event is EdgeCreationEvent => event.hasOwnProperty("edges");
): event is EdgeCreationEvent => event.hasOwnProperty("issuecodes");
const fetchEventsAndAssociatedData = async () => {
await fetchEvents();
Expand All @@ -52,9 +52,7 @@ const fetchEventsAndAssociatedData = async () => {
.map(({ exampleIssuecode }) => exampleIssuecode),
...events.value
.filter((event) => isEdgeCreationEvent(event))
.reduce<
string[]
>((acc, { edges }) => [...acc, ...edges.map(({ issuecode }) => issuecode)], []),
.reduce<string[]>((acc, { issuecodes }) => [...acc, ...issuecodes], []),
]);
await fetchPublicationNames([
Expand All @@ -68,7 +66,7 @@ const fetchEventsAndAssociatedData = async () => {
.filter((event) => isEdgeCreationEvent(event))
.reduce<
string[]
>((acc, { edges }) => [...acc, ...edges.map(({ issuecode }) => issuecodeDetails.value[issuecode].publicationcode)], []),
>((acc, { issuecodes }) => [...acc, ...issuecodes.map((issuecode) => issuecodeDetails.value[issuecode].publicationcode)], []),
]);
await fetchStats(eventUserIds.filter((userId) => userId !== null));
Expand Down
19 changes: 6 additions & 13 deletions packages/api/services/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,25 @@ const retrieveBookstoreCreations = async (): Promise<BookstoreCommentEvent[]> =>
const retrieveEdgeCreations = async (): Promise<EdgeCreationEvent[]> =>
(
await prismaDm.$queryRaw<EdgeCreationEventRaw[]>`
select 'edge' as type,
CONCAT('[', GROUP_CONCAT(json_object(
'publicationcode',
publicationcode,
'issuenumber',
issuenumber
)), ']') AS edges,
select 'edge' AS type,
GROUP_CONCAT(issuecode) AS issuecodes,
UNIX_TIMESTAMP(creationDate) AS timestamp,
users
from (SELECT tp.publicationcode,
tp.issuenumber,
from (SELECT tp.issuecode,
tp.dateajout AS creationDate,
GROUP_CONCAT(DISTINCT tpc.ID_user) AS users
FROM tranches_pretes tp
INNER JOIN users_contributions tpc ON tpc.ID_tranche = tp.ID
WHERE tp.dateajout > DATE_ADD(NOW(), INTERVAL -1 MONTH)
AND NOT (tp.publicationcode = 'fr/JM' AND tp.issuenumber REGEXP '^[0-9]+$')
AND NOT (tp.publicationcode = 'be/MMN')
AND NOT (tp.publicationcode = 'it/TL')
AND NOT (tp.publicationcode = 'se/WDS')
AND tp.publicationcode NOT IN ('be/MMN', 'it/TL', 'se/WDS')
GROUP BY tp.ID) as edges_and_collaborators
group by DATE_FORMAT(creationDate, '%Y-%m-%d %H:00:00'), edges_and_collaborators.users
having count(issuecode) > 0
`
).map((event) => ({
...mapUsers<EdgeCreationEvent>(event),
edges: JSON.parse(event.edges),
issuecodes: event.issuecodes.split(","),
}));

const retrieveNewMedals = async () =>
Expand Down
4 changes: 2 additions & 2 deletions packages/types/events/EdgeCreationEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { AbstractEvent } from "./AbstractEvent";

export interface EdgeCreationEventRaw {
type: string;
edges: string;
issuecodes: string;
timestamp: number;
users: string;
}

export class EdgeCreationEvent extends AbstractEvent {
type = "edge";
edges: { issuecode: string }[] = [];
issuecodes: string[] = [];
}

0 comments on commit d9f0775

Please sign in to comment.