about summary refs log tree commit diff
path: root/src/state/models/media/gallery.ts
diff options
context:
space:
mode:
authorMary <148872143+mary-ext@users.noreply.github.com>2024-09-24 23:14:15 +0700
committerGitHub <noreply@github.com>2024-09-25 01:14:15 +0900
commit8ea89469ef1a7988a7b3d05716da55e9da680c35 (patch)
treee7bc8f6412ae400a2127833ec4abc823b96df2cd /src/state/models/media/gallery.ts
parentdbe1df7ac7de58e02dc8f236347b0856cfb570ef (diff)
downloadvoidsky-8ea89469ef1a7988a7b3d05716da55e9da680c35.tar.zst
MobX removal take 2 (#5381)
* mobx removal take 2

* Actually rm mobx

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/state/models/media/gallery.ts')
-rw-r--r--src/state/models/media/gallery.ts110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/state/models/media/gallery.ts b/src/state/models/media/gallery.ts
deleted file mode 100644
index 828905002..000000000
--- a/src/state/models/media/gallery.ts
+++ /dev/null
@@ -1,110 +0,0 @@
-import {makeAutoObservable, runInAction} from 'mobx'
-
-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?: InitialImageUri[]) {
-    makeAutoObservable(this)
-
-    if (uris) {
-      this.addFromUris(uris)
-    }
-  }
-
-  get isEmpty() {
-    return this.size === 0
-  }
-
-  get size() {
-    return this.images.length
-  }
-
-  get needsAltText() {
-    return this.images.some(image => image.altText.trim() === '')
-  }
-
-  *add(image_: ImageInitOptions) {
-    if (this.size >= 4) {
-      return
-    }
-
-    // Temporarily enforce uniqueness but can eventually also use index
-    if (!this.images.some(i => i.path === image_.path)) {
-      const image = new ImageModel(image_)
-
-      // Initial resize
-      image.manipulate({})
-      this.images.push(image)
-    }
-  }
-
-  async paste(uri: string) {
-    if (this.size >= 4) {
-      return
-    }
-
-    const {width, height} = await getImageDim(uri)
-
-    const image = {
-      path: uri,
-      height,
-      width,
-    }
-
-    runInAction(() => {
-      this.add(image)
-    })
-  }
-
-  setAltText(image: ImageModel, altText: string) {
-    image.setAltText(altText)
-  }
-
-  crop(image: ImageModel) {
-    image.crop()
-  }
-
-  remove(image: ImageModel) {
-    const index = this.images.findIndex(image_ => image_.path === image.path)
-    this.images.splice(index, 1)
-  }
-
-  async previous(image: ImageModel) {
-    image.previous()
-  }
-
-  async pick() {
-    const images = await openPicker({
-      selectionLimit: 4 - this.size,
-      allowsMultipleSelection: true,
-    })
-
-    return await Promise.all(
-      images.map(image => {
-        this.add(image)
-      }),
-    )
-  }
-
-  async addFromUris(uris: InitialImageUri[]) {
-    for (const uriObj of uris) {
-      this.add({
-        height: uriObj.height,
-        width: uriObj.width,
-        path: uriObj.uri,
-        altText: uriObj.altText,
-      })
-    }
-  }
-}