2019-10-17 16:56:44 +00:00
|
|
|
<template>
|
2021-01-26 22:51:22 +00:00
|
|
|
<Chat
|
|
|
|
v-if="activeChannel"
|
|
|
|
:network="activeChannel.network"
|
|
|
|
:channel="activeChannel.channel"
|
2022-06-19 00:25:21 +00:00
|
|
|
:focused="parseInt(String(route.query.focused), 10)"
|
|
|
|
@channel-changed="channelChanged"
|
2021-01-26 22:51:22 +00:00
|
|
|
/>
|
2019-10-17 16:56:44 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<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";
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2019-10-17 16:56:44 +00:00
|
|
|
name: "RoutedChat",
|
|
|
|
components: {
|
|
|
|
Chat,
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
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;
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-10-17 16:56:44 +00:00
|
|
|
</script>
|