Skip to content

Commit

Permalink
Remove the concept of __key__
Browse files Browse the repository at this point in the history
I don't think this concept is consistent.

It's introduced on FeedSourceInfo which is used both by pinned feeds and by useFeedSourceInfoQuery. Pinned feeds use the pinning ID there. But there is no pinning ID for useFeedSourceInfoQuery. So this means this field is sometimes one thing and sometimes some other thing. That is a decent sign that it shouldn't be on that type at all.

It's not used anywhere except the desktop feed enumeration. It seems reasonable to assume there that we wouldn't want to show the same feed URL twice. (And if it does occur in the array twice, IMO we should solve that at the API level and dedupe it on read or next write.) So I think we should just use the URL in that place. (I used the descriptor, which is equivalent.)
  • Loading branch information
gaearon committed May 10, 2024
1 parent b5f0104 commit 7843871
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
27 changes: 3 additions & 24 deletions src/state/queries/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import {useAgent, useSession} from '#/state/session'
import {router} from '#/routes'

export type FeedSourceFeedInfo = {
/**
* Unique identifier. The URI + `savedFeed.id` if available.
*/
__key__: string
type: 'feed'
uri: string
route: {
Expand All @@ -44,10 +40,6 @@ export type FeedSourceFeedInfo = {
}

export type FeedSourceListInfo = {
/**
* Unique identifier. The URI + `savedFeed.id` if available.
*/
__key__: string
type: 'list'
uri: string
route: {
Expand Down Expand Up @@ -78,7 +70,6 @@ const feedSourceNSIDs = {

export function hydrateFeedGenerator(
view: AppBskyFeedDefs.GeneratorView,
extra?: {__key__: string},
): FeedSourceInfo {
const urip = new AtUri(view.uri)
const collection =
Expand All @@ -87,7 +78,6 @@ export function hydrateFeedGenerator(
const route = router.matchPath(href)

return {
__key__: `feed|${view.uri}|${extra?.__key__ || ''}`,
type: 'feed',
uri: view.uri,
cid: view.cid,
Expand All @@ -111,18 +101,14 @@ export function hydrateFeedGenerator(
}
}

export function hydrateList(
view: AppBskyGraphDefs.ListView,
extra?: {__key__: string},
): FeedSourceInfo {
export function hydrateList(view: AppBskyGraphDefs.ListView): FeedSourceInfo {
const urip = new AtUri(view.uri)
const collection =
urip.collection === 'app.bsky.feed.generator' ? 'feed' : 'lists'
const href = `/profile/${urip.hostname}/${collection}/${urip.rkey}`
const route = router.matchPath(href)

return {
__key__: `list|${view.uri}|${extra?.__key__ || ''}`,
type: 'list',
uri: view.uri,
route: {
Expand Down Expand Up @@ -221,7 +207,6 @@ export function useSearchPopularFeedsMutation() {
* The following feed, with fallbacks to Discover
*/
const PWI_DISCOVER_FEED_STUB: FeedSourceInfo = {
__key__: 'pwi',
type: 'feed',
displayName: 'Discover',
uri: DISCOVER_FEED_URI,
Expand Down Expand Up @@ -273,9 +258,7 @@ export function usePinnedFeedsInfos() {
const feedView = res.data.feeds[i]
resolved.set(
feedView.uri + pinnedFeedsIds[i],
hydrateFeedGenerator(feedView, {
__key__: pinnedFeedsIds[i],
}),
hydrateFeedGenerator(feedView),
)
}
})
Expand All @@ -290,10 +273,7 @@ export function usePinnedFeedsInfos() {
})
.then(res => {
const listView = res.data.list
resolved.set(
listView.uri + list.id,
hydrateList(listView, {__key__: list.id}),
)
resolved.set(listView.uri + list.id, hydrateList(listView))
}),
)

Expand All @@ -308,7 +288,6 @@ export function usePinnedFeedsInfos() {
result.push(feedInfo)
} else if (pinnedItem.type === 'timeline') {
result.push({
__key__: `feed|${pinnedItem.value}|${pinnedItem.id}`,
type: 'feed',
displayName: 'Following',
uri: pinnedItem.value,
Expand Down
2 changes: 1 addition & 1 deletion src/view/shell/desktop/Feeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function DesktopFeeds() {
}
return (
<FeedItem
key={feedInfo.__key__}
key={feed}
href={'/?' + new URLSearchParams([['feed', feed]])}
title={feedInfo.displayName}
current={route.name === 'Home' && feed === selectedFeed}
Expand Down

0 comments on commit 7843871

Please sign in to comment.