-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.vue
91 lines (66 loc) · 2.3 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
<template>
<div :class="{ 'dark': darkMode }">
<div class="bg-white dark:bg-dim-900">
<LoadingPage v-if="isAuthLoading" />
<!-- 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">
<!-- Left sidebar -->
<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">
<router-view />
</main>
<!-- Right Sidebar -->
<div class="hidden col-span-12 md:block xl:col-span-4 md:col-span-3">
<div class="sticky top-0">
<SidebarRight />
</div>
</div>
</div>
</div>
<AuthPage v-else />
<UIModal :isOpen="postTweetModal" @on-close="handleModalClose">
<TweetForm :replyTo="replyTweet" showReply :user="user" @onSuccess="handleFormSuccess" />
</UIModal>
</div>
</div>
</template>
<script setup>
const darkMode = ref(false)
const { useAuthUser, initAuth, useAuthLoading, logout } = useAuth()
const isAuthLoading = useAuthLoading()
const { closePostTweetModal, usePostTweetModal, openPostTweetModal, 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
})
onBeforeMount(() => {
initAuth()
})
function handleFormSuccess(tweet) {
closePostTweetModal()
navigateTo({
path: `/status/${tweet.id}`
})
}
function handleModalClose() {
closePostTweetModal()
}
function handleOpenTweetModal() {
openPostTweetModal(null)
}
function handleUserLogout() {
logout()
}
</script>