Composer update (react-query refactor) (#1899)
* Move composer state to a context * Rework composer to use RQ --------- Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
parent
c687172de9
commit
0a26e78dcb
32 changed files with 269 additions and 239 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {RootStoreModel} from 'state/index'
|
||||
import {ImageModel} from './image'
|
||||
import {Image as RNImage} from 'react-native-image-crop-picker'
|
||||
import {openPicker} from 'lib/media/picker'
|
||||
|
|
@ -8,10 +7,8 @@ import {getImageDim} from 'lib/media/manip'
|
|||
export class GalleryModel {
|
||||
images: ImageModel[] = []
|
||||
|
||||
constructor(public rootStore: RootStoreModel) {
|
||||
makeAutoObservable(this, {
|
||||
rootStore: false,
|
||||
})
|
||||
constructor() {
|
||||
makeAutoObservable(this)
|
||||
}
|
||||
|
||||
get isEmpty() {
|
||||
|
|
@ -33,7 +30,7 @@ export class GalleryModel {
|
|||
|
||||
// Temporarily enforce uniqueness but can eventually also use index
|
||||
if (!this.images.some(i => i.path === image_.path)) {
|
||||
const image = new ImageModel(this.rootStore, image_)
|
||||
const image = new ImageModel(image_)
|
||||
|
||||
// Initial resize
|
||||
image.manipulate({})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import {Image as RNImage} from 'react-native-image-crop-picker'
|
||||
import {RootStoreModel} from 'state/index'
|
||||
import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {POST_IMG_MAX} from 'lib/constants'
|
||||
import * as ImageManipulator from 'expo-image-manipulator'
|
||||
|
|
@ -42,10 +41,8 @@ export class ImageModel implements Omit<RNImage, 'size'> {
|
|||
}
|
||||
prevAttributes: ImageManipulationAttributes = {}
|
||||
|
||||
constructor(public rootStore: RootStoreModel, image: Omit<RNImage, 'size'>) {
|
||||
makeAutoObservable(this, {
|
||||
rootStore: false,
|
||||
})
|
||||
constructor(image: Omit<RNImage, 'size'>) {
|
||||
makeAutoObservable(this)
|
||||
|
||||
this.path = image.path
|
||||
this.width = image.width
|
||||
|
|
@ -178,7 +175,7 @@ export class ImageModel implements Omit<RNImage, 'size'> {
|
|||
height: this.height,
|
||||
})
|
||||
|
||||
const cropped = await openCropper(this.rootStore, {
|
||||
const cropped = await openCropper({
|
||||
mediaType: 'photo',
|
||||
path: this.path,
|
||||
freeStyleCropEnabled: true,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {AppBskyEmbedRecord, AppBskyActorDefs} from '@atproto/api'
|
||||
import {AppBskyActorDefs} from '@atproto/api'
|
||||
import {RootStoreModel} from '../root-store'
|
||||
import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {
|
||||
|
|
@ -37,41 +37,9 @@ export class ImagesLightbox implements LightboxModel {
|
|||
}
|
||||
}
|
||||
|
||||
export interface ComposerOptsPostRef {
|
||||
uri: string
|
||||
cid: string
|
||||
text: string
|
||||
author: {
|
||||
handle: string
|
||||
displayName?: string
|
||||
avatar?: string
|
||||
}
|
||||
}
|
||||
export interface ComposerOptsQuote {
|
||||
uri: string
|
||||
cid: string
|
||||
text: string
|
||||
indexedAt: string
|
||||
author: {
|
||||
did: string
|
||||
handle: string
|
||||
displayName?: string
|
||||
avatar?: string
|
||||
}
|
||||
embeds?: AppBskyEmbedRecord.ViewRecord['embeds']
|
||||
}
|
||||
export interface ComposerOpts {
|
||||
replyTo?: ComposerOptsPostRef
|
||||
onPost?: () => void
|
||||
quote?: ComposerOptsQuote
|
||||
mention?: string // handle of user to mention
|
||||
}
|
||||
|
||||
export class ShellUiModel {
|
||||
isLightboxActive = false
|
||||
activeLightbox: ProfileImageLightbox | ImagesLightbox | null = null
|
||||
isComposerActive = false
|
||||
composerOpts: ComposerOpts | undefined
|
||||
tickEveryMinute = Date.now()
|
||||
|
||||
constructor(public rootStore: RootStoreModel) {
|
||||
|
|
@ -92,10 +60,6 @@ export class ShellUiModel {
|
|||
this.closeLightbox()
|
||||
return true
|
||||
}
|
||||
if (this.isComposerActive) {
|
||||
this.closeComposer()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -106,9 +70,6 @@ export class ShellUiModel {
|
|||
if (this.isLightboxActive) {
|
||||
this.closeLightbox()
|
||||
}
|
||||
if (this.isComposerActive) {
|
||||
this.closeComposer()
|
||||
}
|
||||
}
|
||||
|
||||
openLightbox(lightbox: ProfileImageLightbox | ImagesLightbox) {
|
||||
|
|
@ -122,17 +83,6 @@ export class ShellUiModel {
|
|||
this.activeLightbox = null
|
||||
}
|
||||
|
||||
openComposer(opts: ComposerOpts) {
|
||||
this.rootStore.emitNavigation()
|
||||
this.isComposerActive = true
|
||||
this.composerOpts = opts
|
||||
}
|
||||
|
||||
closeComposer() {
|
||||
this.isComposerActive = false
|
||||
this.composerOpts = undefined
|
||||
}
|
||||
|
||||
setupClock() {
|
||||
setInterval(() => {
|
||||
runInAction(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue