-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
324 additions
and
212 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export interface LayoutConfig<T extends Object> { | ||
path: string; | ||
params?: T; | ||
} | ||
|
||
export class FeatureRegistry<R> { | ||
private routes: Array<LayoutConfig<any>> = []; | ||
register<T>(layoutConfig: LayoutConfig<T>, handler: (params: T) => R) { | ||
this.routes.push(layoutConfig); | ||
} | ||
getRoutes() { | ||
return this.routes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { LayoutConfig } from "../FeatureRegistry"; | ||
import { Navigation } from "."; | ||
|
||
const navigation = new Navigation(); | ||
|
||
const service_propertyDetail_scoreAdd: LayoutConfig<{ | ||
propertyPreference: number; | ||
}> = { | ||
path: ":propertyPreference", | ||
}; | ||
|
||
navigation.push( | ||
service_propertyDetail_scoreAdd, | ||
{ | ||
propertyPreference: 123, | ||
}, | ||
{ root: "Hello" } | ||
); | ||
|
||
navigation.back(service_propertyDetail_scoreAdd, { | ||
propertyPreference: 123, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { LayoutConfig } from "../FeatureRegistry"; | ||
import { createBrowserHistory } from "history"; | ||
import * as pathToRegexp from "path-to-regexp"; | ||
|
||
export type LayoutParams<T> = T extends LayoutConfig<infer R> ? R : T; | ||
|
||
export class Navigation { | ||
public history = createBrowserHistory(); | ||
private root?: { | ||
title?: string; | ||
stackReference?: number; | ||
}; | ||
constructor() { | ||
this.history.listen((update: any) => { | ||
if (this.root?.stackReference === undefined) { | ||
return; | ||
} | ||
|
||
switch (update.action) { | ||
case "PUSH": | ||
this.root.stackReference--; | ||
break; | ||
case "POP": { | ||
this.root.stackReference++; | ||
break; | ||
} | ||
default: | ||
} | ||
}); | ||
} | ||
rootTitle(defaultTitle: string): string | undefined { | ||
return this.root?.title ?? defaultTitle; | ||
} | ||
push<T extends LayoutConfig<any>>( | ||
feature: T, | ||
params: LayoutParams<T>, | ||
options?: { | ||
root?: string; | ||
} | ||
) { | ||
const { _unsafe, ...safeParams } = params; | ||
|
||
const url = pathToRegexp.compile(feature.path)(safeParams); | ||
|
||
if (options?.root) { | ||
this.root = { | ||
title: options.root, | ||
stackReference: 1, | ||
}; | ||
} | ||
|
||
this.history.push(url, _unsafe); | ||
} | ||
goRoot<T extends LayoutConfig<any>>(feature: T, params: LayoutParams<T>) { | ||
if (this.root?.stackReference !== undefined) { | ||
this.history.go(this.root.stackReference); | ||
} else { | ||
const { _unsafe, ...safeParams } = params; | ||
const url = pathToRegexp.compile(feature.path)(safeParams); | ||
this.history.replace(url, _unsafe); | ||
} | ||
} | ||
back<T extends LayoutConfig<any>>(feature: T, params: LayoutParams<T>) { | ||
if (document.referrer.length && document.referrer === document.location.hostname) { | ||
this.history.goBack(); | ||
} else { | ||
const { _unsafe, ...safeParams } = params; | ||
const url = pathToRegexp.compile(feature.path)(safeParams); | ||
this.history.replace(url, _unsafe); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ObservableState } from "../_framework/ObservableState"; | ||
|
||
export interface AppShellContext { | ||
title: string; | ||
container: "none" | "main"; | ||
} | ||
|
||
export const appShellContext = new ObservableState<AppShellContext>({ | ||
title: "Loading", | ||
container: "none", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { EventHub } from "../_framework/EventHub"; | ||
|
||
const DISPLAY_SNACKBAR = "DISPLAY_SNACKBAR"; | ||
|
||
export interface DisplaySnackbarEventDetail { | ||
message: string; | ||
} | ||
|
||
interface AppShellEventMap { | ||
[DISPLAY_SNACKBAR]: DisplaySnackbarEventDetail; | ||
} | ||
|
||
export const appshellEventHub = new EventHub<AppShellEventMap>(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Navigation } from "../_framework/Navigation"; | ||
|
||
export const navigation = new Navigation(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,4 @@ | ||
type GuardedPromise = () => Promise<any>; | ||
import { FeatureRegistry } from "../_framework/FeatureRegistry"; | ||
|
||
class GuardError extends Error { | ||
public type: "UNAUTHENTICATED" | "ONBOARDING_REQUIRED"; | ||
constructor(message: string) { | ||
super(message); | ||
} | ||
} | ||
|
||
interface LazyLoad { | ||
(): Promise<any>; | ||
} | ||
|
||
export const routes = []; | ||
|
||
export function registerFeature(paths: Array<string>, lazyLoad: LazyLoad) { | ||
|
||
} | ||
|
||
export function guardOnboarded(guardedPromise: GuardedPromise) { | ||
// lookup | ||
Promise.resolve() | ||
.then(guardedPromise) | ||
.catch((e: GuardError) => {}); | ||
} | ||
// could update to react only here? | ||
export const registy = new FeatureRegistry<any>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface Authorization { | ||
authenticated: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface PersonalProfile { | ||
/** | ||
* Group which this profile belongs to | ||
*/ | ||
groupCode: number; | ||
onboardingCompleted: boolean; | ||
} |
Oops, something went wrong.