-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
99 lines (86 loc) · 2.27 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
<template>
<div :class="{ dark: darkMode }">
<div class="bg-white dark:bg-dim-900">
<div v-if="isAuthLoading">
<LoadingPage />
</div>
<!-- App -->
<div v-else-if="user" clas="min-h-full">
<div
class="grid grid-cols-12 mx-auto sm:px-6 lg:max-w-7xl lg:px-8 lg:gap-5"
>
<div class="hidden md:block xs-col-span-1 xl:col-span-2">
<div class="sticky top-0">
<SidebarLeft
:user="user"
@on-tweet="handleOpenTweetModal"
@on-logOut="handleUserLogOut"
/>
</div>
</div>
<!-- Main content -->
<main class="col-span-12 md:col-span-8 xl:col-span-6 max-h">
<router-view />
</main>
<!-- Right Sidebar -->
<div class="hidden md:block xl:col-span-4 md:col-span-4">
<div class="sticky top-0">
<SidebarRight :mode="mode" />
</div>
</div>
</div>
</div>
<AuthPage v-else />
<UIModal :isOpen="postTweetModal" @on-close="handleCloseTweetModal">
<TweetForm
:replyTo="replyTweet"
:user="user"
showReply
@on-success="handleFormSuccess"
/>
</UIModal>
</div>
</div>
</template>
<script setup>
import { onBeforeMount } from 'vue'
const darkMode = ref(false)
const mode = ref('Dark')
const { useAuthUser, initAuth, useAuthLoading, logout } = useAuth()
const isAuthLoading = useAuthLoading()
const {
closePostTweetModal,
openPostTweetModal,
usePostTweetModal,
useReplyTweet,
} = useTweets()
const user = useAuthUser()
const postTweetModal = usePostTweetModal()
const emitter = useEmitter()
const replyTweet = useReplyTweet()
emitter.$on('replyTweet', (tweet) => {
openPostTweetModal(tweet)
})
emitter.$on('toggleDarkMode', () => {
darkMode.value = !darkMode.value
mode.value = darkMode.value ? 'Light' : 'Dark'
})
function handleFormSuccess(tweet) {
closePostTweetModal()
navigateTo({
path: `/status/${tweet.id}`,
})
}
function handleCloseTweetModal() {
closePostTweetModal()
}
function handleOpenTweetModal() {
openPostTweetModal(null)
}
function handleUserLogOut() {
logout()
}
onBeforeMount(() => {
initAuth()
})
</script>