diff --git a/src/main.js b/src/main.js index 1dcb80b..9c17a5b 100644 --- a/src/main.js +++ b/src/main.js @@ -9,17 +9,26 @@ import {createVuetify} from 'vuetify' import * as components from 'vuetify/components' import * as directives from 'vuetify/directives' import vueGoogleOauth from 'vue3-google-login' +import {useSubscriptionStore} from "@/stores/subscriptionStore.js"; +import {useAuthStore} from "@/stores/authStore.js"; +import {useUserStore} from "@/stores/userStore.js"; const vuetify = createVuetify({ components, directives }); -createApp(App) +const app = createApp(App) .use(createPinia()) .use(vuetify) .use(router) .use(vueGoogleOauth, { clientId: import.meta.env.VITE_GOOGLE_CLIENT_ID, }) - .mount('#app'); + +// this force the creation of the stores +const subscriptionStore = useSubscriptionStore() +const authStore = useAuthStore() +const userStore = useUserStore() + +app.mount('#app'); diff --git a/src/stores/counter.js b/src/stores/counter.js deleted file mode 100644 index b6757ba..0000000 --- a/src/stores/counter.js +++ /dev/null @@ -1,12 +0,0 @@ -import { ref, computed } from 'vue' -import { defineStore } from 'pinia' - -export const useCounterStore = defineStore('counter', () => { - const count = ref(0) - const doubleCount = computed(() => count.value * 2) - function increment() { - count.value++ - } - - return { count, doubleCount, increment } -}) diff --git a/src/stores/subscriptionStore.js b/src/stores/subscriptionStore.js new file mode 100644 index 0000000..225ea60 --- /dev/null +++ b/src/stores/subscriptionStore.js @@ -0,0 +1,71 @@ +import {defineStore} from "pinia"; +import {useSessionStorage} from "@vueuse/core"; +import {useClient} from "@/plugins/api.js"; +import {useAuthStore} from "@/stores/authStore.js"; +import {watch} from "vue"; + +export const useSubscriptionStore = defineStore( + 'subscription', + () => { + + const subscriptions = useSessionStorage( + 'subscription-subscriptions', + {}) + + const authStore = useAuthStore() + const authWatcher = watch( + () => authStore.isAuthenticated, + async (newValue) => { + if (newValue) { + await loadSubscriptions() + } else { + subscriptions.value = {} + } + }) + + function isSubscribeTo(creatorId) { + return !!subscriptions.value[creatorId]; + } + + async function subscribeTo(creatorId) { + try { + const client = useClient() + const response = await client.post( + `/api/creators/${creatorId}/subscribe` + ); + subscriptions.value[creatorId] = response.data; + } catch (error) { + console.error("Error subscribing to creator", error); + } + } + + async function unsubscribeFrom(creatorId) { + try { + const client = useClient() + const response = await client.post( + `/api/creators/${creatorId}/unsubscribe` + ); + delete subscriptions.value[creatorId]; + } catch (error) { + console.error("Error unsubscribing from creator", error); + } + } + + async function loadSubscriptions() { + try { + const client = useClient() + const response = await client.get(`/api/subscriptions`); + + subscriptions.value = response.data.reduce( + (acc, sub) => { + acc[sub.creatorId] = sub; + return acc; + }, + {}); + } catch (error) { + console.error("Error loading subscriptions:", error); + } + } + + return {subscriptions, isSubscribeTo, subscribeTo, unsubscribeFrom} + }); \ No newline at end of file diff --git a/src/views/Profile/ManageAccount.vue b/src/views/Profile/ManageAccount.vue index 8f4b640..63d3fb5 100644 --- a/src/views/Profile/ManageAccount.vue +++ b/src/views/Profile/ManageAccount.vue @@ -14,7 +14,8 @@ :src="'/images/usersmedia/anonyme/profilepictures/profileAnonymeSquare.png'" alt="Profile Image" class="ml-2 rounded-full" - style="width: 48px; height: 48px;"> + width="48" + height="48"> @@ -40,7 +41,8 @@ :src="'/images/usersmedia/anonyme/profilepictures/profileAnonymeSquare.png'" alt="Profile Image" class="ml-2 rounded-full" - style="width: 48px; height: 48px;"> + width="48" + height="48"> diff --git a/src/views/contents/ContentList.vue b/src/views/contents/ContentList.vue index 7e94c8c..4dbc0c0 100644 --- a/src/views/contents/ContentList.vue +++ b/src/views/contents/ContentList.vue @@ -45,7 +45,7 @@ let last_id = null async function load({done}) { try { - let uri = `/api/contents/user/${props.creatorId}?page_size=${page_size}` + let uri = `/api/contents/creator/${props.creatorId}?page_size=${page_size}` if (last_id !== null) uri = uri + `&last_id=${last_id}` const response = await client.get(uri) diff --git a/src/views/creators/CreatorBanner.vue b/src/views/creators/CreatorBanner.vue index cdb17a4..48b4e6d 100644 --- a/src/views/creators/CreatorBanner.vue +++ b/src/views/creators/CreatorBanner.vue @@ -66,11 +66,8 @@