From fb59c42faee903627cbfde1437b6406bfdb2b11c Mon Sep 17 00:00:00 2001 From: Rishi Balakrishnan Date: Thu, 5 Nov 2026 20:27:38 -0500 Subject: [PATCH] fix(composer): match the event card to the design and preselect the cover crop Use the design's values: Azeret Mono lime step label, large input text, regular-weight labels, pill Remove and Back buttons, and the card's padding and spacing. Dates sit side by side on two lines in field-styled boxes; on web they open the browser's picker, and native tabs use the library's underline style. The cover field has a large centred camera button; web opens the file picker directly with a separate Remove. Covers crop at 2:1, and the web crop dialog can now start with the largest centred crop (opt-in, used only for event covers). --- .../com/composer/event/EventCoverPicker.tsx | 198 ++++++++++++++++++ .../com/composer/event/EventDateRange.tsx | 107 ++++++---- .../com/composer/event/EventDateRange.web.tsx | 53 +++-- src/view/com/composer/event/EventEditor.tsx | 74 ++++--- src/view/com/composer/event/EventFields.tsx | 42 ++++ .../event/__tests__/EventEditor.test.tsx | 13 +- .../com/composer/photos/EditImageDialog.tsx | 1 + .../composer/photos/EditImageDialog.web.tsx | 29 ++- 8 files changed, 423 insertions(+), 94 deletions(-) create mode 100644 src/view/com/composer/event/EventCoverPicker.tsx create mode 100644 src/view/com/composer/event/EventFields.tsx diff --git a/src/view/com/composer/event/EventCoverPicker.tsx b/src/view/com/composer/event/EventCoverPicker.tsx new file mode 100644 index 000000000..990389bc9 --- /dev/null +++ b/src/view/com/composer/event/EventCoverPicker.tsx @@ -0,0 +1,198 @@ +import {useState} from 'react' +import {Pressable, View} from 'react-native' +import {Image} from 'expo-image' +import {Trans, useLingui} from '@lingui/react/macro' + +import {IMAGE_SIZE_CONFIG_2K_1MB} from '#/lib/constants' +import { + useCameraPermission, + usePhotoLibraryPermission, +} from '#/lib/hooks/usePermissions' +import {compressIfNeeded} from '#/lib/media/manip' +import {openCamera, openCropper, openPicker} from '#/lib/media/picker' +import {type PickerImage} from '#/lib/media/picker.shared' +import {isCancelledError} from '#/lib/strings/errors' +import {logger} from '#/logger' +import { + type ComposerImage, + compressImage, + createComposerImage, +} from '#/state/gallery' +import {EditImageDialog} from '#/view/com/composer/photos/EditImageDialog' +import {atoms as a, useTheme} from '#/alf' +import {Button, ButtonText} from '#/components/Button' +import {useDialogControl} from '#/components/Dialog' +import {useSheetWrapper} from '#/components/Dialog/sheet-wrapper' +import {Camera_Stroke2_Corner0_Rounded as CameraIcon} from '#/components/icons/Camera' +import {StreamingLive_Stroke2_Corner0_Rounded as LibraryIcon} from '#/components/icons/StreamingLive' +import {Trash_Stroke2_Corner0_Rounded as TrashIcon} from '#/components/icons/Trash' +import * as Menu from '#/components/Menu' +import {IS_NATIVE, IS_WEB} from '#/env' + +const ASPECT = 2 + +export function EventCoverPicker({ + cover, + onChange, +}: { + cover?: string + onChange: (image: PickerImage | null) => void +}) { + const t = useTheme() + const {t: l} = useLingui() + const {requestCameraAccessIfNeeded} = useCameraPermission() + const {requestPhotoAccessIfNeeded} = usePhotoLibraryPermission() + const sheetWrapper = useSheetWrapper() + const editControl = useDialogControl() + const [rawImage, setRawImage] = useState() + + const onCamera = async () => { + if (!(await requestCameraAccessIfNeeded())) return + onChange( + await compressIfNeeded( + await openCamera({aspect: [ASPECT, 1]}), + IMAGE_SIZE_CONFIG_2K_1MB, + ), + ) + } + + const onLibrary = async () => { + if (!(await requestPhotoAccessIfNeeded())) return + const items = await sheetWrapper(openPicker()) + if (!items[0]) return + try { + if (IS_NATIVE) { + onChange( + await compressIfNeeded( + await openCropper({imageUri: items[0].path, aspectRatio: ASPECT}), + IMAGE_SIZE_CONFIG_2K_1MB, + ), + ) + } else { + setRawImage(await createComposerImage(items[0])) + editControl.open() + } + } catch (e) { + if (!isCancelledError(e)) { + logger.error('Failed to pick event cover', {error: e}) + } + } + } + + const field = ( + + {cover && ( + + )} + + + + + ) + + return ( + <> + {IS_WEB ? ( + + void onLibrary()}> + {field} + + {cover && ( + + )} + + ) : ( + + + {({props}) => ( + + {field} + + )} + + + + void onCamera()}> + + Upload from Camera + + + + void onLibrary()}> + + Upload from Library + + + + + {cover && ( + <> + + + onChange(null)}> + + Remove image + + + + + + )} + + + )} + + void compressImage(image, IMAGE_SIZE_CONFIG_2K_1MB).then(onChange) + } + aspectRatio={ASPECT} + preselectCrop + /> + + ) +} diff --git a/src/view/com/composer/event/EventDateRange.tsx b/src/view/com/composer/event/EventDateRange.tsx index 145fddaca..9c11fe876 100644 --- a/src/view/com/composer/event/EventDateRange.tsx +++ b/src/view/com/composer/event/EventDateRange.tsx @@ -6,13 +6,12 @@ import {Trans, useLingui} from '@lingui/react/macro' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' -import * as TextField from '#/components/forms/TextField' import {Text} from '#/components/Typography' -import { - type EventTimeField, - formatEventDraftDate, -} from '#/features/events/draft' +import {type EventTimeField} from '#/features/events/draft' import {type EventDateRangeProps} from './EventDateRange.types' +import {DateBox, FieldLabelText} from './EventFields' + +const FIELDS = ['startsAt', 'endsAt'] as const export function EventDateRange({ startsAt, @@ -26,6 +25,13 @@ export function EventDateRange({ const [field, setField] = useState('startsAt') const values = {startsAt, endsAt} const labels = {startsAt: l`Start date`, endsAt: l`End date`} + const short = (iso: string) => + i18n.date(new Date(iso), { + month: 'short', + day: 'numeric', + hour: 'numeric', + minute: '2-digit', + }) const open = (next: EventTimeField) => { Keyboard.dismiss() @@ -36,28 +42,19 @@ export function EventDateRange({ return ( <> - {(['startsAt', 'endsAt'] as const).map(key => ( + {FIELDS.map(key => ( - {labels[key]} + {labels[key]} open(key)} - style={[ - a.px_md, - a.py_sm, - a.rounded_sm, - a.border, - t.atoms.bg_contrast_50, - key === 'endsAt' && isEndInvalid - ? {borderColor: t.palette.negative_500} - : {borderColor: 'transparent'}, - ]}> - - {formatEventDraftDate(values[key], i18n.locale)} - + onPress={() => open(key)}> + ))} @@ -66,30 +63,50 @@ export function EventDateRange({ - - {(['startsAt', 'endsAt'] as const).map(key => ( - - ))} + + {FIELDS.map(key => { + const active = field === key + return ( + setField(key)} + style={[a.flex_1, a.align_center, a.pt_md]}> + + {key === 'startsAt' ? ( + Start: {short(startsAt)} + ) : ( + End: {short(endsAt)} + )} + + + + ) + })} >({}) const values = {startsAt, endsAt} const labels = {startsAt: l`Start date`, endsAt: l`End date`} return ( - {(['startsAt', 'endsAt'] as const).map(key => ( + {FIELDS.map(key => ( - {labels[key]} - + {labels[key]} + { + const input = inputs.current[key] + try { + input?.showPicker() + } catch { + input?.focus() + } + }}> + { + inputs.current[key] = el + }} type="datetime-local" data-testid={`${key}Input`} aria-label={labels[key]} + tabIndex={-1} value={toLocalInputValue(values[key])} onChange={e => { const iso = fromLocalInputValue(e.target.value) if (iso) onChange(key, iso) }} style={{ - flex: 1, - padding: '10px 14px', - font: 'inherit', - fontSize: a.text_md.fontSize, - color: t.atoms.text.color, - colorScheme: t.scheme, - background: 'transparent', + position: 'absolute', + left: 0, + bottom: 0, + width: '100%', + height: 0, + opacity: 0, border: 0, + padding: 0, + pointerEvents: 'none', }} /> - + ))} diff --git a/src/view/com/composer/event/EventEditor.tsx b/src/view/com/composer/event/EventEditor.tsx index be5e93a3e..1868f0187 100644 --- a/src/view/com/composer/event/EventEditor.tsx +++ b/src/view/com/composer/event/EventEditor.tsx @@ -6,10 +6,12 @@ import {countGraphemes} from 'unicode-segmenter/grapheme' import {getLinkMeta} from '#/lib/link-meta/link-meta' import {useAgent, useSession} from '#/state/session' +import {EventCoverPicker} from '#/view/com/composer/event/EventCoverPicker' import {EventDateRange} from '#/view/com/composer/event/EventDateRange' +import {FieldLabelText, INPUT_TEXT} from '#/view/com/composer/event/EventFields' import {type PostAction} from '#/view/com/composer/state/composer' -import {UserBanner} from '#/view/com/util/UserBanner' import {atoms as a, useTheme} from '#/alf' +import {DEFAULT_BRAND} from '#/alf/themes' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as TextField from '#/components/forms/TextField' import {CalendarDays_Stroke2_Corner0_Rounded as CalendarIcon} from '#/components/icons/CalendarDays' @@ -78,9 +80,9 @@ export function EventEditor({ testID="eventEditor" style={[ a.mt_lg, - a.p_md, - a.gap_md, + a.gap_xl, a.rounded_md, + {padding: 13}, a.border, t.atoms.border_contrast_low, t.atoms.bg_contrast_25, @@ -138,10 +140,11 @@ export function EventEditor({ testID="removeEventBtn" label={l`Remove event`} size="tiny" - variant="ghost" + variant="solid" color="secondary" + style={[t.atoms.bg, a.px_lg, {height: 28}]} onPress={remove}> - + Remove @@ -153,14 +156,14 @@ export function EventEditor({ )} {event.step === 'when' && } {event.step === 'cover' && ( - - + + Select the event image - - - + + + update( image ? { @@ -183,13 +186,27 @@ export function EventEditor({ {stepIndex >= 0 && ( - - - Step {stepIndex + 1} of {STEPS.length} - - + + + + + Step {stepIndex + 1} of {STEPS.length} + + + {stepIndex > 0 && ( @@ -210,6 +228,7 @@ export function EventEditor({ size="small" variant="solid" color="primary" + style={[a.px_2xl]} disabled={!canContinue} onPress={() => { if (isLastStep && !event.cover && cover) { @@ -246,9 +265,9 @@ function DetailsStep({ return ( - + Create your event - + EVENT_NAME_MAX_GRAPHEMES}> update({name})} + style={INPUT_TEXT} /> - + Describe your event (optional) - + EVENT_DESCRIPTION_MAX_GRAPHEMES}> update({description})} + style={INPUT_TEXT} multiline /> @@ -299,9 +320,9 @@ function WhenStep({ return ( - + Add location - + update({location})} + style={INPUT_TEXT} /> diff --git a/src/view/com/composer/event/EventFields.tsx b/src/view/com/composer/event/EventFields.tsx new file mode 100644 index 000000000..45d296f1f --- /dev/null +++ b/src/view/com/composer/event/EventFields.tsx @@ -0,0 +1,42 @@ +import {type ReactNode} from 'react' +import {View} from 'react-native' +import {useLingui} from '@lingui/react/macro' + +import {atoms as a, useTheme} from '#/alf' +import {Text} from '#/components/Typography' + +export const INPUT_TEXT = [a.text_lg, {lineHeight: 22}] + +export function FieldLabelText({children}: {children: ReactNode}) { + const t = useTheme() + return ( + + {children} + + ) +} + +export function DateBox({iso, isInvalid}: {iso: string; isInvalid?: boolean}) { + const t = useTheme() + const {i18n} = useLingui() + const date = new Date(iso) + return ( + + + {`${i18n.date(date, {dateStyle: 'medium'})},\n${i18n.date(date, { + timeStyle: 'short', + })}`} + + + ) +} diff --git a/src/view/com/composer/event/__tests__/EventEditor.test.tsx b/src/view/com/composer/event/__tests__/EventEditor.test.tsx index 89d1c15c5..8e419cfcc 100644 --- a/src/view/com/composer/event/__tests__/EventEditor.test.tsx +++ b/src/view/com/composer/event/__tests__/EventEditor.test.tsx @@ -41,6 +41,7 @@ jest.mock('#/alf', () => { }), } }) +jest.mock('#/alf/themes', () => ({DEFAULT_BRAND: {secondary: '#D2FC51'}})) jest.mock('#/components/Typography', () => { const {Text} = require('react-native') return {Text} @@ -210,15 +211,15 @@ jest.mock('#/features/events/components/EventEmbed', () => { } }) jest.mock('#/lib/link-meta/link-meta', () => ({getLinkMeta: jest.fn()})) -jest.mock('#/view/com/util/UserBanner', () => { +jest.mock('../EventCoverPicker', () => { const {Pressable, Text, View} = require('react-native') return { - UserBanner: ({ - banner, - onSelectNewBanner, + EventCoverPicker: ({ + cover: banner, + onChange: onSelectNewBanner, }: { - banner?: string - onSelectNewBanner: (image: unknown) => void + cover?: string + onChange: (image: unknown) => void }) => ( {banner ?? 'none'} diff --git a/src/view/com/composer/photos/EditImageDialog.tsx b/src/view/com/composer/photos/EditImageDialog.tsx index 9a0eb9084..f0459efb5 100644 --- a/src/view/com/composer/photos/EditImageDialog.tsx +++ b/src/view/com/composer/photos/EditImageDialog.tsx @@ -7,6 +7,7 @@ export type EditImageDialogProps = { onChange: (next: ComposerImage) => void aspectRatio?: number circularCrop?: boolean + preselectCrop?: boolean } export const EditImageDialog = ({}: EditImageDialogProps): React.ReactNode => { diff --git a/src/view/com/composer/photos/EditImageDialog.web.tsx b/src/view/com/composer/photos/EditImageDialog.web.tsx index 60f4fc1fa..e6abc7151 100644 --- a/src/view/com/composer/photos/EditImageDialog.web.tsx +++ b/src/view/com/composer/photos/EditImageDialog.web.tsx @@ -5,7 +5,11 @@ import {View} from 'react-native' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Trans} from '@lingui/react/macro' -import ReactCrop, {type PercentCrop} from 'react-image-crop' +import ReactCrop, { + centerCrop, + makeAspectCrop, + type PercentCrop, +} from 'react-image-crop' import { type ImageSource, @@ -33,6 +37,7 @@ function DialogInner({ onChange, circularCrop, aspectRatio, + preselectCrop, }: EditImageDialogProps) { const {_} = useLingui() const [pending, setPending] = useState(false) @@ -99,6 +104,7 @@ function DialogInner({ onChange={onChange} circularCrop={circularCrop} aspectRatio={aspectRatio} + preselectCrop={preselectCrop} /> )} @@ -111,6 +117,7 @@ function EditImageInner({ saveRef, circularCrop = false, aspectRatio, + preselectCrop, }: Required> & Omit & { saveRef: React.RefObject<{save: () => Promise} | null> @@ -121,7 +128,11 @@ function EditImageInner({ const source = image.source - const initialCrop = getInitialCrop(source, image.manips) + const initialCrop = + getInitialCrop(source, image.manips) ?? + (preselectCrop && aspectRatio + ? centeredCrop(source, aspectRatio) + : undefined) const [crop, setCrop] = useState(initialCrop) const onPressSubmit = useCallback(async () => { @@ -193,3 +204,17 @@ const getInitialCrop = ( } } } + +const centeredCrop = (source: ImageSource, aspect: number): PercentCrop => + centerCrop( + makeAspectCrop( + source.width / source.height > aspect + ? {unit: '%', height: 100} + : {unit: '%', width: 100}, + aspect, + source.width, + source.height, + ), + source.width, + source.height, + ) -- knotmirror 0.0.1