-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.vue
150 lines (129 loc) · 4.16 KB
/
app.vue
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
<v-app>
<NuxtLayout>
<NuxtLoadingIndicator />
<v-app-bar fixed clipped-left class="px-3">
<template #prepend>
<v-app-bar-nav-icon @click="drawer = !drawer" />
</template>
<NuxtLink to="/" class="ml-2">
<v-avatar size="30" image="/icon.png" />
</NuxtLink>
<v-spacer />
<v-btn v-if="userInfo.loggedIn" icon>
<v-badge
bordered
color="primary"
:content="notif.length"
class="text-amber"
size="x-small"
>
<v-icon>
{{
notif.length > 0
? `mdi-bell-ring${notifOverlay ? '' : '-outline'}`
: `mdi-bell${notifOverlay ? '' : '-outline'}`
}}
</v-icon>
</v-badge>
<v-dialog
v-if="userInfo.loggedIn"
v-model="notifOverlay"
width="700"
scrollable
activator="parent"
>
<v-card>
<v-list v-if="notif.length > 0" nav>
<v-list-item
v-for="(d, i) in notif"
:key="i"
@click="LoadNotification(d.link)"
>
<template #prepend>
<UserPhoto :size="45" :src="d?.photoURL" />
</template>
<v-list-item-title>{{ d.title }}</v-list-item-title>
<v-list-item-subtitle>{{ d.time }}</v-list-item-subtitle>
</v-list-item>
</v-list>
<div v-else>
<v-card class="text-center text-grey">
<v-card-text>댓글이 없습니다.</v-card-text>
</v-card>
</div>
<v-card-actions>
<v-divider />
<v-btn
rounded="lg"
variant="tonal"
append-icon="mdi-notification-clear-all"
@click="clearEverything"
>
비우기
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-btn>
<v-btn v-if="userInfo.loggedIn" icon>
<MenuUserBox />
</v-btn>
<v-btn
v-else
rounded="lg"
variant="tonal"
to="/account/login"
icon="mdi-account-circle"
/>
</v-app-bar>
<v-navigation-drawer v-model="drawer" floating mobile-breakpoint="400">
<MenuNavigation />
</v-navigation-drawer>
<v-main :class="route.path !== '/' ? 'mx-5' : ''">
<NuxtPage class="mb-10" />
<v-banner
v-if="userInfo.uid && (!userInfo.displayName || !userInfo.photoURL)"
:sticky="true"
lines="one"
class="rounded-lg"
>
<template #text>
<div class="ma-2">설정에서 이름과 사진을 변경하세요</div>
</template>
<template #actions>
<v-btn rounded="lg" to="/account/account" icon="mdi-open-in-new" />
</template>
</v-banner>
</v-main>
</NuxtLayout>
</v-app>
</template>
<script setup lang="ts">
import { useDisplay } from 'vuetify'
const { $db } = useNuxtApp()
const { mobile } = useDisplay()
const route = useRoute()
const userInfo = User()
userInfo.initUserInfo()
const notif = ref<any>([])
const notifOverlay = ref<boolean>(false)
const drawer = ref<boolean>(!mobile.value)
useAuth((u: any) => {
$db
.ref(`/users/${u.uid}/notification`)
.on('child_added', async (s: any) => notif.value.push(await s.val()))
$db.ref('.info/connected').on('value', () => {
$db.ref(`/users/${userInfo.uid}/status`).onDisconnect().set('offline')
$db.ref(`/users/${userInfo.uid}/status`).set('online')
})
})
const clearEverything = () => {
$db.ref(`/users/${userInfo.uid}/notification`).remove()
notif.value = []
}
const LoadNotification = (link: string) => {
notifOverlay.value = false
navigateTo(link)
}
</script>