init
This commit is contained in:
@@ -1,9 +1,16 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {computed, onMounted, ref} from 'vue';
|
import {computed, onMounted, ref, watch} from 'vue';
|
||||||
import {useRoute} from 'vue-router';
|
import {useRoute} from 'vue-router';
|
||||||
import {storeToRefs} from 'pinia'; // Import crucial
|
import {storeToRefs} from 'pinia'; // Import crucial
|
||||||
import {useMessageStore} from '@/stores/message';
|
import {useMessageStore} from '@/stores/message';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
serverId: string
|
||||||
|
channelId: string
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const channelId = computed(() => props.channelId);
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const messageStore = useMessageStore();
|
const messageStore = useMessageStore();
|
||||||
|
|
||||||
@@ -11,7 +18,7 @@ const messageStore = useMessageStore();
|
|||||||
const {messages, loading} = storeToRefs(messageStore);
|
const {messages, loading} = storeToRefs(messageStore);
|
||||||
|
|
||||||
const newMessage = ref('');
|
const newMessage = ref('');
|
||||||
const channelId = computed(() => route.params.channelId as string);
|
|
||||||
|
|
||||||
const sendMessage = async () => {
|
const sendMessage = async () => {
|
||||||
if (!newMessage.value.trim()) return;
|
if (!newMessage.value.trim()) return;
|
||||||
@@ -31,6 +38,11 @@ onMounted(() => {
|
|||||||
messageStore.fetchMessages(channelId.value);
|
messageStore.fetchMessages(channelId.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
watch(channelId, (newChannelId) => {
|
||||||
|
if (newChannelId) {
|
||||||
|
messageStore.fetchMessages(newChannelId);
|
||||||
|
}
|
||||||
|
}, {immediate: true})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {storeToRefs} from 'pinia'
|
import {storeToRefs} from 'pinia'
|
||||||
import {useChannelStore} from '@/stores/channel'
|
import {useChannelStore} from '@/stores/channel'
|
||||||
import {computed, ref} from 'vue'
|
import {ref} from 'vue'
|
||||||
import {useRoute} from 'vue-router'
|
import {useRoute} from 'vue-router'
|
||||||
|
|
||||||
const route = useRoute()
|
const props = defineProps<{
|
||||||
const serverId = computed(() => route.params.serverId as string)
|
serverId: string
|
||||||
|
channelId?: string
|
||||||
|
}>();
|
||||||
|
const serverId = props.serverId
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
const channelStore = useChannelStore()
|
const channelStore = useChannelStore()
|
||||||
const {channels} = storeToRefs(channelStore)
|
const {channels} = storeToRefs(channelStore)
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const router = createRouter({
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to) => {
|
||||||
const sessionStore = useSessionStore()
|
const sessionStore = useSessionStore()
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
if (!sessionStore.isReady) {
|
if (!sessionStore.isReady) {
|
||||||
@@ -93,16 +93,16 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
|
|
||||||
if (authRequired && !authStore.isAuthenticated) {
|
if (authRequired && !authStore.isAuthenticated) {
|
||||||
// Non connecté -> Login
|
// Non connecté -> Login
|
||||||
next('/auth/login')
|
return '/auth/login'
|
||||||
} else if (to.name === 'login' && authStore.isAuthenticated) {
|
} else if (to.name === 'login' && authStore.isAuthenticated) {
|
||||||
// Déjà connecté -> Accueil
|
// Déjà connecté -> Accueil
|
||||||
next('/')
|
return '/'
|
||||||
} else if (adminRequired && !authStore.isAdmin) {
|
} else if (adminRequired && !authStore.isAdmin) {
|
||||||
// Connecté mais pas admin -> Accueil (ou page 403)
|
// Connecté mais pas admin -> Accueil (ou page 403)
|
||||||
next('/')
|
return '/'
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
}
|
||||||
|
// Retourner true ou ne rien retourner permet de continuer la navigation
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export const useGatewayStore = defineStore('gateway', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async handleMessage(rawData: string) {
|
async handleMessage(rawData: string) {
|
||||||
|
console.log("[ws]message received", rawData)
|
||||||
},
|
},
|
||||||
|
|
||||||
async scheduleReconnect() {
|
async scheduleReconnect() {
|
||||||
|
|||||||
Reference in New Issue
Block a user