complete refactor of dialogs as components

This commit is contained in:
zurdi
2023-08-08 18:10:55 +02:00
parent 80fb047275
commit bb28683f7d
5 changed files with 36 additions and 22 deletions

View File

@@ -4,20 +4,21 @@ import { useDisplay } from "vuetify";
import { updateRomApi } from "@/services/api.js";
const { xs, mdAndDown, lgAndUp } = useDisplay();
const updatedRom = ref();
const show = ref(false);
const rom = ref();
const updatedRom = ref();
const renameAsIGDB = ref(false);
const emitter = inject("emitter");
emitter.on("showEditDialog", (romToEdit, updatedRomToEdit) => {
emitter.on("showEditDialog", (romToEdit) => {
show.value = true;
rom.value = romToEdit;
updatedRom.value = updatedRomToEdit;
updatedRom.value = { ...romToEdit };
});
async function updateRom(updatedData = { ...updatedRom.value }) {
show.value = false;
emitter.emit("showLoadingDialog", true, true);
emitter.emit("showLoadingDialog", { loading: true, scrim: true });
await updateRomApi(rom.value, {
r_igdb_id: updatedData.r_igdb_id,
@@ -50,7 +51,7 @@ async function updateRom(updatedData = { ...updatedRom.value }) {
color: "red",
});
});
emitter.emit("showLoadingDialog", false, false);
emitter.emit("showLoadingDialog", { loading: false, scrim: false });
}
</script>

View File

@@ -5,9 +5,9 @@ const show = ref(false);
const scrim = ref(false);
const emitter = inject("emitter");
emitter.on("showLoadingDialog", (loading, setScrim) => {
show.value = loading;
scrim.value = setScrim;
emitter.on("showLoadingDialog", (args) => {
show.value = args.loading;
scrim.value = args.scrim;
});
</script>

View File

@@ -14,10 +14,10 @@ const matchedRoms = ref([]);
const renameAsIGDB = ref(false);
const emitter = inject("emitter");
emitter.on("showSearchDialog", (romToSearch, updatedRomToSearch) => {
emitter.on("showSearchDialog", (romToSearch) => {
rom.value = romToSearch;
searchTerm.value = romToSearch["file_name_no_tags"];
updatedRom.value = updatedRomToSearch;
updatedRom.value = { ...romToSearch };
searchTerm.value = romToSearch.file_name_no_tags;
show.value = true;
searchRomIGDB();
});
@@ -40,9 +40,9 @@ async function searchRomIGDB() {
async function updateRom(updatedData = { ...updatedRom.value }) {
show.value = false;
emitter.emit("showLoadingDialog", true, true);
emitter.emit("showLoadingDialog", { loading: true, scrim: true });
await updateRomApi(rom, {
await updateRomApi(rom.value, {
r_igdb_id: updatedData.r_igdb_id,
r_slug: updatedData.r_slug,
summary: updatedData.summary,
@@ -74,7 +74,7 @@ async function updateRom(updatedData = { ...updatedRom.value }) {
});
})
.finally(() => {
emitter.emit("showLoadingDialog", false, false);
emitter.emit("showLoadingDialog", { loading: false, scrim: false });
});
}

View File

@@ -26,18 +26,18 @@ const emitter = inject("emitter");
// Functions
onBeforeMount(async () => {
emitter.emit("showLoadingDialog", true, false);
emitter.emit("showLoadingDialog", { loading: true, scrim: false });
await fetchRomApi(route.params.platform, route.params.rom)
.then((response) => {
rom.value = response.data;
downloadUrl.value = `${window.location.origin}${rom.value.download_path}`;
updatedRom.value = response.data;
downloadUrl.value = `${window.location.origin}${rom.value.download_path}`;
})
.catch((error) => {
console.log(error);
})
.finally(() => {
emitter.emit("showLoadingDialog", false, false);
emitter.emit("showLoadingDialog", { loading: false, scrim: false });
});
});
</script>
@@ -139,7 +139,7 @@ onBeforeMount(async () => {
</v-list-item>
<v-divider class="border-opacity-25" />
<v-list-item
@click="emitter.emit('showEditDialog', rom, updatedRom)"
@click="emitter.emit('showEditDialog', rom)"
class="pt-4 pb-4 pr-5"
>
<v-list-item-title class="d-flex"

View File

@@ -20,6 +20,7 @@ import LoadingDialog from "@/components/Dialog/Loading.vue";
// Props
const route = useRoute();
const roms = ref([]);
const updatedRom = ref([]);
const searchRoms = ref([]);
const filteredRoms = ref([]);
const galleryView = storeGalleryView();
@@ -72,7 +73,10 @@ async function fetchMoreSearch() {
if (searchCursor.value === null || gettingRoms.value) return;
gettingRoms.value = true;
emitter.emit("showLoadingDialog", gettingRoms.value, false);
emitter.emit("showLoadingDialog", {
loading: gettingRoms.value,
scrim: false,
});
await fetchRomsApi({
platform: route.params.platform,
cursor: searchCursor.value,
@@ -90,7 +94,10 @@ async function fetchMoreSearch() {
})
.finally(() => {
gettingRoms.value = false;
emitter.emit("showLoadingDialog", gettingRoms.value, false);
emitter.emit("showLoadingDialog", {
loading: gettingRoms.value,
scrim: false,
});
});
}
@@ -98,7 +105,10 @@ async function fetchMoreRoms(platform) {
if (cursor.value === null || gettingRoms.value) return;
gettingRoms.value = true;
emitter.emit("showLoadingDialog", gettingRoms.value, false);
emitter.emit("showLoadingDialog", {
loading: gettingRoms.value,
scrim: false,
});
await fetchRomsApi({ platform, cursor: cursor.value })
.then((response) => {
roms.value = [...roms.value, ...response.data.items];
@@ -110,7 +120,10 @@ async function fetchMoreRoms(platform) {
})
.finally(() => {
gettingRoms.value = false;
emitter.emit("showLoadingDialog", gettingRoms.value, false);
emitter.emit("showLoadingDialog", {
loading: gettingRoms.value,
scrim: false,
});
});
}