diff --git a/src/view/routes.ts b/src/view/routes.ts index a1f8ab28..c4929707 100644 --- a/src/view/routes.ts +++ b/src/view/routes.ts @@ -21,53 +21,70 @@ export type ScreenParams = { visible: boolean scrollElRef?: MutableRefObject | undefined> } -export type Route = [React.FC, IconProp, RegExp] +export type Route = [React.FC, string, IconProp, RegExp] export type MatchResult = { Com: React.FC + defaultTitle: string icon: IconProp params: Record + isNotFound?: boolean } const r = (pattern: string) => new RegExp('^' + pattern + '([?]|$)', 'i') export const routes: Route[] = [ - [Home, 'house', r('/')], - [Contacts, ['far', 'circle-user'], r('/contacts')], - [Search, 'magnifying-glass', r('/search')], - [Notifications, 'bell', r('/notifications')], - [Settings, 'bell', r('/settings')], - [Profile, ['far', 'user'], r('/profile/(?[^/]+)')], - [ProfileFollowers, 'users', r('/profile/(?[^/]+)/followers')], - [ProfileFollows, 'users', r('/profile/(?[^/]+)/follows')], - [ProfileMembers, 'users', r('/profile/(?[^/]+)/members')], + [Home, 'Home', 'house', r('/')], + [Contacts, 'Contacts', ['far', 'circle-user'], r('/contacts')], + [Search, 'Search', 'magnifying-glass', r('/search')], + [Notifications, 'Notifications', 'bell', r('/notifications')], + [Settings, 'Settings', 'bell', r('/settings')], + [Profile, 'User', ['far', 'user'], r('/profile/(?[^/]+)')], + [ + ProfileFollowers, + 'Followers', + 'users', + r('/profile/(?[^/]+)/followers'), + ], + [ProfileFollows, 'Follows', 'users', r('/profile/(?[^/]+)/follows')], + [ProfileMembers, 'Members', 'users', r('/profile/(?[^/]+)/members')], [ PostThread, + 'Post', ['far', 'message'], r('/profile/(?[^/]+)/post/(?[^/]+)'), ], [ PostUpvotedBy, + 'Upvoted by', 'heart', r('/profile/(?[^/]+)/post/(?[^/]+)/upvoted-by'), ], [ PostDownvotedBy, + 'Downvoted by', 'heart', r('/profile/(?[^/]+)/post/(?[^/]+)/downvoted-by'), ], [ PostRepostedBy, + 'Reposted by', 'retweet', r('/profile/(?[^/]+)/post/(?[^/]+)/reposted-by'), ], ] export function match(url: string): MatchResult { - for (const [Com, icon, pattern] of routes) { + for (const [Com, defaultTitle, icon, pattern] of routes) { const res = pattern.exec(url) if (res) { // TODO: query params - return {Com, icon, params: res.groups || {}} + return {Com, defaultTitle, icon, params: res.groups || {}} } } - return {Com: NotFound, icon: 'magnifying-glass', params: {}} + return { + Com: NotFound, + defaultTitle: 'Not found', + icon: 'magnifying-glass', + params: {}, + isNotFound: true, + } }