Skip to content

Commit

Permalink
fix: Correctly update state for cover deletion
Browse files Browse the repository at this point in the history
* Initialize `removeCover` as `false` on each dialog render, so previous
  overrides don't affect the initial state.
* Make both file upload and cover online search update `removeCover` to
  false.
* Fix collection update to send `remove_cover` to the API.

Potential fix for #1169.
  • Loading branch information
adamantike committed Sep 5, 2024
1 parent 3094d46 commit 0e98183
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ const removeCover = ref(false);
const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("showCreateCollectionDialog", () => {
show.value = true;
removeCover.value = false;
});
emitter?.on("updateUrlCover", (url_cover) => {
if (!collection.value) return;
collection.value.url_cover = url_cover;
imagePreviewUrl.value = url_cover;
setArtwork(url_cover);
});
// Functions
Expand All @@ -42,13 +43,19 @@ function previewImage(event: Event) {
const reader = new FileReader();
reader.onload = () => {
imagePreviewUrl.value = reader.result?.toString();
setArtwork(reader.result?.toString() || "");
};
if (input.files[0]) {
reader.readAsDataURL(input.files[0]);
}
}
function setArtwork(imageUrl: string) {
if (!imageUrl) return;
imagePreviewUrl.value = imageUrl;
removeCover.value = false;
}
async function removeArtwork() {
imagePreviewUrl.value = `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`;
removeCover.value = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("showEditCollectionDialog", (collectionToEdit: Collection) => {
collection.value = collectionToEdit;
show.value = true;
removeCover.value = false;
});
emitter?.on("updateUrlCover", (url_cover) => {
if (!collection.value) return;
collection.value.url_cover = url_cover;
imagePreviewUrl.value = url_cover;
setArtwork(url_cover);
});
// Functions
Expand All @@ -42,13 +43,19 @@ function previewImage(event: Event) {
const reader = new FileReader();
reader.onload = () => {
imagePreviewUrl.value = reader.result?.toString();
setArtwork(reader.result?.toString() || "");
};
if (input.files[0]) {
reader.readAsDataURL(input.files[0]);
}
}
function setArtwork(imageUrl: string) {
if (!imageUrl) return;
imagePreviewUrl.value = imageUrl;
removeCover.value = false;
}
async function removeArtwork() {
imagePreviewUrl.value = `/assets/default/cover/big_${theme.global.name.value}_collection.png`;
removeCover.value = true;
Expand All @@ -62,6 +69,7 @@ async function editCollection() {
await collectionApi
.updateCollection({
collection: collection.value,
removeCover: removeCover.value,
})
.then(({ data }) => {
storeCollection.update(data);
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/components/common/Game/Dialog/EditRom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("showEditRomDialog", (romToEdit: UpdateRom | undefined) => {
show.value = true;
rom.value = romToEdit;
removeCover.value = false;
});
emitter?.on("updateUrlCover", (url_cover) => {
if (!rom.value) return;
rom.value.url_cover = url_cover;
imagePreviewUrl.value = url_cover;
setArtwork(url_cover);
});
// Functions
Expand All @@ -43,13 +44,19 @@ function previewImage(event: Event) {
const reader = new FileReader();
reader.onload = () => {
imagePreviewUrl.value = reader.result?.toString();
setArtwork(reader.result?.toString() || "");
};
if (input.files[0]) {
reader.readAsDataURL(input.files[0]);
}
}
function setArtwork(imageUrl: string) {
if (!imageUrl) return;
imagePreviewUrl.value = imageUrl;
removeCover.value = false;
}
async function removeArtwork() {
imagePreviewUrl.value = `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`;
removeCover.value = true;
Expand Down

0 comments on commit 0e98183

Please sign in to comment.