Load previous state in alt text modal (#546)
parent
c8e51a7d48
commit
7a2c21026d
|
@ -1,9 +1,13 @@
|
||||||
import {RootStoreModel} from 'state/index'
|
import {RootStoreModel} from 'state/index'
|
||||||
|
|
||||||
export async function openAltTextModal(store: RootStoreModel): Promise<string> {
|
export async function openAltTextModal(
|
||||||
|
store: RootStoreModel,
|
||||||
|
prevAltText: string,
|
||||||
|
): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
store.shell.openModal({
|
store.shell.openModal({
|
||||||
name: 'alt-text-image',
|
name: 'alt-text-image',
|
||||||
|
prevAltText,
|
||||||
onAltTextSet: (altText?: string) => {
|
onAltTextSet: (altText?: string) => {
|
||||||
if (altText) {
|
if (altText) {
|
||||||
resolve(altText)
|
resolve(altText)
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class ImageModel implements RNImage {
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
size: number
|
size: number
|
||||||
altText?: string = undefined
|
altText = ''
|
||||||
cropped?: RNImage = undefined
|
cropped?: RNImage = undefined
|
||||||
compressed?: RNImage = undefined
|
compressed?: RNImage = undefined
|
||||||
scaledWidth: number = POST_IMG_MAX.width
|
scaledWidth: number = POST_IMG_MAX.width
|
||||||
|
@ -45,7 +45,7 @@ export class ImageModel implements RNImage {
|
||||||
|
|
||||||
async setAltText() {
|
async setAltText() {
|
||||||
try {
|
try {
|
||||||
const altText = await openAltTextModal(this.rootStore)
|
const altText = await openAltTextModal(this.rootStore, this.altText)
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.altText = altText
|
this.altText = altText
|
||||||
|
|
|
@ -43,6 +43,7 @@ export interface CropImageModal {
|
||||||
|
|
||||||
export interface AltTextImageModal {
|
export interface AltTextImageModal {
|
||||||
name: 'alt-text-image'
|
name: 'alt-text-image'
|
||||||
|
prevAltText: string
|
||||||
onAltTextSet: (altText?: string) => void
|
onAltTextSet: (altText?: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,14 +15,15 @@ import {isDesktopWeb} from 'platform/detection'
|
||||||
export const snapPoints = ['80%']
|
export const snapPoints = ['80%']
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
prevAltText: string
|
||||||
onAltTextSet: (altText?: string | undefined) => void
|
onAltTextSet: (altText?: string | undefined) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Component({onAltTextSet}: Props) {
|
export function Component({prevAltText, onAltTextSet}: Props) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const [altText, setAltText] = useState('')
|
const [altText, setAltText] = useState(prevAltText)
|
||||||
|
|
||||||
const onPressSave = useCallback(() => {
|
const onPressSave = useCallback(() => {
|
||||||
onAltTextSet(altText)
|
onAltTextSet(altText)
|
||||||
|
|
Loading…
Reference in New Issue