Skip to content

Commit

Permalink
Rename collection().collection to collection().issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Nov 25, 2023
1 parent 4bcde3b commit e71f583
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 72 deletions.
5 changes: 1 addition & 4 deletions apps/web/src/components/ContextMenuOwnCollection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@
</template>

<script setup lang="ts">
import {
collection,
IssueWithPublicationcodeOptionalId,
} from "~/stores/collection";
import { IssueWithPublicationcodeOptionalId } from "~/stores/collection";
import {
CollectionUpdateMultipleIssues,
CollectionUpdateSingleIssue,
Expand Down
9 changes: 3 additions & 6 deletions apps/web/src/components/IssueCopyEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@
</template>
<script setup lang="ts">
import cond from "~/composables/useCondition";
import {
collection,
IssueWithPublicationcodeOptionalId,
} from "~/stores/collection";
import { IssueWithPublicationcodeOptionalId } from "~/stores/collection";
import { CollectionUpdateMultipleIssues } from "~dm-types/CollectionUpdate";
import type { issue_condition } from "~prisma-clients/client_dm";
Expand Down Expand Up @@ -285,7 +282,7 @@ const { issueRequestsAsSeller, buyerUserNamesById } =
storeToRefs(marketplace());
const { createPurchase, deletePurchase } = collection();
const { collection: currentCollection, purchases } = storeToRefs(collection());
const { issues, purchases } = storeToRefs(collection());
const today = new Date().toISOString().slice(0, 10);
Expand Down Expand Up @@ -316,7 +313,7 @@ const issuenumbers = $computed(() =>
const collectionForCurrentPublication = $computed(
() =>
currentCollection.value?.filter(
issues.value?.filter(
({ publicationcode: issuePublicationcode }) =>
copyState.publicationcode === issuePublicationcode,
),
Expand Down
16 changes: 7 additions & 9 deletions apps/web/src/components/IssueList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,9 @@ const {
readonly?: boolean;
}>();
const collectionStore = collection();
const store = $computed(() =>
readonly ? publicCollection() : collectionStore,
);
const { updateCollectionMultipleIssues, loadPurchases } = collection();
const { issues: collectionIssues, purchases: collectionPurchases } =
storeToRefs(readonly ? publicCollection() : collection());
const { conditions } = condition();
const { t: $t } = useI18n();
Expand Down Expand Up @@ -476,8 +475,8 @@ const issueIds = $computed(() =>
);
let contextMenuKey = $ref("context-menu" as string);
const userIssues = $computed(() => customIssues || store.collection);
let purchases = $computed(() => store.purchases);
const userIssues = $computed(() => customIssues || collectionIssues.value);
let purchases = $computed(() => collectionPurchases.value);
const country = $computed(() => publicationcode.split("/")[0]);
const publicationName = $computed(
() => publicationNames.value[publicationcode],
Expand Down Expand Up @@ -516,7 +515,6 @@ const ownedIssuesCount = $computed(
0,
) || 0,
);
const loadPurchases = store.loadPurchases;
const showContextMenuOnDoubleClickTouchScreen = (e: MouseEvent) => {
if (!readonly) {
Expand Down Expand Up @@ -563,7 +561,7 @@ const deletePublicationIssues = async (
) => {
contextmenuInstance.hide();
if (!readonly) {
await (store as typeof collectionStore).updateCollectionMultipleIssues({
await updateCollectionMultipleIssues({
publicationcode,
issuenumbers: issuesToDelete.map(({ issuenumber }) => issuenumber),
condition:
Expand Down Expand Up @@ -702,7 +700,7 @@ watch(
(async () => {
if (customIssues) {
store.purchases = [];
collectionPurchases.value = [];
} else {
await loadPurchases();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/LastPublishedEdges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const publishedEdgesSincePreviousVisit = $computed(
() =>
lastPublishedEdgesForCurrentUser.value?.filter(
({ creationDate }) =>
previousVisit.value && creationDate >= previousVisit.value,
previousVisit.value && new Date(creationDate) >= previousVisit.value,
) || [],
);
const hasPublicationNames = $computed(
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/LastPurchases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
import { IssueWithPublicationcode } from "~dm-types/IssueWithPublicationcode";
const { publicationNames } = storeToRefs(coa());
const { purchasesById, collection: thisCollection } = storeToRefs(collection());
const { purchasesById, issues } = storeToRefs(collection());
const { t } = useI18n();
const hasPublicationNames = $computed(() => Object.keys(publicationNames)),
collectionPerPurchaseDate = $computed(
() =>
purchasesById.value &&
thisCollection.value
issues.value
?.reduce(
(acc, issue) => {
const existingPurchase =
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/LinkToCollectionIfNoIssue.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<b-alert v-if="myCollection && !myCollection.length" variant="info">
<b-alert v-if="issues && !issues.length" variant="info">
{{ $t("Vous ne possédez aucun numéro ! Cliquez") }}
<router-link to="/collection/show">{{ $t("ici") }}</router-link>
{{ $t("pour en ajouter à votre collection !") }}
</b-alert>
</template>

<script setup lang="ts">
const { collection: myCollection } = storeToRefs(collection());
const { issues } = storeToRefs(collection());
const { t: $t } = useI18n();
</script>
4 changes: 2 additions & 2 deletions apps/web/src/components/StorySearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const emit = defineEmits<{
const { conditions } = condition();
const { findInCollection } = isPublic ? publicCollection() : collection();
const { collection: thisCollection } = storeToRefs(collection());
const { issues } = storeToRefs(collection());
const { fetchPublicationNames, fetchCountryNames } = coa();
const { publicationNames } = storeToRefs(coa());
Expand Down Expand Up @@ -193,7 +193,7 @@ const runSearch = async (value: string) => {
storyResults.results = data.results.map((story) => ({
...story,
collectionIssue:
thisCollection.value!.find(
issues.value!.find(
({
publicationcode: collectionPublicationCode,
issuenumber: collectionIssueNumber,
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/pages/collection/user/[username]/[...all].vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ meta:
public: true
</route>
<template>
<div v-if="thisCollection">
<div v-if="issues">
<ShortStats is-public>
<template #empty-collection>
<b-alert :model-value="true" variant="info" class="mb-3">
Expand Down Expand Up @@ -32,8 +32,7 @@ const username = $computed(() => route.params.username as string);
const publicationcode = $computed(() => (route.params.all as string) || null);
const { loadPublicCollection } = publicCollection();
const { mostPossessedPublication, collection: thisCollection } =
storeToRefs(publicCollection());
const { mostPossessedPublication, issues } = storeToRefs(publicCollection());
watch(
$$(username),
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/pages/expand/suggestions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ alias: [/agrandir/suggestions]
</route>

<template>
<div v-if="thisCollection">
<div v-if="issues">
<b-alert variant="info" :model-value="true">
{{ $t("DucksManager se base sur les") }}
<router-link to="/stats/authors">{{
Expand Down Expand Up @@ -73,8 +73,7 @@ const countryCode = $ref("ALL" as string);
const { t: $t } = useI18n();
const { loadCollection } = collection();
const { collection: thisCollection, watchedAuthors } =
storeToRefs(collection());
const { issues, watchedAuthors } = storeToRefs(collection());
const { loadRatings } = stats();
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/pages/inducks/import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ let importProgress = $ref(0 as number);
const { t: $t } = useI18n();
const { findInCollection, loadCollection } = collection();
const { collection: thisCollection, user } = storeToRefs(collection());
const { issues, user } = storeToRefs(collection());
const { fetchPublicationNames, fetchIssueNumbers, fetchIssueCodesDetails } =
coa();
Expand All @@ -313,7 +313,7 @@ const conditions = {
bon: $t("En bon état"),
};
const importDataReady = $computed(
() => issuesToImport && thisCollection.value && hasIssueNumbers,
() => issuesToImport && issues.value && hasIssueNumbers,
);
const router = useRouter();
const processRawData = async () => {
Expand Down
13 changes: 5 additions & 8 deletions apps/web/src/pages/print/classic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ const { fetchCountryNames, fetchPublicationNames, fetchIssueNumbers } = coa();
const { countryNames, publicationNames, issueNumbers } = storeToRefs(coa());
const { loadCollection } = collection();
const { collection: thisCollection } = storeToRefs(collection());
const { issues } = storeToRefs(collection());
const countryCodes = $computed(
() =>
thisCollection.value && [
...new Set(thisCollection.value.map((i) => i.country)),
],
() => issues.value && [...new Set(issues.value.map((i) => i.country))],
);
const countryCodesSortedByName = $computed(
() =>
Expand All @@ -53,8 +50,8 @@ const countryCodesSortedByName = $computed(
);
const publicationCodes = $computed(
() =>
thisCollection.value && [
...new Set(thisCollection.value.map((i) => `${i.country}/${i.magazine}`)),
issues.value && [
...new Set(issues.value.map((i) => `${i.country}/${i.magazine}`)),
],
);
const publicationCodesOfCountry = (countrycode: string) =>
Expand All @@ -81,7 +78,7 @@ watch(
() => Object.keys(issueNumbers).length && collection,
(newValue) => {
if (newValue) {
const collectionWithPublicationcodes = thisCollection
const collectionWithPublicationcodes = issues
.value!.map(({ country, magazine, issuenumber }) => ({
publicationcode: `${country}/${magazine}`,
issuenumber: issuenumber,
Expand Down
5 changes: 2 additions & 3 deletions apps/web/src/pages/print/collectable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ const { fetchCountryNames, fetchPublicationNames } = coa();
const { countryNames, publicationNames } = storeToRefs(coa());
const { loadCollection, loadPurchases } = collection();
const { collection: thisCollection, totalPerPublication } =
storeToRefs(collection());
const { issues, totalPerPublication } = storeToRefs(collection());
const ready = $computed(
() => issuesPerCell && countryNames && Object.keys(publicationNames).length,
Expand Down Expand Up @@ -177,7 +176,7 @@ let issuesPerCell = $ref(
} | null,
);
watch(thisCollection, (newCollectionValue) => {
watch(issues, (newCollectionValue) => {
if (!newCollectionValue) {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/pages/stats/publications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { Pie } from "vue-chartjs";
Chart.register(Legend, PieController, Tooltip, Title, ArcElement);
const { loadCollection } = collection();
const { totalPerPublication, collection: thisCollection } =
storeToRefs(collection());
const { totalPerPublication, issues } = storeToRefs(collection());
const { fetchPublicationNames } = coa();
const { publicationNames } = storeToRefs(coa());
Expand All @@ -34,8 +33,7 @@ const smallCountPublications = $computed(() =>
? null
: Object.keys(totalPerPublication.value).filter(
(publicationcode) =>
totalPerPublication.value![publicationcode] /
thisCollection.value!.length <
totalPerPublication.value![publicationcode] / issues.value!.length <
0.01,
),
);
Expand Down
9 changes: 3 additions & 6 deletions apps/web/src/pages/stats/purchases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ const { fetchPublicationNames } = coa();
const { publicationNames } = storeToRefs(coa());
const { loadCollection, loadPurchases } = collection();
const {
totalPerPublication,
collection: thisCollection,
purchasesById,
} = storeToRefs(collection());
const { totalPerPublication, issues, purchasesById } =
storeToRefs(collection());
loadCollection();
const { t: $t } = useI18n(),
Expand Down Expand Up @@ -138,7 +135,7 @@ const publicationCodesWithOther = $computed(
collectionWithDates = $computed(
() =>
(purchasesById &&
thisCollection.value?.map((issue) => ({
issues.value?.map((issue) => ({
...issue,
date: getIssueMonth(issue),
}))) ||
Expand Down
14 changes: 7 additions & 7 deletions apps/web/src/stores/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ let api: AxiosInstance,
clearSessionFn: () => Promise<void>;

export const collection = defineStore("collection", () => {
const collection = ref(null as IssueWithPublicationcode[] | null);
const issues = ref(null as IssueWithPublicationcode[] | null);

const collectionUtils = useCollection(collection),
const collectionUtils = useCollection(issues),
watchedPublicationsWithSales = ref(null as string[] | null),
purchases = ref(null as GET__collection__purchases["resBody"] | null),
watchedAuthors = ref(null as authorUser[] | null),
Expand Down Expand Up @@ -108,7 +108,7 @@ export const collection = defineStore("collection", () => {
),
issueNumbersPerPublication = computed(
() =>
collection.value?.reduce(
issues.value?.reduce(
(acc, { country, issuenumber, magazine }) => ({
...acc,
[`${country}/${magazine}`]: [
Expand Down Expand Up @@ -179,7 +179,7 @@ export const collection = defineStore("collection", () => {
"": 0.7,
};
return (
collection.value
issues.value
?.filter(({ publicationcode, issuenumber }) =>
getEstimation(publicationcode, issuenumber),
)
Expand Down Expand Up @@ -267,9 +267,9 @@ export const collection = defineStore("collection", () => {
.data?.previousVisit;
},
loadCollection = async (afterUpdate = false) => {
if (afterUpdate || (!isLoadingCollection.value && !collection.value)) {
if (afterUpdate || (!isLoadingCollection.value && !issues.value)) {
isLoadingCollection.value = true;
collection.value = (
issues.value = (
await call(api, new GET__collection__issues())
).data.map((issue) => ({
...issue,
Expand Down Expand Up @@ -494,7 +494,7 @@ export const collection = defineStore("collection", () => {
sessionExistsFn = params.sessionExistsFn;
clearSessionFn = params.clearSessionFn;
},
collection,
issues,
publicationUrlRoot,
createPurchase,
deletePurchase,
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/stores/public-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { IssueWithPublicationcode } from "~dm-types/IssueWithPublicationcode";
let api: AxiosInstance;

export const publicCollection = defineStore("publicCollection", () => {
const collection = ref(null as IssueWithPublicationcode[] | null),
const issues = ref(null as IssueWithPublicationcode[] | null),
publicUsername = ref(null as string | null),
publicationUrlRoot = computed(
() => `/collection/user/${publicUsername.value || ""}`,
),
purchases = ref([]);

const collectionUtils = useCollection(collection),
const collectionUtils = useCollection(issues),
loadPublicCollection = async (username: string) => {
publicUsername.value = username;
collection.value = (
issues.value = (
await call(
api,
new GET__collection_public__$username({
Expand All @@ -35,7 +35,7 @@ export const publicCollection = defineStore("publicCollection", () => {
api = addUrlParamsRequestInterceptor(params.api);
},
publicationUrlRoot,
collection,
issues,
purchases,
loadPublicCollection,
loadPurchases: () => {},
Expand Down
Loading

0 comments on commit e71f583

Please sign in to comment.