-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.vue
308 lines (290 loc) · 10.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<template>
<div>
<client-only>
<header>
<NavbarDesktop />
<NavbarMobile />
</header>
<div
class="position-absolute top-50 start-50 translate-middle z-3 pointer-none"
>
<LoadingIndicator
with-transition
:throttle="loadingIndicatorThrottle"
/>
</div>
<template #fallback>
<header>
<nav
id="navbar_large"
data-v-454188a5=""
class="navbar fixed-top navbar-expand ourBack d-none d-xl-flex pl-1 pr-2 navbar-dark navbar-expand-xl"
>
<div class="container-fluid">
<a
data-v-454188a5=""
aria-current="page"
href="/"
class="router-link-active router-link-exact-active navbar-brand p-0"
><picture data-v-454188a5="" class="logo mr-2"
><source
type="image/webp"
sizes="58px"
srcset="
https://61ddd294bd3a390019c6.ucr.io//-/format/webp/-/resize/58x//https://www.ilovefreegle.org/icon.png 58w,
https://61ddd294bd3a390019c6.ucr.io//-/format/webp/-/resize/116x//https://www.ilovefreegle.org/icon.png 116w
" />
<img
alt="Home"
loading="eager"
data-nuxt-pic=""
src="https://61ddd294bd3a390019c6.ucr.io//-/format/png/-/resize/116x//https://www.ilovefreegle.org/icon.png"
sizes="58px"
srcset="
https://61ddd294bd3a390019c6.ucr.io//-/format/png/-/resize/58x//https://www.ilovefreegle.org/icon.png 58w,
https://61ddd294bd3a390019c6.ucr.io//-/format/png/-/resize/116x//https://www.ilovefreegle.org/icon.png 116w
" /></picture></a
><!----><!---->
<div data-v-454188a5="" class="navbar-nav ml-auto">
<div data-v-454188a5="" class="nav-item" no-prefetch="">
<button
data-v-454188a5=""
class="btn btn-md btn-white mr-2"
type="button"
>
Sign in
</button>
</div>
</div>
</div>
</nav>
<nav
class="navbar fixed-top navbar-expand ourBack d-flex justify-content-between d-xl-none showNavBarTop"
type="dark"
>
<div class="container-fluid">
<div />
<div />
<div class="d-flex align-items-center">
<ul class="nav">
<a><div class="btn btn-white mr-2">Log in or Join</div></a>
</ul>
</div>
</div>
</nav>
</header>
</template>
</client-only>
<div
v-if="ready"
class="nuxt-layout-wrapper"
:style="{
filter: isLoading ? 'blur(1rem)' : 'unset',
}"
>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</div>
</div>
</template>
<script setup>
import { useRoute } from 'vue-router'
import { useNoticeboardStore } from './stores/noticeboard'
import { useAuthStore } from './stores/auth'
import { useGroupStore } from './stores/group'
import { useMessageStore } from './stores/message'
import { useUserStore } from './stores/user'
import { useIsochroneStore } from './stores/isochrone'
import { useComposeStore } from './stores/compose'
import { useChatStore } from './stores/chat'
import { useAddressStore } from './stores/address'
import { useTrystStore } from './stores/tryst'
import { useNotificationStore } from './stores/notification'
import { useNewsfeedStore } from './stores/newsfeed'
import { useReplyStore } from './stores/reply'
import { useSearchStore } from './stores/search'
import { useStoryStore } from './stores/stories'
import { useVolunteeringStore } from './stores/volunteering'
import { useCommunityEventStore } from './stores/communityevent'
import { useJobStore } from './stores/job'
import { useTeamStore } from './stores/team'
import { useDonationStore } from './stores/donations'
import { useGiftAidStore } from './stores/giftaid'
import { useAuthorityStore } from './stores/authority'
import { useStatsStore } from './stores/stats'
import { useMicroVolunteeringStore } from './stores/microvolunteering'
import { useImageStore } from './stores/image'
import { useDomainStore } from './stores/domain'
import { useLogoStore } from './stores/logo'
import { useLocationStore } from './stores/location'
import { useShortlinkStore } from './stores/shortlinks'
import { useMiscStore } from './stores/misc'
import { computed, watch, reloadNuxtApp } from '#imports'
// polyfills
import 'core-js/actual/array/to-sorted'
const route = useRoute()
const loadingIndicatorThrottle = ref(5000)
const { isLoading } = useLoadingIndicator({
throttle: loadingIndicatorThrottle.value,
})
// Don't render the app until we've done everything in here.
let ready = false
// We're having trouble accessing the Nuxt config from within a Pinia store. So instead we access it here, then
// pass it in to each store via an init() action.
//
// Starting with around Nuxt 3.4.1, when we first access the config (here) it has public as we'd expect, but
// if we store that and access it later, we are just looking at the contents of public. I don't understand why
// this is, but we don't expect the config to change, so we take a copy here.
const runtimeConfig = JSON.parse(JSON.stringify(useRuntimeConfig()))
const miscStore = useMiscStore()
const groupStore = useGroupStore()
const messageStore = useMessageStore()
const authStore = useAuthStore()
const userStore = useUserStore()
const isochroneStore = useIsochroneStore()
const composeStore = useComposeStore()
const chatStore = useChatStore()
const addressStore = useAddressStore()
const trystStore = useTrystStore()
const notificationStore = useNotificationStore()
const newsfeedStore = useNewsfeedStore()
const replyStore = useReplyStore()
const searchStore = useSearchStore()
const storyStore = useStoryStore()
const volunteeringStore = useVolunteeringStore()
const communityEventStore = useCommunityEventStore()
const jobStore = useJobStore()
const teamStore = useTeamStore()
const donationStore = useDonationStore()
const giftAidStore = useGiftAidStore()
const authorityStore = useAuthorityStore()
const noticeboardStore = useNoticeboardStore()
const statsStore = useStatsStore()
const microVolunteeringStore = useMicroVolunteeringStore()
const imageStore = useImageStore()
const domainStore = useDomainStore()
const logoStore = useLogoStore()
const locationStore = useLocationStore()
const shortlinkStore = useShortlinkStore()
miscStore.init(runtimeConfig)
groupStore.init(runtimeConfig)
messageStore.init(runtimeConfig)
authStore.init(runtimeConfig)
userStore.init(runtimeConfig)
isochroneStore.init(runtimeConfig)
composeStore.init(runtimeConfig)
chatStore.init(runtimeConfig)
addressStore.init(runtimeConfig)
trystStore.init(runtimeConfig)
notificationStore.init(runtimeConfig)
newsfeedStore.init(runtimeConfig)
replyStore.init(runtimeConfig)
searchStore.init(runtimeConfig)
storyStore.init(runtimeConfig)
volunteeringStore.init(runtimeConfig)
communityEventStore.init(runtimeConfig)
jobStore.init(runtimeConfig)
teamStore.init(runtimeConfig)
donationStore.init(runtimeConfig)
giftAidStore.init(runtimeConfig)
authorityStore.init(runtimeConfig)
noticeboardStore.init(runtimeConfig)
statsStore.init(runtimeConfig)
microVolunteeringStore.init(runtimeConfig)
imageStore.init(runtimeConfig)
domainStore.init(runtimeConfig)
logoStore.init(runtimeConfig)
locationStore.init(runtimeConfig)
shortlinkStore.init(runtimeConfig)
const loginCount = computed(() => {
return authStore.loginCount
})
watch(loginCount, async () => {
if (!route.query.k) {
await reloadNuxtApp({
force: true,
persistState: false,
})
}
})
try {
if (route.query.u && route.query.k) {
// We are impersonating.
try {
// Clear the related list. This avoids accidentally flagging members as related if people forget to close
// an incognito tab while impersonating.
await authStore.clearRelated()
// Log in using the username and key.
await authStore.login({
u: route.query.u,
k: route.query.k,
})
} catch (e) {
// Login failed. Usually this is because they're logged in as someone else. Ignore it.
console.log('Login failed', e)
}
}
} catch (e) {
console.error('Error fetching user', e)
}
if (process.client) {
if (typeof window !== 'undefined') {
// There's a bug https://github.com/nuxt/framework/issues/3141 which causes route to stop working.
const messages = [
`Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`, // chromium based
`NotFoundError: The object can not be found here.`, // safari
`Cannot read properties of null (reading 'subTree')`,
]
window.addEventListener('error', (ev) => {
if (messages.includes(ev.message)) {
ev.preventDefault()
window.location.reload()
}
})
window.onunhandledrejection = (ev) => {
// We get various of these - some from Leaflet. It seems to break Nuxt routing and we get stuck, so if we
// get one of these reload the page so that at least we keep going.
if (messages.includes(ev.message)) {
console.error('Unhandled rejection - may break Nuxt - reload')
ev.preventDefault()
window.location.reload()
}
}
}
const chatCount = computed(() => {
return chatStore.unreadCount
})
const notificationCount = computed(() => {
return notificationStore.count
})
useHead({
titleTemplate: (titleChunk) => {
const totalCount = notificationCount.value + chatCount.value
if (titleChunk) {
if (titleChunk.charAt(0) !== '(' && totalCount.value > 0) {
return '(' + totalCount.value + ') ' + titleChunk
} else {
return titleChunk
}
} else {
return null
}
},
})
}
ready = true
</script>
<style lang="scss">
.nuxt-layout-wrapper {
transition: all 0.25s;
}
.trans {
background-color: transparent !important;
color: transparent !important;
border: none !important;
}
.pointer-none {
pointer-events: none;
}
</style>