From a3d2db96457d87b7c9a874d699e51dd5f98750c1 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 26 Jan 2023 12:53:46 -0600 Subject: Get MVP of web app running --- src/view/shell/web/index.tsx | 140 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/view/shell/web/index.tsx (limited to 'src/view/shell/web/index.tsx') diff --git a/src/view/shell/web/index.tsx b/src/view/shell/web/index.tsx new file mode 100644 index 000000000..9032eb884 --- /dev/null +++ b/src/view/shell/web/index.tsx @@ -0,0 +1,140 @@ +import React from 'react' +import {observer} from 'mobx-react-lite' +import {View, StyleSheet, Text} from 'react-native' +import {useStores} from '../../../state' +import {match, MatchResult} from '../../routes' +// import {DesktopLeftColumn} from './left-column' +// import {DesktopRightColumn} from './right-column' +import {Login} from '../../screens/Login' +import {ErrorBoundary} from '../../com/util/ErrorBoundary' +import {usePalette} from '../../lib/hooks/usePalette' +import {s} from '../../lib/styles' + +export const WebShell: React.FC = observer(() => { + const pal = usePalette('default') + const store = useStores() + const screenRenderDesc = constructScreenRenderDesc(store.nav) + + if (!store.session.hasSession) { + return ( + + + + + + ) + } + + return ( + + + {screenRenderDesc.screens.map(({Com, navIdx, params, key, current}) => ( + + + + + + ))} + + + ) + // TODO + // + // + // store.shell.closeComposer()} + // winHeight={winDim.height} + // replyTo={store.shell.composerOpts?.replyTo} + // imagesOpen={store.shell.composerOpts?.imagesOpen} + // onPost={store.shell.composerOpts?.onPost} + // /> + // return ( + // + // {store.session.hasSession ? ( + // <> + // + // + // Hello, world! (Logged in) + // {children} + // + // + // + // ) : ( + // + // Hello, world! (Logged out) + // {children} + // + // )} + // + // ) +}) + +/** + * This method produces the information needed by the shell to + * render the current screens with screen-caching behaviors. + */ +type ScreenRenderDesc = MatchResult & { + key: string + navIdx: string + current: boolean + previous: boolean + isNewTab: boolean +} +function constructScreenRenderDesc(nav: NavigationModel): { + icon: IconProp + hasNewTab: boolean + screens: ScreenRenderDesc[] +} { + let hasNewTab = false + let icon: IconProp = 'magnifying-glass' + let screens: ScreenRenderDesc[] = [] + for (const tab of nav.tabs) { + const tabScreens = [ + ...tab.getBackList(5), + Object.assign({}, tab.current, {index: tab.index}), + ] + const parsedTabScreens = tabScreens.map(screen => { + const isCurrent = nav.isCurrentScreen(tab.id, screen.index) + const isPrevious = nav.isCurrentScreen(tab.id, screen.index + 1) + const matchRes = match(screen.url) + if (isCurrent) { + icon = matchRes.icon + } + hasNewTab = hasNewTab || tab.isNewTab + return Object.assign(matchRes, { + key: `t${tab.id}-s${screen.index}`, + navIdx: `${tab.id}-${screen.id}`, + current: isCurrent, + previous: isPrevious, + isNewTab: tab.isNewTab, + }) as ScreenRenderDesc + }) + screens = screens.concat(parsedTabScreens) + } + return { + icon, + hasNewTab, + screens, + } +} + +const styles = StyleSheet.create({ + outerContainer: { + height: '100%', + }, + innerContainer: { + marginLeft: 'auto', + marginRight: 'auto', + width: '600px', + height: '100%', + }, + visible: { + display: 'flex', + }, + hidden: { + display: 'none', + }, +}) -- cgit 1.4.1