-
Notifications
You must be signed in to change notification settings - Fork 474
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
5 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
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
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,24 @@ | ||
import { makeAutoObservable } from 'mobx'; | ||
import { sendAnalytics } from '../utils'; | ||
|
||
export enum Route { | ||
EDITOR = 'editor', | ||
LOGIN = 'login', | ||
} | ||
|
||
export class RouteManager { | ||
private currentRoute: Route = Route.EDITOR; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
|
||
get route() { | ||
return this.currentRoute; | ||
} | ||
|
||
set route(newRoute: Route) { | ||
this.route = newRoute; | ||
sendAnalytics('navigate', { route: newRoute }); | ||
} | ||
} |
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 { RouteManager } from '@/lib/routes'; | ||
import { createContext, ReactNode, useContext } from 'react'; | ||
|
||
const RouteContext = createContext(new RouteManager()); | ||
export const useRouteManager = () => useContext(RouteContext); | ||
|
||
const RouteProvider = ({ children }: { children: ReactNode }) => { | ||
return <RouteContext.Provider value={useRouteManager()}>{children}</RouteContext.Provider>; | ||
}; | ||
|
||
export default RouteProvider; |
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,23 @@ | ||
import { Route } from '@/lib/routes'; | ||
import { observer } from 'mobx-react-lite'; | ||
import ProjectEditor from './project'; | ||
import RouteProvider, { useRouteManager } from './Provider'; | ||
|
||
const Routes = observer(() => { | ||
const routeManager = useRouteManager(); | ||
|
||
function renderRoutes() { | ||
switch (routeManager.route) { | ||
case Route.EDITOR: | ||
return <ProjectEditor />; | ||
case Route.LOGIN: | ||
return <div>Login</div>; | ||
default: | ||
return <div>404: Unknown route</div>; | ||
} | ||
} | ||
|
||
return <RouteProvider>{renderRoutes()}</RouteProvider>; | ||
}); | ||
|
||
export default 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,5 @@ | ||
const Login = () => { | ||
return <>Login</>; | ||
}; | ||
|
||
export default Login; |