-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathApp.vue
336 lines (286 loc) · 10.1 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<template>
<div
id="app"
:class="[
`theme-${theme.toLowerCase()}`,
$route.name === 'CFP' ? 'cfp' : 'main',
isInApp() ? 'in-app' : '',
isPopup ? 'popuped' : '',
]"
>
<Navbar v-if="$route.name !== 'CFP' && !isInApp()" />
<transition :name="transitionDirect.toLowerCase()">
<keep-alive>
<router-view class="transition-group" />
</keep-alive>
</transition>
<Footer :show-sponsors="$route.name === 'Home'" />
<Popup :isOpen="isPopup" :content="popupContent" />
</div>
</template>
<script lang="ts">
import { Route } from "vue-router";
import { Component, Watch, Vue } from "vue-property-decorator";
import { Action, Getter } from "vuex-class";
import Navbar from "@/components/Navbar.vue";
import Popup from "@/components/Popup.vue";
import Footer from "@/components/Footer.vue";
import { TemplateState } from "@/store/types/template";
import { DeviceType, AppMode, ThemeType } from "@/store/types/app";
import head from "@/util/head";
enum TransitionDirect {
SLIDE_LEFT = "slide-left",
SLIDE_RIGHT = "slide-right",
}
@Component({
components: {
Navbar,
Popup,
Footer,
},
})
export default class App extends Vue {
@Action("toggleTheme", { namespace: "app" }) private toggleTheme!: (
theme: ThemeType
) => void;
@Action("toggleMode", { namespace: "app" }) private toggleMode!: (
mode: AppMode
) => void;
@Action("toggleDevice", { namespace: "app" }) private toggleDevice!: (
device: DeviceType
) => void;
@Action("togglePopup", { namespace: "app" }) private togglePopup!: (
status: boolean
) => void;
@Action("togglePopupContent", { namespace: "app" })
private togglePopupContent!: (content: string) => void;
@Action("getSunRiseSunSetData", { namespace: "sunRiseSunSet" })
private getSunRiseSunSetData!: () => Promise<void>;
@Getter("device", { namespace: "app" }) private device!: DeviceType;
@Getter("mode", { namespace: "app" }) private mode!: AppMode;
@Getter("theme", { namespace: "app" }) private theme!: ThemeType;
@Getter("isPopup", { namespace: "app" }) private isPopup!: boolean;
@Getter("popupContent", { namespace: "app" }) private popupContent!: string;
@Getter("sunrise", { namespace: "sunRiseSunSet" }) private sunrise!: Date;
@Getter("sunset", { namespace: "sunRiseSunSet" }) private sunset!: Date;
@Getter("submitInfo", { namespace: "template" }) private submitInfo!: string;
@Getter("openSubmit", { namespace: "template" }) private openSubmit!: string;
@Getter("loudly", { namespace: "template" }) private loudly!: string;
private transitionDirect: TransitionDirect = TransitionDirect.SLIDE_LEFT;
public async mounted() {
this.autoDetectMetaOg();
this.detectPopupFromLoadURL();
this.assignThemePrefixToBody(this.theme);
this.detectAppMode();
this.detectDeviceType();
window.addEventListener("resize", this.detectDeviceType);
window.addEventListener("keyup", this.escHandler);
await this.detectSystemPrefersColorSchema();
window.matchMedia("(prefers-color-scheme: dark)").addListener(async () => {
await this.detectSystemPrefersColorSchema();
});
}
@Watch("$route")
public onChangeRoute(to: Route, from: Route) {
this.autoDetectMetaOg();
this.detectPopupFromLoadURL();
this.detectTransitionDirect(to, from);
}
@Watch("isPopup")
public onChangePopup(value: boolean) {
this.toggleBodyLock(value);
}
@Watch("theme")
public onThemeChange(theme: ThemeType) {
this.assignThemePrefixToBody(theme);
}
public destroyed() {
window.removeEventListener("resize", this.detectDeviceType);
}
private isInApp(): boolean {
return this.mode === AppMode.APP;
}
private detectedEgg(): boolean {
const now: Date = new Date();
return (
now.getTime() > new Date("2019-10-26").getTime() &&
now.getTime() < new Date("2019-11-27").getTime()
);
}
private detectAppMode(): void {
const isApp: boolean = this.$route.query.mode === "app";
if (isApp) {
this.toggleMode(AppMode.APP);
} else {
this.toggleMode(AppMode.WEB);
}
}
private detectDeviceType(): void {
const isDesktop: boolean = window.matchMedia("(min-width: 1024px)").matches;
if (isDesktop) {
this.toggleDevice(DeviceType.DESKTOP);
} else {
this.toggleDevice(DeviceType.MOBILE);
}
}
private async detectSystemPrefersColorSchema(): Promise<void> {
const isDarkMode: boolean = window.matchMedia(
"(prefers-color-scheme: dark)"
).matches;
const isLightMode: boolean = window.matchMedia(
"(prefers-color-scheme: light)"
).matches;
if (isLightMode) {
this.detectedEgg()
? this.toggleTheme(ThemeType.RAINBOW_LIGHT)
: this.toggleTheme(ThemeType.LIGHT);
} else if (isDarkMode) {
this.detectedEgg()
? this.toggleTheme(ThemeType.RAINBOW_DARK)
: this.toggleTheme(ThemeType.DARK);
} else {
await this.getSunRiseSunSetData();
this.toggleThemeViaSunRiseSunSet();
setInterval(() => {
this.toggleThemeViaSunRiseSunSet();
}, 1000);
}
}
private toggleThemeViaSunRiseSunSet(): void {
const now = new Date();
const isEgg: boolean = this.detectedEgg();
const isDay: boolean =
now.getTime() > this.sunrise.getTime() &&
now.getTime() < this.sunset.getTime();
let themePrefix: string = "";
if (isEgg) {
themePrefix = "RAINBOW_";
} else {
themePrefix = "";
}
if (isDay) {
themePrefix += "LIGHT";
} else {
themePrefix += "DARK";
}
this.toggleTheme(ThemeType[themePrefix as keyof typeof ThemeType]);
}
private assignThemePrefixToBody(theme: ThemeType): void {
const bodyDOM = document.querySelector("body") as HTMLElement;
bodyDOM.classList.remove("theme-dark");
bodyDOM.classList.remove("theme-light");
bodyDOM.classList.remove("theme-rainbow-dark");
bodyDOM.classList.add(`theme-${theme}`);
}
private detectPopupFromLoadURL(): void {
if (this.$route.query && this.$route.query.popUp) {
switch (this.$route.query.popUp) {
case "submitInfo":
this.togglePopup(true);
this.togglePopupContent(this.submitInfo);
break;
case "openSubmit":
this.togglePopup(true);
this.togglePopupContent(this.openSubmit);
break;
case "loudly":
this.togglePopup(true);
this.togglePopupContent(this.loudly);
break;
default:
break;
}
} else if (!this.$route.name!.includes("Agenda")) {
this.togglePopup(false);
}
}
private detectTransitionDirect(to: Route, from: Route): void {
if (to.meta.index < from.meta.index) {
this.transitionDirect = TransitionDirect.SLIDE_RIGHT;
} else {
this.transitionDirect = TransitionDirect.SLIDE_LEFT;
}
}
private toggleBodyLock(isLock: boolean): void {
if (isLock) {
(document.querySelector("body") as HTMLElement).classList.add(
"popup-scrolling-lock"
);
} else {
(document.querySelector("body") as HTMLElement).classList.remove(
"popup-scrolling-lock"
);
}
}
private escHandler(event: any): void {
if (event.keyCode === 27 && this.isPopup) {
this.togglePopup(false);
}
}
private autoDetectMetaOg(): void {
switch (this.$route.name) {
case "Agenda":
head.title("議程表");
head.ogTitle("議程表");
head.ogDescription(
"GopherCon TW 2020 邀請身為 Golang 使用者的你,向大家分享您的經驗與技術,期待您能在演講桌前,與我們一起 have fun with golang。"
);
head.ogUrl("https://gophercon.golang.tw/2020/agenda/");
head.ogImage("https://gophercon.golang.tw/2020/img/og.png");
break;
case "Traffic":
head.title("交通方式");
head.ogTitle("交通方式");
head.ogDescription(
"GopherCon TW 2020 邀請身為 Golang 使用者的你,向大家分享您的經驗與技術,期待您能在演講桌前,與我們一起 have fun with golang。"
);
head.ogUrl("https://gophercon.golang.tw/2020/traffic/");
head.ogImage("https://gophercon.golang.tw/2020/img/og.png");
break;
case "Team":
case "Team/Staff":
case "Team/Sponsor":
head.title("GopherCon團隊");
head.ogTitle("GopherCon團隊");
head.ogDescription(
"GopherCon TW 2020 邀請身為 Golang 使用者的你,向大家分享您的經驗與技術,期待您能在演講桌前,與我們一起 have fun with golang。"
);
head.ogUrl("https://gophercon.golang.tw/2020/team/staff");
head.ogImage("https://gophercon.golang.tw/2020/img/og.png");
break;
case "Sponsor":
head.title("贊助");
head.ogTitle("贊助");
head.ogDescription(
"GopherCon TW 2020 邀請身為 Golang 使用者的你,向大家分享您的經驗與技術,期待您能在演講桌前,與我們一起 have fun with golang。"
);
head.ogUrl("https://gophercon.golang.tw/2020/sponsor");
head.ogImage("https://gophercon.golang.tw/2020/img/og.png");
break;
case "Venue":
head.title("會場地圖");
head.ogTitle("會場地圖");
head.ogDescription(
"GopherCon TW 2020 邀請身為 Golang 使用者的你,向大家分享您的經驗與技術,期待您能在演講桌前,與我們一起 have fun with golang。"
);
head.ogUrl("https://gophercon.golang.tw/2020/traffic/");
head.ogImage("https://gophercon.golang.tw/2020/img/og.png");
break;
case "Covid-19":
head.title("Covid-19");
head.ogTitle("Covid-19");
head.ogDescription(
"GopherCon TW 2020 邀請身為 Golang 使用者的你,向大家分享您的經驗與技術,期待您能在演講桌前,與我們一起 have fun with golang。"
);
head.ogUrl("https://gophercon.golang.tw/2020/traffic/");
head.ogImage("https://gophercon.golang.tw/2020/img/og.png");
break;
default:
break;
}
}
}
</script>
<style lang="scss">
@import "@/assets/scss/main.scss";
</style>