summaryrefslogtreecommitdiff
path: root/src/client/app/mobile/views/components/ui.vue
blob: 7e2d39f259d4c6dd2e32f274c5e7cd898a0fa8bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<template>
<div class="mk-ui">
	<x-header>
		<template slot="func"><slot name="func"></slot></template>
		<slot name="header"></slot>
	</x-header>
	<x-nav :is-open="isDrawerOpening"/>
	<div class="content">
		<slot></slot>
	</div>
	<mk-stream-indicator v-if="$store.getters.isSignedIn"/>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import MkNotify from './notify.vue';
import XHeader from './ui.header.vue';
import XNav from './ui.nav.vue';

export default Vue.extend({
	components: {
		XHeader,
		XNav
	},
	props: ['title'],
	data() {
		return {
			isDrawerOpening: false,
			connection: null,
			connectionId: null
		};
	},
	mounted() {
		if (this.$store.getters.isSignedIn) {
			this.connection = (this as any).os.stream.getConnection();
			this.connectionId = (this as any).os.stream.use();

			this.connection.on('notification', this.onNotification);
		}
	},
	beforeDestroy() {
		if (this.$store.getters.isSignedIn) {
			this.connection.off('notification', this.onNotification);
			(this as any).os.stream.dispose(this.connectionId);
		}
	},
	methods: {
		onNotification(notification) {
			// TODO: ユーザーが画面を見てないと思われるとき(ブラウザやタブがアクティブじゃないなど)は送信しない
			this.connection.send({
				type: 'read_notification',
				id: notification.id
			});

			(this as any).os.new(MkNotify, {
				notification
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
.mk-ui
	display flex
	flex 1
	flex-direction column
	padding-top 48px

	> .content
		display flex
		flex 1
		flex-direction column
</style>