simplify web app & connect to provider

This commit is contained in:
Pavel Prichodko 2023-02-28 14:59:47 +01:00
parent 838180c9d5
commit 5b802b1d15
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
3 changed files with 63 additions and 103 deletions

View File

@ -11,7 +11,6 @@
"@status-im/components": "*", "@status-im/components": "*",
"@status-im/icons": "*", "@status-im/icons": "*",
"@tamagui/core": "1.0.15", "@tamagui/core": "1.0.15",
"expo-blur": "~12.0.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-native-web": "^0.18.6" "react-native-web": "^0.18.6"

View File

@ -1,4 +1,4 @@
import { cloneElement, useRef, useState } from 'react' import { useMemo, useRef, useState } from 'react'
import { import {
Composer, Composer,
@ -6,120 +6,80 @@ import {
Sidebar, Sidebar,
SidebarMembers, SidebarMembers,
Topbar, Topbar,
useAppDispatch,
useAppState,
} from '@status-im/components' } from '@status-im/components'
import { useBlur } from '@status-im/components/hooks' import { useBlur } from '@status-im/components/hooks'
import { COMMUNITIES } from '@status-im/components/src/sidebar/mock-data' import { CHANNEL_GROUPS } from '@status-im/components/src/sidebar/mock-data'
import { Stack, styled, TamaguiProvider } from '@tamagui/core'
import { AnimatePresence } from 'tamagui'
import tamaguiConfig from '../tamagui.config' const COMMUNITY = {
name: 'Rarible',
import type { ReactElement, ReactNode } from 'react' description:
'Multichain community-centric NFT marketplace. Create, buy and sell your NFTs.',
type ThemeVars = 'light' | 'dark' membersCount: 123,
imageUrl:
const AnimatableDrawer = styled(Stack, { 'https://images.unsplash.com/photo-1574786527860-f2e274867c91?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1764&q=80',
variants: {
fromRight: {
true: {
x: 500,
width: 0,
},
},
fromLeft: {
true: {
x: 500,
width: 250,
},
},
},
})
function App() {
const [theme, setTheme] = useState<ThemeVars>('light')
const [showMembers, setShowMembers] = useState(false)
const [selectedChannel, setSelectedChannel] = useState<string>('welcome')
const refMessagesContainer = useRef<HTMLDivElement>(null)
// TODO - this is a hack to get the icon to show up in the topbar when a channel is selected on mount
const [icon, setIcon] = useState<ReactNode>(
cloneElement(COMMUNITIES[0].channels[0].icon as ReactElement, {
hasBackground: false,
})
)
const onChannelPress = (id: string, icon?: ReactNode) => {
setSelectedChannel(id)
setIcon(icon)
} }
function App() {
const [showMembers, setShowMembers] = useState(false)
const containerRef = useRef<HTMLDivElement>(null)
const { shouldBlurTop, shouldBlurBottom } = useBlur({ const { shouldBlurTop, shouldBlurBottom } = useBlur({
ref: refMessagesContainer, ref: containerRef,
}) })
const appState = useAppState()
const appDispatch = useAppDispatch()
// TODO: This should change based on the URL
const selectedChannel = useMemo(() => {
for (const { channels } of CHANNEL_GROUPS) {
for (const channel of channels) {
if (channel.id === appState.channelId) {
return channel
}
}
}
}, [appState.channelId])
return ( return (
<TamaguiProvider config={tamaguiConfig} defaultTheme={'light'}>
<div id="app"> <div id="app">
<div id="sidebar" style={{ zIndex: 200 }}> <div id="sidebar" style={{ zIndex: 200 }}>
<Sidebar <Sidebar
name="Rarible" community={COMMUNITY}
description="Multichain community-centric NFT marketplace. Create, buy and sell your NFTs." selectedChannelId={appState.channelId}
membersCount={123} onChannelPress={channelId =>
onChannelPress={onChannelPress} appDispatch({ type: 'set-channel', channelId })
selectedChannel={selectedChannel} }
/> />
</div> </div>
<main id="main"> <main id="main">
<Topbar <Topbar
isBlurred={shouldBlurTop} blur={shouldBlurTop}
backgroundColor="$blurBackground" channel={selectedChannel}
icon={
icon &&
cloneElement(icon as ReactElement, { hasBackground: false })
}
title={`#${selectedChannel}`}
description="Share random funny stuff with the community. Play nice."
membersVisisble={showMembers} membersVisisble={showMembers}
onMembersPress={() => setShowMembers(show => !show)} onMembersPress={() => setShowMembers(show => !show)}
/> />
<div <div id="content" ref={containerRef}>
id="content"
ref={refMessagesContainer}
style={{ position: 'relative' }}
>
<div id="messages"> <div id="messages">
<Messages /> <Messages />
</div> </div>
<div id="composer"> <div id="composer">
<Composer isBlurred={shouldBlurBottom} reply={false} /> <Composer blur={shouldBlurBottom} />
</div> </div>
</div> </div>
</main> </main>
<AnimatePresence enterVariant="fromRight" exitVariant="fromLeft">
{showMembers && ( {showMembers && (
<AnimatableDrawer <div id="members">
id="members"
key="members"
animation={[
'fast',
{
opacity: {
overshootClamping: true,
},
},
]}
enterStyle={{ opacity: 0 }}
exitStyle={{ opacity: 0 }}
opacity={1}
>
<SidebarMembers /> <SidebarMembers />
</AnimatableDrawer>
)}
</AnimatePresence>
</div> </div>
</TamaguiProvider> )}
</div>
) )
} }

View File

@ -40,6 +40,7 @@ body,
} }
#content { #content {
position: relative;
overflow: auto; overflow: auto;
padding: 40px 0px 0px 0px; padding: 40px 0px 0px 0px;
height: 100vh; height: 100vh;