Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… UI polishes and bugfixes (#3543)
  • Loading branch information
rickyrombo authored Jun 8, 2023
1 parent cc1bc46 commit 8e54ff7
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 103 deletions.
11 changes: 3 additions & 8 deletions packages/common/src/store/pages/chat/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,10 @@ const slice = createSlice({
delete state.optimisticReactions[messageId]

// Ensure the message exists
chatMessagesAdapter.addOne(state.messages[chatId], {
message_id: messageId,
reactions: [],
message: '',
sender_user_id: '',
created_at: '',
hasTail: false
})
const existingMessage = getMessage(state.messages[chatId], messageId)
if (!existingMessage) {
return
}
const existingReactions = existingMessage?.reactions ?? []
const filteredReactions = existingReactions.filter(
(r) => r.user_id !== reaction.user_id
Expand Down
13 changes: 12 additions & 1 deletion packages/mobile/src/screens/chat-screen/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,14 @@ export const ChatScreen = () => {
flatListInnerHeight.current = event.nativeEvent.layout.height
}, [])

// Scroll to the bottom if the user sends a message
const handleMessageSent = useCallback(() => {
// Set a timeout to ensure the full render happened and we got the final height
setTimeout(() => {
flatListRef.current?.scrollToOffset({ offset: 0, animated: true })
}, 0)
}, [flatListRef])

return (
<Screen
url={url}
Expand Down Expand Up @@ -621,7 +629,10 @@ export const ChatScreen = () => {
pointerEvents={'box-none'}
>
<View style={styles.whiteBackground} />
<ChatTextInput chatId={chatId} />
<ChatTextInput
chatId={chatId}
onMessageSent={handleMessageSent}
/>
</View>
) : null}
</KeyboardAvoidingView>
Expand Down
9 changes: 7 additions & 2 deletions packages/mobile/src/screens/chat-screen/ChatTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ const useStyles = makeStyles(({ spacing, palette, typography }) => ({

type ChatTextInputProps = {
chatId: string
onMessageSent: () => void
}

export const ChatTextInput = ({ chatId }: ChatTextInputProps) => {
export const ChatTextInput = ({
chatId,
onMessageSent
}: ChatTextInputProps) => {
const styles = useStyles()
const dispatch = useDispatch()
const { primary, primaryDark2 } = useThemeColors()
Expand All @@ -66,8 +70,9 @@ export const ChatTextInput = ({ chatId }: ChatTextInputProps) => {
if (chatId && inputMessage) {
dispatch(sendMessage({ chatId, message: inputMessage }))
setInputMessage('')
onMessageSent()
}
}, [inputMessage, chatId, dispatch])
}, [inputMessage, chatId, dispatch, onMessageSent])

const renderIcon = () => (
<Pressable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
box-sizing: border-box;
}

.root:has(:checked)::before {
/* Use the .checked class since Firefox doesn't support :has() */
.root.checked::before {
background: var(--white);
border: 6px solid var(--secondary);
}

.root:has(:disabled)::before {
/* Use the .disabled class since Firefox doesn't support :has() */
.root.disabled::before {
background: var(--neutral-light-7);
}
12 changes: 11 additions & 1 deletion packages/stems/src/components/RadioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const RadioButton = (props: RadioButtonProps) => {
onChange,
name: nameProp,
checked: checkedProp,
disabled,
...other
} = props

Expand All @@ -46,13 +47,22 @@ export const RadioButton = (props: RadioButtonProps) => {
)

return (
<div className={cn(styles.root, className)}>
<div
className={cn(
styles.root,
// Firefox doesn't support :has() so we're using classes here
{ [styles.disabled]: disabled },
{ [styles.checked]: checked },
className
)}
>
<input
className={cn(styles.input, inputClassName)}
name={name}
checked={checked}
type='radio'
onChange={handleChange}
disabled={disabled}
{...other}
/>
</div>
Expand Down
15 changes: 8 additions & 7 deletions packages/web/src/components/data-entry/InputV2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
border-color: var(--neutral-light-6);
}

.root:has(input:focus) {
.root.focused {
border-color: var(--secondary);
}

.root.warning,
.root.warning:has(input:focus) {
.root.warning.focused {
border-color: var(--accent-orange);
}

.root.error,
.root.error:has(input:focus) {
.root.error.focused {
border-color: var(--accent-red);
}

.root.error:hover,
.root.error:hover:has(input:focus) {
.root.error:hover.focused {
border-color: var(--accent-red-dark-1);
}

.root:has(input:disabled) {
.root.disabled {
background-color: var(--neutral-light-9);
border-color: var(--neutral-light-8);
}
Expand Down Expand Up @@ -86,7 +86,8 @@
}

/** Add the "*" to required fields, but have it disappear when elevated **/
.elevatedPlaceholderLabel:has(input:required:not(:focus))
.required:not(.focused)
.elevatedPlaceholderLabel
.placeholder:not(.hasValue)::after {
content: ' *';
}
Expand All @@ -105,7 +106,7 @@
}

/** Move the elevated placeholder to the top left if focused or has text **/
.elevatedPlaceholderLabel:has(input:focus) .placeholder,
.focused .elevatedPlaceholderLabel .placeholder,
.placeholder.hasValue {
transform: translate(0px, calc(-1em - var(--gap)));
font-size: var(--font-xs);
Expand Down
27 changes: 26 additions & 1 deletion packages/web/src/components/data-entry/InputV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentPropsWithoutRef, MutableRefObject, RefCallback } from 'react'
import cn from 'classnames'

import styles from './InputV2.module.css'
import { useFocusState } from './useFocusState'

export enum InputV2Size {
SMALL,
Expand Down Expand Up @@ -42,6 +43,9 @@ export const InputV2 = (props: InputV2Props) => {
warning: warningProp,
error,
inputClassName,
disabled,
onFocus: onFocusProp,
onBlur: onBlurProp,
...other
} = props

Expand All @@ -59,20 +63,41 @@ export const InputV2 = (props: InputV2Props) => {
[styles.error]: error
}

/**
* Since Firefox doesn't support the :has() pseudo selector,
* manually track the focused state and use classes for focus, required, and disabled
*/
const [isFocused, handleFocus, handleBlur] = useFocusState(
onFocusProp,
onBlurProp
)

const input = (
<input
onFocus={handleFocus}
onBlur={handleBlur}
ref={inputRef}
placeholder={!elevatePlaceholder ? placeholder : undefined}
required={required}
className={inputClassName}
value={value}
maxLength={maxLength}
disabled={disabled}
{...other}
/>
)

return (
<div className={cn(styles.root, style, className)}>
<div
className={cn(
styles.root,
{ [styles.focused]: isFocused },
{ [styles.disabled]: disabled },
{ [styles.required]: required },
style,
className
)}
>
{elevatePlaceholder ? (
<label className={styles.elevatedPlaceholderLabel}>
<span
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/components/data-entry/TextAreaV2.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
.root:hover > textarea {
border-color: var(--neutral-light-6);
}
.root:has(textarea:focus) {
/* Using .focus class since Firefox doesn't support :has() */
.root.focus {
border-color: var(--secondary);
}
.root.error {
Expand Down
Loading

0 comments on commit 8e54ff7

Please sign in to comment.