forked from pulsejet/memories
-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.ts
202 lines (176 loc) · 5.02 KB
/
router.ts
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
import Router, { type Route, type RouteConfig } from 'vue-router';
import Vue from 'vue';
import { generateUrl } from '@nextcloud/router';
import Timeline from '@components/Timeline.vue';
import Explore from '@components/Explore.vue';
import SplitTimeline from '@components/SplitTimeline.vue';
import ClusterView from '@components/ClusterView.vue';
import NativeXSetup from '@native/Setup.vue';
import { translate as t } from '@services/l10n';
import { constants as c } from '@services/utils';
// Routes are defined here
export type RouteId =
| 'Base'
| 'Folders'
| 'Favorites'
| 'Videos'
| 'Albums'
| 'Archive'
| 'ThisDay'
| 'Recognize'
| 'FaceRecognition'
| 'Places'
| 'Tags'
| 'FolderShare'
| 'AlbumShare'
| 'Map'
| 'Explore'
| 'NxSetup';
export const routes: { [key in RouteId]: RouteConfig } = {
Base: {
path: '/',
component: Timeline,
name: 'timeline',
props: (route: Route) => ({ rootTitle: t('memories', 'Timeline') }),
},
Folders: {
path: '/folders/:path*',
component: Timeline,
name: 'folders',
props: (route: Route) => ({ rootTitle: t('memories', 'Folders') }),
},
Favorites: {
path: '/favorites',
component: Timeline,
name: 'favorites',
props: (route: Route) => ({ rootTitle: t('memories', 'Favorites') }),
},
Videos: {
path: '/videos',
component: Timeline,
name: 'videos',
props: (route: Route) => ({ rootTitle: t('memories', 'Videos') }),
},
Albums: {
path: '/albums/:user?/:name?',
component: ClusterView,
name: 'albums',
props: (route: Route) => ({ rootTitle: t('memories', 'Albums') }),
},
Archive: {
path: '/archive',
component: Timeline,
name: 'archive',
props: (route: Route) => ({ rootTitle: t('memories', 'Archive') }),
},
ThisDay: {
path: '/thisday',
component: Timeline,
name: 'thisday',
props: (route: Route) => ({ rootTitle: t('memories', 'On this day') }),
},
Recognize: {
path: '/recognize/:user?/:name?',
component: ClusterView,
name: 'recognize',
props: (route: Route) => ({ rootTitle: t('memories', 'People') }),
},
FaceRecognition: {
path: '/facerecognition/:user?/:name?',
component: ClusterView,
name: 'facerecognition',
props: (route: Route) => ({ rootTitle: t('memories', 'People') }),
},
Places: {
path: '/places/:name*',
component: ClusterView,
name: 'places',
props: (route: Route) => ({ rootTitle: t('memories', 'Places') }),
},
Tags: {
path: '/tags/:name*',
component: ClusterView,
name: 'tags',
props: (route: Route) => ({ rootTitle: t('memories', 'Tags') }),
},
FolderShare: {
path: '/s/:token/:path*',
component: Timeline,
name: 'folder-share',
props: (route: Route) => ({ rootTitle: t('memories', 'Shared Folder') }),
},
AlbumShare: {
path: '/a/:token',
component: Timeline,
name: 'album-share',
props: (route: Route) => ({ rootTitle: t('memories', 'Shared Album') }),
},
Map: {
path: '/map',
component: SplitTimeline,
name: 'map',
props: (route: Route) => ({ rootTitle: t('memories', 'Map') }),
},
Explore: {
path: '/explore',
component: Explore,
name: 'explore',
props: (route: Route) => ({ rootTitle: t('memories', 'Explore') }),
},
NxSetup: {
path: '/nxsetup',
component: NativeXSetup,
name: 'nxsetup',
props: (route: Route) => ({ rootTitle: t('memories', 'Setup') }),
},
};
Vue.use(Router);
export default new Router({
mode: 'history',
// if index.php is in the url AND we got this far, then it's working:
// let's keep using index.php in the url
base: generateUrl('/apps/memories'),
linkActiveClass: 'active',
routes: Object.values(routes),
});
// Define global route checkers
// Injected through globals.d.ts
export type GlobalRouteCheckers = {
[key in `routeIs${RouteId}`]: boolean;
} & {
// Extra, special route checkers
routeIsPublic: boolean;
routeIsPeople: boolean;
routeIsRecognizeUnassigned: boolean;
routeIsCluster: boolean;
};
// Implement getters for route checkers
function defineRouteChecker(key: keyof GlobalRouteCheckers, condition: (route?: Route) => boolean) {
Object.defineProperty(Vue.prototype, key, {
get() {
return condition(this.$route);
},
});
}
// Build basic route checkers
for (const [key, value] of Object.entries(routes)) {
defineRouteChecker(`routeIs${<keyof typeof routes>key}`, (route) => route?.name === value.name);
}
// Extra route checkers
defineRouteChecker('routeIsPublic', (route) => route?.name?.endsWith('-share') ?? false);
defineRouteChecker('routeIsPeople', (route) =>
[routes.Recognize.name, routes.FaceRecognition.name].includes(route?.name ?? ''),
);
defineRouteChecker(
'routeIsRecognizeUnassigned',
(route) => route?.name === routes.Recognize.name && route!.params.name === c.FACE_NULL,
);
defineRouteChecker('routeIsCluster', (route) =>
[
routes.Albums.name,
routes.Recognize.name,
routes.FaceRecognition.name,
routes.Places.name,
routes.Tags.name,
].includes(route?.name ?? ''),
);