Skip to content

Commit 0335eba

Browse files
lethemanhlethemanh
authored andcommitted
fix: Make mobile UI friendly 🐛
1 parent d819626 commit 0335eba

23 files changed

Lines changed: 274 additions & 56 deletions

packages/cozy-search/src/components/Assistant/AssistantContainer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const AssistantContainer = () => {
2828
styles['assistant-container']
2929
)}
3030
>
31-
<Sidebar className="u-w-5 u-pb-1" />
31+
<Sidebar className="u-w-5 u-pb-0-t u-pb-1" />
3232

33-
<PrettyScrollbar className="u-flex-auto u-flex u-flex-column u-pb-1 u-ov-hidden">
33+
<PrettyScrollbar className="u-flex-auto u-flex u-flex-column u-pb-0-t u-pb-1 u-ov-hidden">
3434
{isOpenSearchConversation &&
3535
flag('cozy.search-conversation.enabled') ? (
3636
<SearchConversation />

packages/cozy-search/src/components/Assistant/AssistantSelection.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu'
77
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
88
import Chips from 'cozy-ui/transpiled/react/Chips'
99
import Icon from 'cozy-ui/transpiled/react/Icon'
10+
import DropdownIcon from 'cozy-ui/transpiled/react/Icons/Dropdown'
1011
import PlusIcon from 'cozy-ui/transpiled/react/Icons/Plus'
1112
import Typography from 'cozy-ui/transpiled/react/Typography'
13+
import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'
1214

1315
import styles from './styles.styl'
1416
import { useAssistant } from '../AssistantProvider'
@@ -19,6 +21,7 @@ import AssistantSelectionItem from './AssistantSelectionItem'
1921

2022
const AssistantSelection = ({ className, disabled }) => {
2123
const { t } = useI18n()
24+
const { isMobile } = useBreakpoints()
2225
const buttonRef = useRef(null)
2326
const [open, setOpen] = useState(false)
2427
const {
@@ -62,7 +65,13 @@ const AssistantSelection = ({ className, disabled }) => {
6265
assistant={selectedAssistant}
6366
/>
6467
}
65-
label={selectedAssistant.name}
68+
label={
69+
!isMobile ? (
70+
selectedAssistant.name
71+
) : (
72+
<Icon className={styles['dropdown-icon']} icon={DropdownIcon} />
73+
)
74+
}
6675
clickable
6776
onClick={handleClick}
6877
disabled={disabled}

packages/cozy-search/src/components/Assistant/AssistantSelectionItem.jsx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import React from 'react'
1+
import cx from 'classnames'
2+
import React, { useMemo } from 'react'
23

34
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
5+
import Badge from 'cozy-ui/transpiled/react/Badge'
46
import Icon from 'cozy-ui/transpiled/react/Icon'
57
import IconButton from 'cozy-ui/transpiled/react/IconButton'
68
import CheckIcon from 'cozy-ui/transpiled/react/Icons/Check'
79
import PenIcon from 'cozy-ui/transpiled/react/Icons/Pen'
810
import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash'
911
import Typography from 'cozy-ui/transpiled/react/Typography'
12+
import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'
1013

1114
import styles from './styles.styl'
1215
import AssistantAvatar from '../Assistant/AssistantAvatar'
@@ -21,6 +24,8 @@ const AssistantSelectionItem = ({
2124
setIsOpenEditAssistant,
2225
disableActions = false
2326
}) => {
27+
const { isMobile } = useBreakpoints()
28+
2429
const handleSelect = assistant => {
2530
onSelect(assistant)
2631
onClose()
@@ -40,33 +45,67 @@ const AssistantSelectionItem = ({
4045
e.stopPropagation()
4146
}
4247

48+
const isSelected = useMemo(
49+
() => selectedAssistant?.id === assistant.id,
50+
[selectedAssistant?.id, assistant.id]
51+
)
52+
4353
return (
4454
<ActionsMenuItem
4555
onClick={() => handleSelect(assistant)}
4656
className={styles['menu-item']}
4757
>
4858
<div className="u-flex u-flex-items-center">
49-
<AssistantAvatar assistant={assistant} />
59+
{isMobile && isSelected ? (
60+
<Badge
61+
badgeContent={
62+
<Icon
63+
icon={CheckIcon}
64+
size={10}
65+
className={styles['selected-item--mobile']}
66+
/>
67+
}
68+
variant="standard"
69+
size="small"
70+
anchorOrigin={{
71+
vertical: 'bottom',
72+
horizontal: 'right'
73+
}}
74+
overlap="circular"
75+
>
76+
<AssistantAvatar assistant={assistant} />
77+
</Badge>
78+
) : (
79+
<AssistantAvatar assistant={assistant} />
80+
)}
5081
<Typography variant="body1">{assistant.name}</Typography>
5182
</div>
5283
<div className="u-flex u-flex-items-center u-flex-justify-between">
53-
{selectedAssistant?.id === assistant.id && (
84+
{isSelected && !isMobile && (
5485
<Icon icon={CheckIcon} className="u-success" />
5586
)}
5687
{!disableActions && (
5788
<>
5889
<IconButton
5990
aria-label="Edit assistant"
6091
size="small"
61-
className={styles['menu-item-icon-button']}
92+
className={cx({
93+
[styles['menu-item-icon-button']]:
94+
!isMobile || (!isSelected && isMobile),
95+
'u-db': isSelected && isMobile
96+
})}
6297
onClick={handleEdit}
6398
>
6499
<Icon icon={PenIcon} color="var(--primaryColor)" />
65100
</IconButton>
66101
<IconButton
67102
aria-label="Delete assistant"
68103
size="small"
69-
className={styles['menu-item-icon-button']}
104+
className={cx({
105+
[styles['menu-item-icon-button']]:
106+
!isMobile || (!isSelected && isMobile),
107+
'u-db': isSelected && isMobile
108+
})}
70109
onClick={handleDelete}
71110
>
72111
<Icon icon={TrashIcon} className="u-error" />

packages/cozy-search/src/components/Assistant/styles.styl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@
4343
display none !important
4444

4545
.create-icon
46-
margin-right 8px
46+
margin-right 0.5rem
47+
48+
.dropdown-icon
49+
margin-top 0.25rem
50+
51+
.selected-item--mobile
52+
padding 1px
53+
border-radius 100%
54+
color var(--white)
55+
background-color var(--malachite)

packages/cozy-search/src/components/Conversations/ConversationBar.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComposerPrimitive } from '@assistant-ui/react'
2+
import cx from 'classnames'
23
import React, { useRef } from 'react'
34
import { useI18n } from 'twake-i18n'
45

@@ -19,7 +20,8 @@ const ConversationBar = ({
1920
isRunning,
2021
onKeyDown,
2122
onSend,
22-
onCancel
23+
onCancel,
24+
...props
2325
}) => {
2426
const { t } = useI18n()
2527
const { isMobile } = useBreakpoints()
@@ -51,7 +53,10 @@ const ConversationBar = ({
5153
return (
5254
<div className="u-w-100 u-maw-7 u-mh-auto">
5355
<SearchBar
54-
className={styles['conversationBar']}
56+
{...props}
57+
className={cx(styles['conversationBar'], {
58+
[styles['conversationBar--mobile']]: isMobile
59+
})}
5560
icon={null}
5661
size="auto"
5762
placeholder={t('assistant.search.placeholder')}

packages/cozy-search/src/components/Conversations/ConversationComposer.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useThread,
55
useComposer
66
} from '@assistant-ui/react'
7+
import cx from 'classnames'
78
import React, { useCallback } from 'react'
89

910
import flag from 'cozy-flags'
@@ -49,8 +50,14 @@ const ConversationComposer = () => {
4950
)
5051

5152
return (
52-
<ComposerPrimitive.Root className="u-w-100 u-maw-7 u-mh-auto">
53+
<ComposerPrimitive.Root
54+
className={cx('u-w-100 u-maw-7 u-mh-auto', {
55+
'u-card u-bxz u-elevation-1': isMobile
56+
})}
57+
>
5358
<ConversationBar
59+
elevation={isMobile ? 0 : 1}
60+
disabledHover={!!isMobile}
5461
value={value}
5562
isEmpty={isEmpty}
5663
isRunning={isRunning}

packages/cozy-search/src/components/Conversations/styles.styl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
+gt-mobile()
99
max-height 178px
1010

11+
&--mobile
12+
border 0
13+
background-color transparent !important
14+
border-color transparent !important
15+
16+
1117
.conversationBar-input
1218
max-height 80px
1319

packages/cozy-search/src/components/CreateAssistantSteps/ProviderSelectionStep.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
import cx from 'classnames'
12
import React from 'react'
23
import { useI18n } from 'twake-i18n'
34

45
import Alert from 'cozy-ui/transpiled/react/Alert'
56
import Typography from 'cozy-ui/transpiled/react/Typography'
7+
import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'
68

79
import Provider from './Provider'
810
import providers from './providers.json'
911
import styles from './styles.styl'
1012

1113
const ProviderSelectionStep = ({ selectedProvider, onSelect }) => {
1214
const { t } = useI18n()
15+
const { isMobile } = useBreakpoints()
1316
return (
14-
<div className={`u-flex u-flex-column ${styles.ModelSelectionStep}`}>
17+
<div className={cx('u-flex u-flex-column', styles.ModelSelectionStep)}>
1518
<Typography variant="body1" className="u-mb-1 u-c-text-secondary">
1619
{t('assistant_create.steps.provider_selection.description')}
1720
</Typography>
18-
<div className={styles['grid-container']}>
21+
<div
22+
className={cx(styles['grid-container'], {
23+
[styles['grid-container--mobile']]: isMobile
24+
})}
25+
>
1926
{providers.map(provider => (
2027
<Provider
2128
key={provider.id}

packages/cozy-search/src/components/CreateAssistantSteps/styles.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
grid-template-columns 1fr 1fr
1818
gap 16px
1919

20+
&--mobile
21+
grid-template-columns 1fr
22+
2023
& .model-card
2124
border-radius 16px
2225
border 1px solid #E5E5E5

0 commit comments

Comments
 (0)