thelounge/client/components/RoutedChat.vue

67 lines
1.4 KiB
Vue
Raw Permalink Normal View History

2019-10-17 16:56:44 +00:00
<template>
<Chat
v-if="activeChannel"
:network="activeChannel.network"
:channel="activeChannel.channel"
:focused="parseInt(String(route.query.focused), 10)"
@channel-changed="channelChanged"
/>
2019-10-17 16:56:44 +00:00
</template>
<script lang="ts">
import {watch, computed, defineComponent, onMounted} from "vue";
import {useRoute} from "vue-router";
import {useStore} from "../js/store";
import {ClientChan} from "../js/types";
2019-10-17 16:56:44 +00:00
// Temporary component for routing channels and lobbies
import Chat from "./Chat.vue";
export default defineComponent({
2019-10-17 16:56:44 +00:00
name: "RoutedChat",
components: {
Chat,
},
setup() {
const route = useRoute();
const store = useStore();
const activeChannel = computed(() => {
const chanId = parseInt(String(route.params.id || ""), 10);
const channel = store.getters.findChannel(chanId);
2019-10-17 16:56:44 +00:00
return channel;
});
const setActiveChannel = () => {
if (activeChannel.value) {
store.commit("activeChannel", activeChannel.value);
}
};
watch(activeChannel, () => {
setActiveChannel();
});
onMounted(() => {
setActiveChannel();
});
const channelChanged = (channel: ClientChan) => {
const chanId = channel.id;
const chanInStore = store.getters.findChannel(chanId);
if (chanInStore?.channel) {
chanInStore.channel.unread = 0;
chanInStore.channel.highlight = 0;
}
};
return {
route,
activeChannel,
channelChanged,
};
2019-10-17 16:56:44 +00:00
},
});
2019-10-17 16:56:44 +00:00
</script>