Do less work (#1953)
parent
9c8a1b8a31
commit
c858b58307
|
@ -1,4 +1,4 @@
|
||||||
import {useEffect, useState, useCallback, useRef} from 'react'
|
import {useEffect, useState, useMemo, useCallback, useRef} from 'react'
|
||||||
import EventEmitter from 'eventemitter3'
|
import EventEmitter from 'eventemitter3'
|
||||||
import {AppBskyFeedDefs} from '@atproto/api'
|
import {AppBskyFeedDefs} from '@atproto/api'
|
||||||
import {Shadow} from './types'
|
import {Shadow} from './types'
|
||||||
|
@ -55,9 +55,11 @@ export function usePostShadow(
|
||||||
firstRun.current = false
|
firstRun.current = false
|
||||||
}, [post])
|
}, [post])
|
||||||
|
|
||||||
return state.ts > ifAfterTS
|
return useMemo(() => {
|
||||||
? mergeShadow(post, state.value)
|
return state.ts > ifAfterTS
|
||||||
: {...post, isShadowed: true}
|
? mergeShadow(post, state.value)
|
||||||
|
: {...post, isShadowed: true}
|
||||||
|
}, [post, state, ifAfterTS])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updatePostShadow(uri: string, value: Partial<PostShadow>) {
|
export function updatePostShadow(uri: string, value: Partial<PostShadow>) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {useEffect, useState, useCallback, useRef} from 'react'
|
import {useEffect, useState, useMemo, useCallback, useRef} from 'react'
|
||||||
import EventEmitter from 'eventemitter3'
|
import EventEmitter from 'eventemitter3'
|
||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs} from '@atproto/api'
|
||||||
import {Shadow} from './types'
|
import {Shadow} from './types'
|
||||||
|
@ -56,9 +56,11 @@ export function useProfileShadow(
|
||||||
firstRun.current = false
|
firstRun.current = false
|
||||||
}, [profile])
|
}, [profile])
|
||||||
|
|
||||||
return state.ts > ifAfterTS
|
return useMemo(() => {
|
||||||
? mergeShadow(profile, state.value)
|
return state.ts > ifAfterTS
|
||||||
: {...profile, isShadowed: true}
|
? mergeShadow(profile, state.value)
|
||||||
|
: {...profile, isShadowed: true}
|
||||||
|
}, [profile, state, ifAfterTS])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateProfileShadow(
|
export function updateProfileShadow(
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
import {useEffect, useState} from 'react'
|
import {useMemo} from 'react'
|
||||||
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query'
|
||||||
import {
|
import {LabelPreference, BskyFeedViewPreference} from '@atproto/api'
|
||||||
LabelPreference,
|
|
||||||
BskyFeedViewPreference,
|
|
||||||
ModerationOpts,
|
|
||||||
} from '@atproto/api'
|
|
||||||
import isEqual from 'lodash.isequal'
|
|
||||||
|
|
||||||
import {track} from '#/lib/analytics/analytics'
|
import {track} from '#/lib/analytics/analytics'
|
||||||
import {getAge} from '#/lib/strings/time'
|
import {getAge} from '#/lib/strings/time'
|
||||||
|
@ -91,21 +86,16 @@ export function usePreferencesQuery() {
|
||||||
|
|
||||||
export function useModerationOpts() {
|
export function useModerationOpts() {
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const [opts, setOpts] = useState<ModerationOpts | undefined>()
|
|
||||||
const prefs = usePreferencesQuery()
|
const prefs = usePreferencesQuery()
|
||||||
useEffect(() => {
|
const opts = useMemo(() => {
|
||||||
if (!prefs.data) {
|
if (!prefs.data) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// only update this hook when the moderation options change
|
return getModerationOpts({
|
||||||
const newOpts = getModerationOpts({
|
|
||||||
userDid: currentAccount?.did || '',
|
userDid: currentAccount?.did || '',
|
||||||
preferences: prefs.data,
|
preferences: prefs.data,
|
||||||
})
|
})
|
||||||
if (!isEqual(opts, newOpts)) {
|
}, [currentAccount?.did, prefs.data])
|
||||||
setOpts(newOpts)
|
|
||||||
}
|
|
||||||
}, [prefs.data, currentAccount, opts, setOpts])
|
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, {useMemo} from 'react'
|
import React, {memo, useMemo} from 'react'
|
||||||
import {StyleSheet, View} from 'react-native'
|
import {StyleSheet, View} from 'react-native'
|
||||||
import {
|
import {
|
||||||
AtUri,
|
AtUri,
|
||||||
|
@ -118,7 +118,7 @@ function PostThreadItemDeleted() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function PostThreadItemLoaded({
|
let PostThreadItemLoaded = ({
|
||||||
post,
|
post,
|
||||||
record,
|
record,
|
||||||
richText,
|
richText,
|
||||||
|
@ -144,12 +144,12 @@ function PostThreadItemLoaded({
|
||||||
showParentReplyLine?: boolean
|
showParentReplyLine?: boolean
|
||||||
hasPrecedingItem: boolean
|
hasPrecedingItem: boolean
|
||||||
onPostReply: () => void
|
onPostReply: () => void
|
||||||
}) {
|
}): React.ReactNode => {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const langPrefs = useLanguagePrefs()
|
const langPrefs = useLanguagePrefs()
|
||||||
const {openComposer} = useComposerControls()
|
const {openComposer} = useComposerControls()
|
||||||
const [limitLines, setLimitLines] = React.useState(
|
const [limitLines, setLimitLines] = React.useState(
|
||||||
countLines(richText?.text) >= MAX_POST_LINES,
|
() => countLines(richText?.text) >= MAX_POST_LINES,
|
||||||
)
|
)
|
||||||
const styles = useStyles()
|
const styles = useStyles()
|
||||||
const hasEngagement = post.likeCount || post.repostCount
|
const hasEngagement = post.likeCount || post.repostCount
|
||||||
|
@ -565,6 +565,7 @@ function PostThreadItemLoaded({
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PostThreadItemLoaded = memo(PostThreadItemLoaded)
|
||||||
|
|
||||||
function PostOuterWrapper({
|
function PostOuterWrapper({
|
||||||
post,
|
post,
|
||||||
|
|
|
@ -99,7 +99,7 @@ function PostInner({
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {openComposer} = useComposerControls()
|
const {openComposer} = useComposerControls()
|
||||||
const [limitLines, setLimitLines] = useState(
|
const [limitLines, setLimitLines] = useState(
|
||||||
countLines(richText?.text) >= MAX_POST_LINES,
|
() => countLines(richText?.text) >= MAX_POST_LINES,
|
||||||
)
|
)
|
||||||
const itemUrip = new AtUri(post.uri)
|
const itemUrip = new AtUri(post.uri)
|
||||||
const itemHref = makeProfileLink(post.author, 'post', itemUrip.rkey)
|
const itemHref = makeProfileLink(post.author, 'post', itemUrip.rkey)
|
||||||
|
|
|
@ -106,7 +106,7 @@ let FeedItemInner = ({
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const [limitLines, setLimitLines] = useState(
|
const [limitLines, setLimitLines] = useState(
|
||||||
countLines(richText.text) >= MAX_POST_LINES,
|
() => countLines(richText.text) >= MAX_POST_LINES,
|
||||||
)
|
)
|
||||||
|
|
||||||
const href = useMemo(() => {
|
const href = useMemo(() => {
|
||||||
|
|
Loading…
Reference in New Issue