Bump api@0.0.5 and use the type guard helpers
parent
f6a0e634d7
commit
6885fb2b41
|
@ -13,7 +13,7 @@
|
||||||
"postinstall": "patch-package"
|
"postinstall": "patch-package"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@atproto/api": "^0.0.4",
|
"@atproto/api": "^0.0.5",
|
||||||
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.1.1",
|
"@fortawesome/fontawesome-svg-core": "^6.1.1",
|
||||||
"@fortawesome/free-regular-svg-icons": "^6.1.1",
|
"@fortawesome/free-regular-svg-icons": "^6.1.1",
|
||||||
|
|
|
@ -4,11 +4,6 @@ import {AtUri} from '../../third-party/uri'
|
||||||
import {RootStoreModel} from './root-store'
|
import {RootStoreModel} from './root-store'
|
||||||
import * as apilib from '../lib/api'
|
import * as apilib from '../lib/api'
|
||||||
|
|
||||||
interface UnknownPost {
|
|
||||||
$type: string
|
|
||||||
[k: string]: unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
function* reactKeyGenerator(): Generator<string> {
|
function* reactKeyGenerator(): Generator<string> {
|
||||||
let counter = 0
|
let counter = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -16,17 +11,6 @@ function* reactKeyGenerator(): Generator<string> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isThreadViewPost(
|
|
||||||
v: GetPostThread.ThreadViewPost | GetPostThread.NotFoundPost | UnknownPost,
|
|
||||||
): v is GetPostThread.ThreadViewPost {
|
|
||||||
return v.$type === 'app.bksy.feed.getPostThread#threadViewPost'
|
|
||||||
}
|
|
||||||
function isNotFoundPost(
|
|
||||||
v: GetPostThread.ThreadViewPost | GetPostThread.NotFoundPost | UnknownPost,
|
|
||||||
): v is GetPostThread.NotFoundPost {
|
|
||||||
return v.$type === 'app.bsky.feed.getPostThread#notFoundPost'
|
|
||||||
}
|
|
||||||
|
|
||||||
export class PostThreadViewPostModel {
|
export class PostThreadViewPostModel {
|
||||||
// ui state
|
// ui state
|
||||||
_reactKey: string = ''
|
_reactKey: string = ''
|
||||||
|
@ -58,7 +42,7 @@ export class PostThreadViewPostModel {
|
||||||
) {
|
) {
|
||||||
// parents
|
// parents
|
||||||
if (includeParent && v.parent) {
|
if (includeParent && v.parent) {
|
||||||
if (isThreadViewPost(v.parent)) {
|
if (GetPostThread.isThreadViewPost(v.parent)) {
|
||||||
const parentModel = new PostThreadViewPostModel(
|
const parentModel = new PostThreadViewPostModel(
|
||||||
this.rootStore,
|
this.rootStore,
|
||||||
keyGen.next().value,
|
keyGen.next().value,
|
||||||
|
@ -69,7 +53,7 @@ export class PostThreadViewPostModel {
|
||||||
parentModel.assignTreeModels(keyGen, v.parent, true, false)
|
parentModel.assignTreeModels(keyGen, v.parent, true, false)
|
||||||
}
|
}
|
||||||
this.parent = parentModel
|
this.parent = parentModel
|
||||||
} else if (isNotFoundPost(v.parent)) {
|
} else if (GetPostThread.isNotFoundPost(v.parent)) {
|
||||||
this.parent = v.parent
|
this.parent = v.parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +61,7 @@ export class PostThreadViewPostModel {
|
||||||
if (includeChildren && v.replies) {
|
if (includeChildren && v.replies) {
|
||||||
const replies = []
|
const replies = []
|
||||||
for (const item of v.replies) {
|
for (const item of v.replies) {
|
||||||
if (isThreadViewPost(item)) {
|
if (GetPostThread.isThreadViewPost(item)) {
|
||||||
const itemModel = new PostThreadViewPostModel(
|
const itemModel = new PostThreadViewPostModel(
|
||||||
this.rootStore,
|
this.rootStore,
|
||||||
keyGen.next().value,
|
keyGen.next().value,
|
||||||
|
@ -88,7 +72,7 @@ export class PostThreadViewPostModel {
|
||||||
itemModel.assignTreeModels(keyGen, item, false, true)
|
itemModel.assignTreeModels(keyGen, item, false, true)
|
||||||
}
|
}
|
||||||
replies.push(itemModel)
|
replies.push(itemModel)
|
||||||
} else if (isNotFoundPost(item)) {
|
} else if (GetPostThread.isNotFoundPost(item)) {
|
||||||
replies.push(item)
|
replies.push(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {ImageStyle, StyleSheet, StyleProp, View, ViewStyle} from 'react-native'
|
import {StyleSheet, StyleProp, View, ViewStyle} from 'react-native'
|
||||||
import {AppBskyEmbedImages, AppBskyEmbedExternal} from '@atproto/api'
|
import {AppBskyEmbedImages, AppBskyEmbedExternal} from '@atproto/api'
|
||||||
import {Link} from '../util/Link'
|
import {Link} from '../util/Link'
|
||||||
import {Text} from './text/Text'
|
import {Text} from './text/Text'
|
||||||
|
@ -23,39 +23,38 @@ export function PostEmbeds({
|
||||||
}) {
|
}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
if (embed?.$type === 'app.bsky.embed.images#presented') {
|
if (AppBskyEmbedImages.isPresented(embed)) {
|
||||||
const imgEmbed = embed as AppBskyEmbedImages.Presented
|
if (embed.images.length > 0) {
|
||||||
if (imgEmbed.images.length > 0) {
|
const uris = embed.images.map(img => img.fullsize)
|
||||||
const uris = imgEmbed.images.map(img => img.fullsize)
|
|
||||||
const openLightbox = (index: number) => {
|
const openLightbox = (index: number) => {
|
||||||
store.shell.openLightbox(new ImagesLightbox(uris, index))
|
store.shell.openLightbox(new ImagesLightbox(uris, index))
|
||||||
}
|
}
|
||||||
if (imgEmbed.images.length === 4) {
|
if (embed.images.length === 4) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.imagesContainer}>
|
<View style={styles.imagesContainer}>
|
||||||
<ImageLayoutGrid
|
<ImageLayoutGrid
|
||||||
type="four"
|
type="four"
|
||||||
uris={imgEmbed.images.map(img => img.thumb)}
|
uris={embed.images.map(img => img.thumb)}
|
||||||
onPress={openLightbox}
|
onPress={openLightbox}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
} else if (imgEmbed.images.length === 3) {
|
} else if (embed.images.length === 3) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.imagesContainer}>
|
<View style={styles.imagesContainer}>
|
||||||
<ImageLayoutGrid
|
<ImageLayoutGrid
|
||||||
type="three"
|
type="three"
|
||||||
uris={imgEmbed.images.map(img => img.thumb)}
|
uris={embed.images.map(img => img.thumb)}
|
||||||
onPress={openLightbox}
|
onPress={openLightbox}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
} else if (imgEmbed.images.length === 2) {
|
} else if (embed.images.length === 2) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.imagesContainer}>
|
<View style={styles.imagesContainer}>
|
||||||
<ImageLayoutGrid
|
<ImageLayoutGrid
|
||||||
type="two"
|
type="two"
|
||||||
uris={imgEmbed.images.map(img => img.thumb)}
|
uris={embed.images.map(img => img.thumb)}
|
||||||
onPress={openLightbox}
|
onPress={openLightbox}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
@ -64,7 +63,7 @@ export function PostEmbeds({
|
||||||
return (
|
return (
|
||||||
<View style={styles.imagesContainer}>
|
<View style={styles.imagesContainer}>
|
||||||
<AutoSizedImage
|
<AutoSizedImage
|
||||||
uri={imgEmbed.images[0].thumb}
|
uri={embed.images[0].thumb}
|
||||||
onPress={() => openLightbox(0)}
|
onPress={() => openLightbox(0)}
|
||||||
containerStyle={{borderRadius: 4}}
|
containerStyle={{borderRadius: 4}}
|
||||||
/>
|
/>
|
||||||
|
@ -73,9 +72,8 @@ export function PostEmbeds({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (embed?.$type === 'app.bsky.embed.external#presented') {
|
if (AppBskyEmbedExternal.isPresented(embed)) {
|
||||||
const externalEmbed = embed as AppBskyEmbedExternal.Presented
|
const link = embed.external
|
||||||
const link = externalEmbed.external
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
style={[styles.extOuter, pal.view, pal.border, style]}
|
style={[styles.extOuter, pal.view, pal.border, style]}
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
jsonpointer "^5.0.0"
|
jsonpointer "^5.0.0"
|
||||||
leven "^3.1.0"
|
leven "^3.1.0"
|
||||||
|
|
||||||
"@atproto/api@^0.0.4":
|
"@atproto/api@^0.0.5":
|
||||||
version "0.0.4"
|
version "0.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.0.4.tgz#f2cb17f234ea1360ebe719be244cabc28724d992"
|
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.0.5.tgz#6d850b1ebba57a0ce9a880c59299331e3324304e"
|
||||||
integrity sha512-lSaww8M2R7pRi1p1CUoidiYRNgIcUrEbhk4SZ7dGYhp9M2BKXYr9PzwWDZmB/tmFLdRPzAslmg9QWKbc0mqeUQ==
|
integrity sha512-DLI8GL2rQATh30d4VsiUyKL9j45q8o95tATJT6OnuBSf5YwD7kY5239DUjVSFEP08SAnM71ACl1O7EsoitsOXQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@atproto/xrpc" "*"
|
"@atproto/xrpc" "*"
|
||||||
typed-emitter "^2.1.0"
|
typed-emitter "^2.1.0"
|
||||||
|
|
Loading…
Reference in New Issue