connect components to state

This commit is contained in:
Pavel Prichodko 2023-02-28 15:01:04 +01:00
parent 0ee881e2d8
commit 32a8fed0be
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
5 changed files with 51 additions and 56 deletions

View File

@ -33,7 +33,9 @@
"@tamagui/react-native-media-driver": "1.0.15",
"@tamagui/shorthands": "1.0.15",
"@tamagui/theme-base": "1.0.15",
"tamagui": "1.0.15"
"tamagui": "1.0.15",
"expo-blur": "~12.0.1",
"zustand": "^4.3.4"
},
"devDependencies": {
"@storybook/addon-essentials": "7.0.0-beta.21",

View File

@ -16,15 +16,15 @@ import { Button } from '../button'
import { IconButton } from '../icon-button'
import { Image } from '../image'
import { Input } from '../input'
import { useChatDispatch, useChatState } from '../provider'
import { Reply } from '../reply'
interface Props {
isBlurred: boolean
reply: boolean
blur: boolean
}
const Composer = (props: Props) => {
const { isBlurred, reply } = props
const { blur } = props
const [isFocused, setIsFocused] = useState(false)
const [text, setText] = useState('')
@ -37,7 +37,10 @@ const Composer = (props: Props) => {
isDisabled: isImageUploadDisabled,
} = useImageUpload()
const iconButtonBlurred = isBlurred && !isFocused && imagesData.length === 0
const iconButtonBlurred = blur && !isFocused && imagesData.length === 0
const chatState = useChatState()
const chatDispatch = useChatDispatch()
return (
<BlurView
@ -62,15 +65,13 @@ const Composer = (props: Props) => {
elevation: 10,
}}
>
{reply && (
{chatState?.type === 'reply' && (
<Stack paddingLeft={4} paddingBottom={4}>
<Reply
type="text"
name="Alisher"
src="https://images.unsplash.com/photo-1524638431109-93d95c968f03?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=500&ixid=MnwxfDB8MXxyYW5kb218MHx8Z2lybHx8fHx8fDE2NzM4ODQ0NzU&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=500"
onClose={() => {
console.log('close')
}}
onClose={() => chatDispatch({ type: 'cancel' })}
/>
</Stack>
)}
@ -80,7 +81,7 @@ const Composer = (props: Props) => {
placeholder="Type something..."
px={0}
borderWidth={0}
blurred={isBlurred}
blurred={blur}
onBlur={() => setIsFocused(false)}
onFocus={() => setIsFocused(true)}
onChangeText={setText}

View File

@ -23,12 +23,12 @@ interface Props {
reactions: ReactionsType
onOpenChange: (open: boolean) => void
onReplyPress: VoidFunction
// onEditPress: VoidFunction
onEditPress: VoidFunction
// onDeletePress: VoidFunction
}
export const Actions = (props: Props) => {
const { reactions, onOpenChange, onReplyPress } = props
const { reactions, onOpenChange, onReplyPress, onEditPress } = props
useEffect(() => {
return () => onOpenChange(false)
@ -70,11 +70,7 @@ export const Actions = (props: Props) => {
/>
{/* EDIT */}
{/* <IconButton
variant="outline"
icon={<EditIcon />}
onPress={onEditPress}
/> */}
<IconButton variant="outline" icon={<EditIcon />} onPress={onEditPress} />
{/* DELETE */}
{/* <IconButton
@ -90,12 +86,12 @@ export const Actions = (props: Props) => {
<DropdownMenu.Item
icon={<EditIcon />}
label="Edit message"
onSelect={() => console.log('edit')}
onSelect={onEditPress}
/>
<DropdownMenu.Item
icon={<ReplyIcon />}
label="Reply"
onSelect={() => console.log('reply')}
onSelect={onReplyPress}
/>
<DropdownMenu.Item
icon={<CopyIcon />}

View File

@ -6,6 +6,7 @@ import { Stack, Unspaced, XStack, YStack } from 'tamagui'
import { Author } from '../author/author'
import { Avatar } from '../avatar'
import { Image } from '../image'
import { useChatDispatch } from '../provider'
import { Reply } from '../reply'
import { Paragraph } from '../typography'
import { Actions } from './components/actions'
@ -30,6 +31,8 @@ const Message = (props: Props) => {
const active = actionsOpen || hovered
// <Sheet press="long">
const dispatch = useChatDispatch()
return (
<YStack
position="relative"
@ -48,9 +51,8 @@ const Message = (props: Props) => {
<Actions
reactions={reactions}
onOpenChange={setActionsOpen}
onReplyPress={() => {
console.log('reply')
}}
onReplyPress={() => dispatch({ type: 'reply', messageId: '1' })}
onEditPress={() => dispatch({ type: 'edit', messageId: '1' })}
/>
</Unspaced>
)}

View File

@ -7,33 +7,32 @@ import { Avatar } from '../avatar'
import { Button } from '../button'
import { Image } from '../image'
import { Heading, Paragraph } from '../typography'
import { COMMUNITIES } from './mock-data'
import { CHANNEL_GROUPS } from './mock-data'
import type { CommunityProps } from './mock-data'
import type { GetProps } from '@tamagui/core'
import type { ReactNode } from 'react'
type BaseProps = GetProps<typeof Stack>
import type { ChannelGroup } from './mock-data'
type Props = {
community: {
name: string
description: string
membersCount: number
selectedChannel?: string
communities?: CommunityProps[]
onChannelPress: (channelId: string, channelIcon?: ReactNode) => void
} & BaseProps
imageUrl: string
}
channels?: ChannelGroup[]
selectedChannelId?: string
onChannelPress: (channelId: string) => void
}
const Sidebar = (props: Props) => {
const {
name,
description,
membersCount,
communities = COMMUNITIES,
selectedChannel,
community,
channels = CHANNEL_GROUPS,
selectedChannelId,
onChannelPress,
} = props
const { name, description, membersCount, imageUrl } = community
return (
<Stack
backgroundColor="$background"
@ -42,11 +41,7 @@ const Sidebar = (props: Props) => {
height="100%"
overflow="scroll"
>
<Image
src="https://images.unsplash.com/photo-1574786527860-f2e274867c91?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1764&q=80"
width="full"
aspectRatio={2.6}
/>
<Image src={imageUrl} width="full" aspectRatio={2.6} />
<Stack
paddingBottom={16}
marginTop={-16}
@ -72,17 +67,16 @@ const Sidebar = (props: Props) => {
<Button>Join community</Button>
</Stack>
{communities.map(community => (
{channels.map(group => (
<Accordion
key={community.id}
// This is just for the demo
initialExpanded={community.id === 'welcome'}
title={community.title}
numberOfNewMessages={community.numberOfNewMessages}
key={group.id}
initialExpanded={group.id === 'welcome'}
title={group.title}
numberOfNewMessages={group.unreadCount}
>
{community.channels.map((channel, index) => {
const isLastChannelOfTheList =
index === community.channels.length - 1
{group.channels.map((channel, index) => {
const isLastChannelOfTheList = index === group.channels.length - 1
return (
<AccordionItem
key={channel.id}
@ -90,8 +84,8 @@ const Sidebar = (props: Props) => {
title={channel.title}
channelStatus={channel.channelStatus}
numberOfMessages={channel.numberOfMessages}
isSelected={selectedChannel === channel.id}
onPress={() => onChannelPress(channel.id, channel.icon)}
isSelected={selectedChannelId === channel.id}
onPress={() => onChannelPress(channel.id)}
mb={isLastChannelOfTheList ? 8 : 0}
/>
)