Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
langehm committed Dec 11, 2024
1 parent a4c20e1 commit 1ed9e1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
25 changes: 1 addition & 24 deletions anzeigen-frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,18 @@

<script setup lang="ts">
import { useTitle } from "@vueuse/core";
import { onMounted } from "vue";
import { getUser } from "@/api/user-client";
import Ad2ImageAvatar from "@/components/common/Ad2ImageAvatar.vue";
import SearchAd from "@/components/Filter/SearchAd.vue";
import TheSnackbarQueue from "@/components/TheSnackbarQueue.vue";
import { useApi } from "@/composables/useApi";
import { useUserStore } from "@/stores/user";
import User, { UserLocalDevelopment } from "@/types/User";
useApi();
useTitle("Anzeigen Portal");
const userStore = useUserStore();
onMounted(() => {
loadUser();
});
/**
* Loads UserInfo from the backend and sets it in the store.
*/
function loadUser(): void {
getUser()
.then((user: User) => userStore.setUser(user))
.catch(() => {
// No user info received, so fallback
if (import.meta.env.DEV) {
userStore.setUser(UserLocalDevelopment());
} else {
userStore.setUser(null);
}
});
}
useTitle("Anzeigen Portal");
</script>

<style>
Expand Down
15 changes: 10 additions & 5 deletions anzeigen-frontend/src/views/AdDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ import type {
import { useMemoize } from "@vueuse/core";
import { useRouteQuery } from "@vueuse/router";
import { onMounted, ref, watch } from "vue";
import { onActivated, ref, watch } from "vue";
import { useRouter } from "vue-router";
import AdNotFound from "@/components/Ad/Details/AdNotFound.vue";
import AdOverview from "@/components/Ad/Details/AdOverview.vue";
import { useGetAd } from "@/composables/api/useAdApi";
import { useClearCacheEventBus } from "@/composables/useEventBus";
const exampleAd: AdTO = {
id: 1,
Expand Down Expand Up @@ -89,26 +90,30 @@ const exampleAd: AdTO = {
views: 150,
};
const router = useRouter();
const clearCacheEventBus = useClearCacheEventBus();
const idQuery = useRouteQuery("id");
const adDetails = ref<Readonly<AdTO> | null>(exampleAd);
const router = useRouter();
const { call: getAdCall, data: getAdData, error: getAdError } = useGetAd();
const adDetails = ref<Readonly<AdTO> | null>(null);
const getAd = useMemoize(async (adId: number) => {
await getAdCall({ id: adId });
return getAdData;
});
const idQuery = useRouteQuery("id");
clearCacheEventBus.on(() => getAd.clear());
watch(idQuery, (newId) => {
if (newId !== null) {
updateAd(newId.toString() || "1");
}
});
onMounted(() => {
onActivated(() => {
updateAd(idQuery.value?.toString() || "");
});
Expand Down

0 comments on commit 1ed9e1b

Please sign in to comment.