diff options
author | Eric Bailey <git@esb.lol> | 2024-09-17 13:55:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-17 13:55:19 -0500 |
commit | 2745cba3eae2e7f6dd803bbbb805599b2a99c834 (patch) | |
tree | 13fc992e9b06143000ecfe5fe7cd0e088618d010 /src/state | |
parent | 8f98d6b12f2bcf482207602580c5c8162c508152 (diff) | |
download | voidsky-2745cba3eae2e7f6dd803bbbb805599b2a99c834.tar.zst |
Pre-fill alt text with 10-million card post (#5389)
* Pre-fill alt text with 10-million card post (#5377) * Clean up type * Tweak alt copy * Add pt translation, fix typo --------- Co-authored-by: Calvin <clavin@users.noreply.github.com>
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/models/media/gallery.ts | 14 | ||||
-rw-r--r-- | src/state/models/media/image.ts | 23 | ||||
-rw-r--r-- | src/state/shell/composer/index.tsx | 2 |
3 files changed, 25 insertions, 14 deletions
diff --git a/src/state/models/media/gallery.ts b/src/state/models/media/gallery.ts index 9c8c13010..828905002 100644 --- a/src/state/models/media/gallery.ts +++ b/src/state/models/media/gallery.ts @@ -1,19 +1,20 @@ import {makeAutoObservable, runInAction} from 'mobx' -import {ImageModel} from './image' -import {Image as RNImage} from 'react-native-image-crop-picker' -import {openPicker} from 'lib/media/picker' + import {getImageDim} from 'lib/media/manip' +import {openPicker} from 'lib/media/picker' +import {ImageInitOptions, ImageModel} from './image' interface InitialImageUri { uri: string width: number height: number + altText?: string } export class GalleryModel { images: ImageModel[] = [] - constructor(uris?: {uri: string; width: number; height: number}[]) { + constructor(uris?: InitialImageUri[]) { makeAutoObservable(this) if (uris) { @@ -33,7 +34,7 @@ export class GalleryModel { return this.images.some(image => image.altText.trim() === '') } - *add(image_: Omit<RNImage, 'size'>) { + *add(image_: ImageInitOptions) { if (this.size >= 4) { return } @@ -59,7 +60,6 @@ export class GalleryModel { path: uri, height, width, - mime: 'image/jpeg', } runInAction(() => { @@ -100,10 +100,10 @@ export class GalleryModel { async addFromUris(uris: InitialImageUri[]) { for (const uriObj of uris) { this.add({ - mime: 'image/jpeg', height: uriObj.height, width: uriObj.width, path: uriObj.uri, + altText: uriObj.altText, }) } } diff --git a/src/state/models/media/image.ts b/src/state/models/media/image.ts index 5c547c148..55f636491 100644 --- a/src/state/models/media/image.ts +++ b/src/state/models/media/image.ts @@ -1,14 +1,15 @@ import {Image as RNImage} from 'react-native-image-crop-picker' -import {makeAutoObservable, runInAction} from 'mobx' -import {POST_IMG_MAX} from 'lib/constants' import * as ImageManipulator from 'expo-image-manipulator' -import {getDataUriSize} from 'lib/media/util' -import {openCropper} from 'lib/media/picker' import {ActionCrop, FlipType, SaveFormat} from 'expo-image-manipulator' +import {makeAutoObservable, runInAction} from 'mobx' import {Position} from 'react-avatar-editor' + +import {logger} from '#/logger' +import {POST_IMG_MAX} from 'lib/constants' +import {openCropper} from 'lib/media/picker' import {Dimensions} from 'lib/media/types' +import {getDataUriSize} from 'lib/media/util' import {isIOS} from 'platform/detection' -import {logger} from '#/logger' export interface ImageManipulationAttributes { aspectRatio?: '4:3' | '1:1' | '3:4' | 'None' @@ -19,6 +20,13 @@ export interface ImageManipulationAttributes { flipVertical?: boolean } +export interface ImageInitOptions { + path: string + width: number + height: number + altText?: string +} + const MAX_IMAGE_SIZE_IN_BYTES = 976560 export class ImageModel implements Omit<RNImage, 'size'> { @@ -41,12 +49,15 @@ export class ImageModel implements Omit<RNImage, 'size'> { } prevAttributes: ImageManipulationAttributes = {} - constructor(image: Omit<RNImage, 'size'>) { + constructor(image: ImageInitOptions) { makeAutoObservable(this) this.path = image.path this.width = image.width this.height = image.height + if (image.altText !== undefined) { + this.setAltText(image.altText) + } } setRatio(aspectRatio: ImageManipulationAttributes['aspectRatio']) { diff --git a/src/state/shell/composer/index.tsx b/src/state/shell/composer/index.tsx index 612388ff8..6755ec9a6 100644 --- a/src/state/shell/composer/index.tsx +++ b/src/state/shell/composer/index.tsx @@ -36,7 +36,7 @@ export interface ComposerOpts { mention?: string // handle of user to mention openEmojiPicker?: (pos: DOMRect | undefined) => void text?: string - imageUris?: {uri: string; width: number; height: number}[] + imageUris?: {uri: string; width: number; height: number; altText?: string}[] } type StateContext = ComposerOpts | undefined |