ENHANCE
This commit is contained in:
+8
-11
@@ -58,7 +58,6 @@ import {Provider as ProgressGuideProvider} from '#/state/shell/progress-guide'
|
|||||||
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
||||||
import {Provider as StarterPackProvider} from '#/state/shell/starter-pack'
|
import {Provider as StarterPackProvider} from '#/state/shell/starter-pack'
|
||||||
import {Provider as HiddenRepliesProvider} from '#/state/threadgate-hidden-replies'
|
import {Provider as HiddenRepliesProvider} from '#/state/threadgate-hidden-replies'
|
||||||
import {Provider as UnstablePostSourceProvider} from '#/state/unstable-post-source'
|
|
||||||
import {TestCtrls} from '#/view/com/testing/TestCtrls'
|
import {TestCtrls} from '#/view/com/testing/TestCtrls'
|
||||||
import {Provider as VideoVolumeProvider} from '#/view/com/util/post-embeds/VideoVolumeContext'
|
import {Provider as VideoVolumeProvider} from '#/view/com/util/post-embeds/VideoVolumeContext'
|
||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
@@ -151,16 +150,14 @@ function InnerApp() {
|
|||||||
<MutedThreadsProvider>
|
<MutedThreadsProvider>
|
||||||
<ProgressGuideProvider>
|
<ProgressGuideProvider>
|
||||||
<ServiceAccountManager>
|
<ServiceAccountManager>
|
||||||
<UnstablePostSourceProvider>
|
<GestureHandlerRootView
|
||||||
<GestureHandlerRootView
|
style={s.h100pct}>
|
||||||
style={s.h100pct}>
|
<IntentDialogProvider>
|
||||||
<IntentDialogProvider>
|
<TestCtrls />
|
||||||
<TestCtrls />
|
<Shell />
|
||||||
<Shell />
|
<NuxDialogs />
|
||||||
<NuxDialogs />
|
</IntentDialogProvider>
|
||||||
</IntentDialogProvider>
|
</GestureHandlerRootView>
|
||||||
</GestureHandlerRootView>
|
|
||||||
</UnstablePostSourceProvider>
|
|
||||||
</ServiceAccountManager>
|
</ServiceAccountManager>
|
||||||
</ProgressGuideProvider>
|
</ProgressGuideProvider>
|
||||||
</MutedThreadsProvider>
|
</MutedThreadsProvider>
|
||||||
|
|||||||
+4
-7
@@ -48,7 +48,6 @@ import {Provider as ProgressGuideProvider} from '#/state/shell/progress-guide'
|
|||||||
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
||||||
import {Provider as StarterPackProvider} from '#/state/shell/starter-pack'
|
import {Provider as StarterPackProvider} from '#/state/shell/starter-pack'
|
||||||
import {Provider as HiddenRepliesProvider} from '#/state/threadgate-hidden-replies'
|
import {Provider as HiddenRepliesProvider} from '#/state/threadgate-hidden-replies'
|
||||||
import {Provider as UnstablePostSourceProvider} from '#/state/unstable-post-source'
|
|
||||||
import {Provider as ActiveVideoProvider} from '#/view/com/util/post-embeds/ActiveVideoWebContext'
|
import {Provider as ActiveVideoProvider} from '#/view/com/util/post-embeds/ActiveVideoWebContext'
|
||||||
import {Provider as VideoVolumeProvider} from '#/view/com/util/post-embeds/VideoVolumeContext'
|
import {Provider as VideoVolumeProvider} from '#/view/com/util/post-embeds/VideoVolumeContext'
|
||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
@@ -132,12 +131,10 @@ function InnerApp() {
|
|||||||
<SafeAreaProvider>
|
<SafeAreaProvider>
|
||||||
<ProgressGuideProvider>
|
<ProgressGuideProvider>
|
||||||
<ServiceConfigProvider>
|
<ServiceConfigProvider>
|
||||||
<UnstablePostSourceProvider>
|
<IntentDialogProvider>
|
||||||
<IntentDialogProvider>
|
<Shell />
|
||||||
<Shell />
|
<NuxDialogs />
|
||||||
<NuxDialogs />
|
</IntentDialogProvider>
|
||||||
</IntentDialogProvider>
|
|
||||||
</UnstablePostSourceProvider>
|
|
||||||
</ServiceConfigProvider>
|
</ServiceConfigProvider>
|
||||||
</ProgressGuideProvider>
|
</ProgressGuideProvider>
|
||||||
</SafeAreaProvider>
|
</SafeAreaProvider>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {createContext, useCallback, useContext, useId, useState} from 'react'
|
import {useCallback, useId, useState} from 'react'
|
||||||
import {type AppBskyFeedDefs, AtUri} from '@atproto/api'
|
import {type AppBskyFeedDefs, AtUri} from '@atproto/api'
|
||||||
|
|
||||||
import {Logger} from '#/logger'
|
import {Logger} from '#/logger'
|
||||||
@@ -13,12 +13,6 @@ export type PostSource = {
|
|||||||
post: AppBskyFeedDefs.FeedViewPost
|
post: AppBskyFeedDefs.FeedViewPost
|
||||||
feed?: FeedDescriptor
|
feed?: FeedDescriptor
|
||||||
}
|
}
|
||||||
const SetUnstablePostSourceContext = createContext<
|
|
||||||
(key: string, source: PostSource) => void
|
|
||||||
>(() => {})
|
|
||||||
const ConsumeUnstablePostSourceContext = createContext<
|
|
||||||
(key: string, id: string) => PostSource | undefined
|
|
||||||
>(() => undefined)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache of sources that will be consumed by the post thread view. This is
|
* A cache of sources that will be consumed by the post thread view. This is
|
||||||
@@ -35,25 +29,30 @@ const transientSourcesRef = new Map<string, PostSource>()
|
|||||||
const consumedSourcesRef = new Map<string, PostSource>()
|
const consumedSourcesRef = new Map<string, PostSource>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For passing the source of the post (i.e. the original post, from the feed)
|
* For stashing the feed that the user was browsing when they clicked on a post.
|
||||||
* to the threadview, without using query params. Deliberately unstable to
|
*
|
||||||
* avoid using query params, use for FeedFeedback and other ephemeral
|
* Used for FeedFeedback and other ephemeral non-critical systems.
|
||||||
* non-critical systems.
|
|
||||||
*/
|
*/
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function useSetUnstablePostSource() {
|
||||||
const setUnstablePostSource = useCallback(
|
return useCallback((key: string, source: PostSource) => {
|
||||||
(key: string, source: PostSource) => {
|
assertValid(
|
||||||
assertValid(
|
key,
|
||||||
key,
|
`setUnstablePostSource key should be a URI containing a handle, received ${key} — use buildPostSourceKey`,
|
||||||
`setUnstablePostSource key should be a URI containing a handle, received ${key} — use buildPostSourceKey`,
|
)
|
||||||
)
|
logger.debug('set', {key, source})
|
||||||
logger.debug('set', {key, source})
|
transientSourcesRef.set(key, source)
|
||||||
transientSourcesRef.set(key, source)
|
}, [])
|
||||||
},
|
}
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
const consumeUnstablePostSource = useCallback((key: string, id: string) => {
|
/**
|
||||||
|
* This hook is unstable and should only be used for FeedFeedback and other
|
||||||
|
* ephemeral non-critical systems. Views that use this hook will continue to
|
||||||
|
* return a reference to the same source until those views are dropped from
|
||||||
|
* memory.
|
||||||
|
*/
|
||||||
|
export function useUnstablePostSource(key: string) {
|
||||||
|
const id = useId()
|
||||||
|
const [source] = useState(() => {
|
||||||
assertValid(
|
assertValid(
|
||||||
key,
|
key,
|
||||||
`consumeUnstablePostSource key should be a URI containing a handle, received ${key} — use buildPostSourceKey`,
|
`consumeUnstablePostSource key should be a URI containing a handle, received ${key} — use buildPostSourceKey`,
|
||||||
@@ -65,30 +64,7 @@ export function Provider({children}: {children: React.ReactNode}) {
|
|||||||
consumedSourcesRef.set(id, source)
|
consumedSourcesRef.set(id, source)
|
||||||
}
|
}
|
||||||
return source
|
return source
|
||||||
}, [])
|
})
|
||||||
|
|
||||||
return (
|
|
||||||
<SetUnstablePostSourceContext.Provider value={setUnstablePostSource}>
|
|
||||||
<ConsumeUnstablePostSourceContext.Provider
|
|
||||||
value={consumeUnstablePostSource}>
|
|
||||||
{children}
|
|
||||||
</ConsumeUnstablePostSourceContext.Provider>
|
|
||||||
</SetUnstablePostSourceContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSetUnstablePostSource() {
|
|
||||||
return useContext(SetUnstablePostSourceContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DANGER - This hook is unstable and should only be used for FeedFeedback
|
|
||||||
* and other ephemeral non-critical systems. Does not change when the URI changes.
|
|
||||||
*/
|
|
||||||
export function useUnstablePostSource(key: string) {
|
|
||||||
const id = useId()
|
|
||||||
const consume = useContext(ConsumeUnstablePostSourceContext)
|
|
||||||
const [source] = useState(() => consume(key, id))
|
|
||||||
return source
|
return source
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +78,9 @@ export function buildPostSourceKey(key: string, handle: string) {
|
|||||||
return urip.toString()
|
return urip.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just a lil dev helper
|
||||||
|
*/
|
||||||
function assertValid(key: string, message: string) {
|
function assertValid(key: string, message: string) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
const urip = new AtUri(key)
|
const urip = new AtUri(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user