Skip to content

Commit 056df56

Browse files
committed
edgecreator: Fix existing contributors not loaded in save model modal
1 parent 36e36f6 commit 056df56

File tree

4 files changed

+62
-62
lines changed

4 files changed

+62
-62
lines changed

apps/edgecreator/api/services/upload/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ const _getFilenameUsagesInOtherModels = async (
5757
).filter((otherUse) => issue.issuenumber !== otherUse.issuenumberStart);
5858
};
5959

60-
const storePhotoHash = async (
60+
const storePhotoHash = (
6161
filename: string,
6262
hash: string,
6363
token: string
64-
) => {
65-
await getEdgeCreatorServices(token).createElementImage(hash, filename);
66-
};
64+
) => getEdgeCreatorServices(token).createElementImage(hash, filename);
6765

6866
const validateUpload = async (
6967
filename: string,

apps/edgecreator/src/components/SaveModelButton.vue

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"
4040
ok-only
4141
:ok-disabled="
42-
!contributors.photographe.size || !contributors.createur.size
42+
!contributorsByContributionType.photographe.size ||
43+
!contributorsByContributionType.createur.size
4344
"
4445
:ok-title="$t(action === 'export' ? 'Export' : 'Submit')"
4546
@ok="onOK"
@@ -59,7 +60,9 @@
5960
>
6061
<h2>{{ $t(ucFirst(userContributionEnL10n[contributionType])) }}</h2>
6162
<b-alert
62-
:model-value="!contributors[contributionType].size"
63+
:model-value="
64+
!contributorsByContributionType[contributionType].size
65+
"
6366
variant="warning"
6467
>
6568
{{ $t("You should select at least one user") }} </b-alert
@@ -70,20 +73,20 @@
7073
:min-input-length="0"
7174
@select-item="
7275
(user: SimpleUser) => {
73-
contributors[contributionType as contribution].add(user);
76+
contributorsByContributionType[contributionType as contribution].add(user);
7477
}
7578
"
7679
/>
7780
<ul>
7881
<li
79-
v-for="contributor in contributors[contributionType]"
82+
v-for="contributor in contributorsByContributionType[contributionType as contribution]"
8083
:key="contributor.username"
8184
>
8285
{{ contributor.username }}
8386
<i-bi-x-square-fill
8487
class="clickable"
8588
@click="
86-
contributors[contributionType as contribution].delete(
89+
contributorsByContributionType[contributionType as contribution].delete(
8790
contributor,
8891
);
8992
"
@@ -107,16 +110,17 @@ import type { contribution } from "~prisma-schemas/schemas/edgecreator";
107110
import type { SimpleUser } from "~types/SimpleUser";
108111
import { stores as webStores } from "~web";
109112
110-
const userContributionEnL10n: Record<contribution, string> = {
113+
const userContributionEnL10n = {
111114
photographe: "photographers",
112115
createur: "designers",
113-
};
116+
} as const;
114117
115118
const { saveEdgeSvg } = saveEdge();
116119
117120
const { t: $t } = useI18n();
118121
const userStore = webStores.users();
119122
const mainStore = main();
123+
const { issuecodes, contributors } = storeToRefs(mainStore);
120124
121125
const { action } = defineProps<{
122126
action: "save" | "submit" | "export";
@@ -127,10 +131,10 @@ const progress = ref(0);
127131
const issueIndexToSave = ref<number>();
128132
const result = ref<string>();
129133
130-
const contributors = ref<Record<contribution, Set<SimpleUser>>>({
131-
photographe: new Set(),
132-
createur: new Set(),
133-
});
134+
const contributorsByContributionType = ref({
135+
photographe: new Set<SimpleUser>(),
136+
createur: new Set<SimpleUser>(),
137+
} as const);
134138
135139
const label = computed(() => $t(ucFirst(action)));
136140
@@ -150,8 +154,7 @@ watch(progress, (newValue) => {
150154
}
151155
});
152156
watch(issueIndexToSave, (newValue) => {
153-
console.log("issueIndexToSave", newValue);
154-
const currentIssuecode = mainStore.issuecodes[newValue!];
157+
const currentIssuecode = issuecodes.value[newValue!];
155158
156159
if (currentIssuecode === undefined) {
157160
return;
@@ -161,15 +164,15 @@ watch(issueIndexToSave, (newValue) => {
161164
nextTick(() => {
162165
saveEdgeSvg(
163166
currentIssuecode,
164-
Array.from(mainStore.contributors).filter(
167+
Array.from(contributors.value).filter(
165168
({ issuecode }) => issuecode === currentIssuecode,
166169
),
167170
action === "export",
168171
action === "submit",
169172
).then((response) => {
170173
const isSuccess = response!.paths.svgPath;
171174
if (isSuccess) {
172-
progress.value += 100 / mainStore.issuecodes.length;
175+
progress.value += 100 / issuecodes.value.length;
173176
issueIndexToSave.value!++;
174177
} else {
175178
progress.value = 0;
@@ -185,8 +188,10 @@ const onOK = () => {
185188
for (const contributionType of Object.keys(
186189
contributors.value,
187190
) as contribution[]) {
188-
for (const contributor of contributors.value[contributionType]) {
189-
for (const issuecode of mainStore.issuecodes) {
191+
for (const contributor of contributorsByContributionType.value[
192+
contributionType
193+
]) {
194+
for (const issuecode of issuecodes.value) {
190195
mainStore.addContributor({
191196
issuecode,
192197
contributionType,
@@ -204,7 +209,8 @@ const ucFirst = (text: string) =>
204209
205210
const getUsersWithoutContributors = (contributionType: contribution) =>
206211
userStore.allUsers!.filter(
207-
(contributor) => !contributors.value[contributionType].has(contributor),
212+
(contributor) =>
213+
!contributorsByContributionType.value[contributionType].has(contributor),
208214
);
209215
210216
const onClick = () => {
@@ -214,6 +220,21 @@ const onClick = () => {
214220
issueIndexToSave.value = 0;
215221
}
216222
};
223+
224+
onMounted(() => {
225+
contributorsByContributionType.value = {
226+
photographe: new Set(
227+
Array.from(contributors.value)
228+
.filter(({ contributionType }) => contributionType === "photographe")
229+
.map(({ user }) => user),
230+
),
231+
createur: new Set(
232+
Array.from(contributors.value)
233+
.filter(({ contributionType }) => contributionType === "createur")
234+
.map(({ user }) => user),
235+
),
236+
};
237+
});
217238
</script>
218239
<style scoped lang="scss">
219240
:deep(.btn) {

apps/edgecreator/src/pages/upload.vue

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,20 @@ meta:
135135
<script lang="ts" setup>
136136
import "cropperjs/dist/cropper.css";
137137
138-
import { useToast } from "bootstrap-vue-next";
139138
import type Cropper from "cropperjs";
140139
import { nextTick } from "vue";
141140
import VueCropper from "vue-cropperjs";
142-
import type { CropperData } from "vue-cropperjs";
143141
import { useI18n } from "vue-i18n";
144142
145143
import { edgecreatorSocketInjectionKey } from "~/composables/useEdgecreatorSocket";
146144
import useSaveEdge from "~/composables/useSaveEdge";
147-
import type { ModelContributor } from "~types/ModelContributor";
148145
149146
const i18n = useI18n();
150147
151148
const { upload: uploadEvents } = inject(edgecreatorSocketInjectionKey)!;
152149
153150
const { saveEdgeSvg } = useSaveEdge();
154151
155-
const toast = useToast();
156-
157152
interface Crop {
158153
width: number;
159154
height: number;
@@ -176,42 +171,27 @@ const cropper = ref<Cropper>();
176171
177172
const isWidthBiggerThanHeight = ref(false);
178173
179-
const initialContributors = computed(
180-
(): Omit<ModelContributor, "issuecode">[] =>
181-
!collection().user
182-
? []
183-
: [
184-
{
185-
contributionType: "photographe",
186-
user: {
187-
id: collection().user!.id,
188-
username: collection().user!.username,
189-
},
174+
const initialContributors = computed(() =>
175+
!collection().user
176+
? []
177+
: [
178+
{
179+
contributionType: "photographe" as const,
180+
user: {
181+
id: collection().user!.id,
182+
username: collection().user!.username,
190183
},
191-
],
184+
},
185+
],
192186
);
193187
194188
const addCrop = () => {
195-
const data = cropper.value!.getData() as CropperData;
196-
if (data.height < data.width) {
197-
toast.create({
198-
props: {
199-
body: i18n
200-
.t(
201-
`The width of your selection is bigger than its height! Make sure that the edges appear vertically on the photo.`,
202-
)
203-
.toString(),
204-
title: i18n.t("Error").toString(),
205-
},
206-
});
207-
} else {
208-
crops.value.push({
209-
...currentCrop.value,
210-
sent: false,
211-
url: cropper.value!.getCroppedCanvas().toDataURL("image/jpeg"),
212-
});
213-
currentCrop.value = { width: 15, height: 200 };
214-
}
189+
crops.value.push({
190+
...currentCrop.value,
191+
sent: false,
192+
url: cropper.value!.getCroppedCanvas().toDataURL("image/jpeg"),
193+
});
194+
currentCrop.value = { width: 15, height: 200 };
215195
};
216196
const uploadAll = async () => {
217197
for (const crop of crops.value.filter(({ sent }) => !sent)) {
@@ -286,8 +266,9 @@ const update = (data: { url: string }) => {
286266
287267
onMounted(() => {
288268
setInterval(() => {
289-
isWidthBiggerThanHeight.value =
290-
cropper.value?.getData().width > cropper.value?.getData().height;
269+
isWidthBiggerThanHeight.value = !cropper.value?.getData()
270+
? false
271+
: cropper.value.getData().width > cropper.value.getData().height;
291272
}, 100);
292273
});
293274
</script>

packages/api/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ [email protected]
2121
SMTP_FRIENDLYNAME=DucksManager
2222

2323
WEBSITE_ROOT="http://localhost:8001"
24-
EDGECREATOR_ROOT="http://localhost:3002"
24+
EDGECREATOR_ROOT="http://localhost:8002"
2525

2626
PUSHER_INSTANCE_ID=
2727
PUSHER_SECRET_KEY=

0 commit comments

Comments
 (0)