PWI behavior updates (#2207)
* Enable PWI * Disable access to feeds on PWI * Remove feeds nav item from drawer when signed out * Replace discover feed on home with a CTA * Wire up the sign in and create account buttons to go straight to their respective screens * Give a custom ScreenHider interface for no-pwi * Add side borders on desktop to the screen hider * Filter accounts in the autocomplete according to mod settings * Trim replies in the post thread that are pwi opt-out * Show 'learn more' on the content hider when no-override is enabled * Apply the moderation filter on profile cards * Disable post search on logged-out view * Update locale files * Bump api pkg * Ensure feeds with no posts don't show as NSFPublic * Fix types --------- Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
parent
7fd7970237
commit
075ffdf583
24 changed files with 839 additions and 443 deletions
|
@ -1,16 +1,27 @@
|
|||
import React from 'react'
|
||||
import {AppBskyActorDefs} from '@atproto/api'
|
||||
import {AppBskyActorDefs, ModerationOpts, moderateProfile} from '@atproto/api'
|
||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useMyFollowsQuery} from '#/state/queries/my-follows'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {
|
||||
DEFAULT_LOGGED_OUT_PREFERENCES,
|
||||
getModerationOpts,
|
||||
useModerationOpts,
|
||||
} from './preferences'
|
||||
|
||||
const DEFAULT_MOD_OPTS = getModerationOpts({
|
||||
userDid: '',
|
||||
preferences: DEFAULT_LOGGED_OUT_PREFERENCES,
|
||||
})
|
||||
|
||||
export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix]
|
||||
|
||||
export function useActorAutocompleteQuery(prefix: string) {
|
||||
const {data: follows, isFetching} = useMyFollowsQuery()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
|
@ -22,9 +33,20 @@ export function useActorAutocompleteQuery(prefix: string) {
|
|||
limit: 8,
|
||||
})
|
||||
: undefined
|
||||
return computeSuggestions(prefix, follows, res?.data.actors)
|
||||
return res?.data.actors || []
|
||||
},
|
||||
enabled: !isFetching,
|
||||
select: React.useCallback(
|
||||
(data: AppBskyActorDefs.ProfileViewBasic[]) => {
|
||||
return computeSuggestions(
|
||||
prefix,
|
||||
follows,
|
||||
data,
|
||||
moderationOpts || DEFAULT_MOD_OPTS,
|
||||
)
|
||||
},
|
||||
[prefix, follows, moderationOpts],
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -32,6 +54,7 @@ export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn>
|
|||
export function useActorAutocompleteFn() {
|
||||
const queryClient = useQueryClient()
|
||||
const {data: follows} = useMyFollowsQuery()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
return React.useCallback(
|
||||
async ({query, limit = 8}: {query: string; limit?: number}) => {
|
||||
|
@ -54,9 +77,14 @@ export function useActorAutocompleteFn() {
|
|||
}
|
||||
}
|
||||
|
||||
return computeSuggestions(query, follows, res?.data.actors)
|
||||
return computeSuggestions(
|
||||
query,
|
||||
follows,
|
||||
res?.data.actors,
|
||||
moderationOpts || DEFAULT_MOD_OPTS,
|
||||
)
|
||||
},
|
||||
[follows, queryClient],
|
||||
[follows, queryClient, moderationOpts],
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -64,6 +92,7 @@ function computeSuggestions(
|
|||
prefix: string,
|
||||
follows: AppBskyActorDefs.ProfileViewBasic[] | undefined,
|
||||
searched: AppBskyActorDefs.ProfileViewBasic[] = [],
|
||||
moderationOpts: ModerationOpts,
|
||||
) {
|
||||
let items: AppBskyActorDefs.ProfileViewBasic[] = []
|
||||
if (follows) {
|
||||
|
@ -76,10 +105,14 @@ function computeSuggestions(
|
|||
handle: item.handle,
|
||||
displayName: item.displayName,
|
||||
avatar: item.avatar,
|
||||
labels: item.labels,
|
||||
})
|
||||
}
|
||||
}
|
||||
return items
|
||||
return items.filter(profile => {
|
||||
const mod = moderateProfile(profile, moderationOpts)
|
||||
return !mod.account.filter
|
||||
})
|
||||
}
|
||||
|
||||
function prefixMatch(
|
||||
|
|
|
@ -409,6 +409,9 @@ export function* findAllPostsInQueryData(
|
|||
}
|
||||
|
||||
function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
||||
// no posts in this feed
|
||||
if (feed.length === 0) return true
|
||||
|
||||
// assume false
|
||||
let somePostsPassModeration = false
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ type Controls = {
|
|||
/**
|
||||
* The did of the account to populate the login form with.
|
||||
*/
|
||||
requestedAccount?: string
|
||||
requestedAccount?: string | 'none' | 'new'
|
||||
}) => void
|
||||
/**
|
||||
* Clears the requested account so that next time the logged out view is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue