Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Do less work (#1953)

authored by

dan and committed by
GitHub
c858b583 9c8a1b8a

+24 -29
+6 -4
src/state/cache/post-shadow.ts
··· 1 - import {useEffect, useState, useCallback, useRef} from 'react' 1 + import {useEffect, useState, useMemo, useCallback, useRef} from 'react' 2 2 import EventEmitter from 'eventemitter3' 3 3 import {AppBskyFeedDefs} from '@atproto/api' 4 4 import {Shadow} from './types' ··· 55 55 firstRun.current = false 56 56 }, [post]) 57 57 58 - return state.ts > ifAfterTS 59 - ? mergeShadow(post, state.value) 60 - : {...post, isShadowed: true} 58 + return useMemo(() => { 59 + return state.ts > ifAfterTS 60 + ? mergeShadow(post, state.value) 61 + : {...post, isShadowed: true} 62 + }, [post, state, ifAfterTS]) 61 63 } 62 64 63 65 export function updatePostShadow(uri: string, value: Partial<PostShadow>) {
+6 -4
src/state/cache/profile-shadow.ts
··· 1 - import {useEffect, useState, useCallback, useRef} from 'react' 1 + import {useEffect, useState, useMemo, useCallback, useRef} from 'react' 2 2 import EventEmitter from 'eventemitter3' 3 3 import {AppBskyActorDefs} from '@atproto/api' 4 4 import {Shadow} from './types' ··· 56 56 firstRun.current = false 57 57 }, [profile]) 58 58 59 - return state.ts > ifAfterTS 60 - ? mergeShadow(profile, state.value) 61 - : {...profile, isShadowed: true} 59 + return useMemo(() => { 60 + return state.ts > ifAfterTS 61 + ? mergeShadow(profile, state.value) 62 + : {...profile, isShadowed: true} 63 + }, [profile, state, ifAfterTS]) 62 64 } 63 65 64 66 export function updateProfileShadow(
+5 -15
src/state/queries/preferences/index.ts
··· 1 - import {useEffect, useState} from 'react' 1 + import {useMemo} from 'react' 2 2 import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query' 3 - import { 4 - LabelPreference, 5 - BskyFeedViewPreference, 6 - ModerationOpts, 7 - } from '@atproto/api' 8 - import isEqual from 'lodash.isequal' 3 + import {LabelPreference, BskyFeedViewPreference} from '@atproto/api' 9 4 10 5 import {track} from '#/lib/analytics/analytics' 11 6 import {getAge} from '#/lib/strings/time' ··· 91 86 92 87 export function useModerationOpts() { 93 88 const {currentAccount} = useSession() 94 - const [opts, setOpts] = useState<ModerationOpts | undefined>() 95 89 const prefs = usePreferencesQuery() 96 - useEffect(() => { 90 + const opts = useMemo(() => { 97 91 if (!prefs.data) { 98 92 return 99 93 } 100 - // only update this hook when the moderation options change 101 - const newOpts = getModerationOpts({ 94 + return getModerationOpts({ 102 95 userDid: currentAccount?.did || '', 103 96 preferences: prefs.data, 104 97 }) 105 - if (!isEqual(opts, newOpts)) { 106 - setOpts(newOpts) 107 - } 108 - }, [prefs.data, currentAccount, opts, setOpts]) 98 + }, [currentAccount?.did, prefs.data]) 109 99 return opts 110 100 } 111 101
+5 -4
src/view/com/post-thread/PostThreadItem.tsx
··· 1 - import React, {useMemo} from 'react' 1 + import React, {memo, useMemo} from 'react' 2 2 import {StyleSheet, View} from 'react-native' 3 3 import { 4 4 AtUri, ··· 118 118 ) 119 119 } 120 120 121 - function PostThreadItemLoaded({ 121 + let PostThreadItemLoaded = ({ 122 122 post, 123 123 record, 124 124 richText, ··· 144 144 showParentReplyLine?: boolean 145 145 hasPrecedingItem: boolean 146 146 onPostReply: () => void 147 - }) { 147 + }): React.ReactNode => { 148 148 const pal = usePalette('default') 149 149 const langPrefs = useLanguagePrefs() 150 150 const {openComposer} = useComposerControls() 151 151 const [limitLines, setLimitLines] = React.useState( 152 - countLines(richText?.text) >= MAX_POST_LINES, 152 + () => countLines(richText?.text) >= MAX_POST_LINES, 153 153 ) 154 154 const styles = useStyles() 155 155 const hasEngagement = post.likeCount || post.repostCount ··· 565 565 ) 566 566 } 567 567 } 568 + PostThreadItemLoaded = memo(PostThreadItemLoaded) 568 569 569 570 function PostOuterWrapper({ 570 571 post,
+1 -1
src/view/com/post/Post.tsx
··· 99 99 const pal = usePalette('default') 100 100 const {openComposer} = useComposerControls() 101 101 const [limitLines, setLimitLines] = useState( 102 - countLines(richText?.text) >= MAX_POST_LINES, 102 + () => countLines(richText?.text) >= MAX_POST_LINES, 103 103 ) 104 104 const itemUrip = new AtUri(post.uri) 105 105 const itemHref = makeProfileLink(post.author, 'post', itemUrip.rkey)
+1 -1
src/view/com/posts/FeedItem.tsx
··· 106 106 const pal = usePalette('default') 107 107 const {track} = useAnalytics() 108 108 const [limitLines, setLimitLines] = useState( 109 - countLines(richText.text) >= MAX_POST_LINES, 109 + () => countLines(richText.text) >= MAX_POST_LINES, 110 110 ) 111 111 112 112 const href = useMemo(() => {