diff --git a/lexicons.json b/lexicons.json
index c0b5c9323..389c1f31d 100644
--- a/lexicons.json
+++ b/lexicons.json
@@ -118,6 +118,7 @@
"app.bsky.notification.unregisterPush",
"app.bsky.notification.updateSeen",
"app.bsky.richtext.facet",
+ "app.bsky.unspecced.getAtmosphereApps",
"app.bsky.unspecced.getAtmosphereExploreTab",
"app.bsky.video.defs",
"app.bsky.video.getJobStatus",
@@ -753,6 +754,10 @@
"uri": "at://did:plc:4v4y5r3lwsbtmsxhile2ljac/com.atproto.lexicon.schema/app.bsky.richtext.facet",
"cid": "bafyreidg56eo7zynf6ihz4xb627vwoqf5idnevkmwp7sxc4tijg6xngbu4"
},
+ "app.bsky.unspecced.getAtmosphereApps": {
+ "uri": "at://did:plc:4v4y5r3lwsbtmsxhile2ljac/com.atproto.lexicon.schema/app.bsky.unspecced.getAtmosphereApps",
+ "cid": "bafyreihpi7hxe7j4uh7haawophxtppjwziojd4swq4anpgvnegigqk2234"
+ },
"app.bsky.unspecced.getAtmosphereExploreTab": {
"uri": "at://did:plc:4v4y5r3lwsbtmsxhile2ljac/com.atproto.lexicon.schema/app.bsky.unspecced.getAtmosphereExploreTab",
"cid": "bafyreiez66qb7byto44nzivpn27ykzdgilgpuqogeusypl3mln7wicjnry"
diff --git a/lexicons/README.md b/lexicons/README.md
index ac557b969..be1c94f55 100644
--- a/lexicons/README.md
+++ b/lexicons/README.md
@@ -5,15 +5,18 @@ to exclude the unpublished exception below. `lexicons.json` pins each schema's
URI and CID, and `pnpm lexicons:verify` checks the installed files against it.
Do not hand-edit published schemas.
-## Exception: `app.bsky.unspecced.getAtmosphereExploreTab`
+## Exceptions: `app.bsky.unspecced.getAtmosphereExploreTab` and `getAtmosphereApps`
The `app.bsky.unspecced` namespace is intentionally unpublished (it is a DNS
carveout upstream, and resolving it is a CI violation there), so the installer
-cannot fetch it. Its schema is copied from the merged upstream source,
-[`lexicons/app/bsky/unspecced/getAtmosphereExploreTab.json` at `293d6494ed90`](https://github.com/bluesky-social/bsky/blob/293d6494ed9058e28a04b97133d16ab8abe7ef5e/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.json).
+cannot fetch it. These schemas are copied from merged upstream sources:
-In `lexicons.json`, its `cid` is a locally calculated content-integrity pin, not
-a published record CID, and its `uri` is only an installer compatibility hint,
-not a published record location. An unscoped network update will fail when it
-tries to fetch this schema. Update it from upstream JSON and compute its local
-CID with `cidForLex` from `@atproto/lex-cbor`.
+- [`lexicons/app/bsky/unspecced/getAtmosphereExploreTab.json` at `293d6494ed90`](https://github.com/bluesky-social/bsky/blob/293d6494ed9058e28a04b97133d16ab8abe7ef5e/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.json)
+- `lexicons-overrides/app/bsky/unspecced/getAtmosphereApps.json` at atproto
+ `11f52c5588279d159ab12404a1b323731a467fdd` (from atproto PR 5801)
+
+In `lexicons.json`, their `cid` values are locally calculated content-integrity
+pins, not published record CIDs, and their `uri` values are only installer
+compatibility hints, not published record locations. An unscoped network update
+will fail when it tries to fetch these schemas. Update them from upstream JSON
+and compute each local CID with `cidForLex` from `@atproto/lex-cbor`.
diff --git a/lexicons/app/bsky/unspecced/getAtmosphereApps.json b/lexicons/app/bsky/unspecced/getAtmosphereApps.json
new file mode 100644
index 000000000..2121f381c
--- /dev/null
+++ b/lexicons/app/bsky/unspecced/getAtmosphereApps.json
@@ -0,0 +1,80 @@
+{
+ "lexicon": 1,
+ "id": "app.bsky.unspecced.getAtmosphereApps",
+ "defs": {
+ "main": {
+ "type": "query",
+ "description": "Get curated Atmosphere apps. Authentication is optional; authenticated requests include viewer-specific profile state and known followers.",
+ "parameters": {
+ "type": "params",
+ "properties": {
+ "category": {
+ "type": "string",
+ "maxLength": 100,
+ "description": "Only return apps with this category (exact match). Omit to return all apps."
+ }
+ }
+ },
+ "output": {
+ "encoding": "application/json",
+ "schema": {
+ "type": "object",
+ "required": ["apps"],
+ "properties": {
+ "apps": {
+ "type": "array",
+ "maxLength": 100,
+ "items": {
+ "type": "ref",
+ "ref": "#appCard"
+ }
+ }
+ }
+ }
+ }
+ },
+ "appCard": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string",
+ "maxLength": 4096
+ },
+ "title": {
+ "type": "string",
+ "maxLength": 4096
+ },
+ "description": {
+ "type": "string",
+ "maxLength": 4096
+ },
+ "logo": {
+ "type": "string",
+ "format": "uri",
+ "maxLength": 4096,
+ "description": "The app's logo, using its account avatar when available."
+ },
+ "banner": {
+ "type": "string",
+ "format": "uri",
+ "maxLength": 4096,
+ "description": "The app's banner, using its account banner when available."
+ },
+ "url": {
+ "type": "string",
+ "format": "uri",
+ "maxLength": 4096
+ },
+ "category": {
+ "type": "string",
+ "maxLength": 100
+ },
+ "profile": {
+ "type": "ref",
+ "ref": "app.bsky.actor.defs#profileViewDetailed",
+ "description": "The app's account profile, when available."
+ }
+ }
+ }
+ }
+}
diff --git a/src/screens/Atmosphere/AppsTab.tsx b/src/screens/Atmosphere/AppsTab.tsx
new file mode 100644
index 000000000..96fe6bfbf
--- /dev/null
+++ b/src/screens/Atmosphere/AppsTab.tsx
@@ -0,0 +1,146 @@
+import {useEffect, useState} from 'react'
+import {RefreshControl, View} from 'react-native'
+import {useSharedValue, withTiming} from 'react-native-reanimated'
+import {useLingui} from '@lingui/react/macro'
+
+import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
+import {getAtmosphereApps} from '#/screens/Atmosphere/data/exploreData'
+import {useAtmosphereAppsQuery} from '#/screens/Atmosphere/data/useAtmosphereAppsQuery'
+import {TabPills} from '#/screens/Notifications/components/TabPills'
+import {atoms as a, useTheme} from '#/alf'
+import * as Layout from '#/components/Layout'
+import {Loader} from '#/components/Loader'
+import {Text} from '#/components/Typography'
+import {AppCard} from './components/AppCard'
+
+export function AtmosphereAppsTab() {
+ const t = useTheme()
+ const {t: l} = useLingui()
+ const {data, isError, isPending, refetch} = useAtmosphereAppsQuery()
+ const [selectedKey, setSelectedKey] = useState('all')
+ const [isRefreshing, setIsRefreshing] = useState(false)
+ const dragProgress = useSharedValue(0)
+
+ /** Keys other than `all` are the category values sent by the backend. */
+ const categoryDefinitions = [
+ {key: 'all', label: l`All`},
+ {key: 'writing', label: l`Blogging`},
+ {key: 'photography', label: l`Photo`},
+ {key: 'video', label: l`Video`},
+ {key: 'games', label: l`Games`},
+ {key: 'feeds', label: l`Feeds`},
+ {key: 'social', label: l`Social`},
+ {key: 'dev', label: l`Dev`},
+ {key: 'audio', label: l`Audio`},
+ {key: 'events', label: l`Events`},
+ {key: 'utils', label: l`Utils`},
+ ]
+ /*
+ * Only show categories with at least one renderable app. All is always
+ * shown and keeps apps with a missing or unknown category.
+ */
+ const categories = categoryDefinitions.filter(
+ ({key}) =>
+ key === 'all' || (data && getAtmosphereApps(data, key).length > 0),
+ )
+ const selectedIndex = categories.findIndex(({key}) => key === selectedKey)
+
+ /*
+ * Keeps the indicator on the selected pill, including when a refresh
+ * removes categories before it, and returns to All if the selected category
+ * itself disappears.
+ */
+ useEffect(() => {
+ dragProgress.set(withTiming(Math.max(0, selectedIndex)))
+ if (selectedIndex === -1) setSelectedKey('all')
+ }, [selectedIndex, dragProgress])
+
+ async function onRefresh() {
+ setIsRefreshing(true)
+ try {
+ await refetch()
+ } finally {
+ setIsRefreshing(false)
+ }
+ }
+
+ const refreshControl = (
+
+ )
+
+ const errorMessage = (
+ void refetch()}
+ />
+ )
+
+ if (!data) {
+ return (
+
+ {isPending ? (
+
+
+
+ ) : isError ? (
+ errorMessage
+ ) : undefined}
+
+ )
+ }
+
+ const activeKey = selectedIndex === -1 ? 'all' : selectedKey
+ const apps = getAtmosphereApps(
+ data,
+ activeKey === 'all' ? undefined : activeKey,
+ )
+
+ return (
+
+
+ {isError ? {errorMessage} : undefined}
+ l`Shows ${tab.label} apps`}
+ />
+
+ {apps.length ? (
+ apps.map(app => )
+ ) : (
+
+ {l`No apps in this category yet.`}
+
+ )}
+
+
+
+ )
+}
diff --git a/src/screens/Atmosphere/ExploreTab.tsx b/src/screens/Atmosphere/ExploreTab.tsx
index 9e8afad66..e745d7d5b 100644
--- a/src/screens/Atmosphere/ExploreTab.tsx
+++ b/src/screens/Atmosphere/ExploreTab.tsx
@@ -1,31 +1,50 @@
-import {View} from 'react-native'
+import {useState} from 'react'
+import {RefreshControl, View} from 'react-native'
import {useLingui} from '@lingui/react/macro'
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
import {
getAtmosphereAnnouncementBanner,
- getAtmosphereApps,
getAtmosphereArticles,
getAtmosphereLivestreams,
getAtmospherePhotos,
getAtmospherePublications,
} from '#/screens/Atmosphere/data/exploreData'
import {useAtmosphereExploreQuery} from '#/screens/Atmosphere/data/useAtmosphereExploreQuery'
-import {atoms as a} from '#/alf'
+import {atoms as a, useTheme} from '#/alf'
import * as Layout from '#/components/Layout'
import {Loader} from '#/components/Loader'
import {AnnouncementBanner} from './components/AnnouncementBanner'
import {AtmosphereNux} from './components/AtmosphereNux'
import {ExploreGalleryBleed} from './components/ExploreGallery'
-import {FeaturedApps} from './components/FeaturedApps'
import {FeaturedArticles} from './components/FeaturedArticles'
import {FeaturedLivestreams} from './components/FeaturedLivestreams'
import {FeaturedPhotos} from './components/FeaturedPhotos'
import {FeaturedPublications} from './components/FeaturedPublications'
export function AtmosphereExploreTab() {
+ const t = useTheme()
const {t: l} = useLingui()
const {data, isError, isPending, refetch} = useAtmosphereExploreQuery()
+ const [isRefreshing, setIsRefreshing] = useState(false)
+
+ async function onRefresh() {
+ setIsRefreshing(true)
+ try {
+ await refetch()
+ } finally {
+ setIsRefreshing(false)
+ }
+ }
+
+ const refreshControl = (
+
+ )
const errorMessage = (
{isPending ? (
@@ -75,7 +98,6 @@ export function AtmosphereExploreTab() {
/>
-
diff --git a/src/screens/Atmosphere/__tests__/AppsTab.test.tsx b/src/screens/Atmosphere/__tests__/AppsTab.test.tsx
new file mode 100644
index 000000000..b5f79a081
--- /dev/null
+++ b/src/screens/Atmosphere/__tests__/AppsTab.test.tsx
@@ -0,0 +1,332 @@
+import {type RefreshControlProps} from 'react-native'
+import {createDeferrable} from '@atproto/common-web'
+import {act, fireEvent, render, screen} from '@testing-library/react-native'
+
+import {AtmosphereAppsTab} from '#/screens/Atmosphere/AppsTab'
+import {type AtmosphereAppsData} from '#/screens/Atmosphere/data/exploreData'
+import {useAtmosphereAppsQuery} from '#/screens/Atmosphere/data/useAtmosphereAppsQuery'
+
+jest.mock('@lingui/react', () => ({
+ useLingui: () => ({
+ _: (message: {message?: string} | string) =>
+ typeof message === 'string' ? message : (message.message ?? ''),
+ }),
+}))
+
+/* The most recent shared value, so tests can read it after effects run. */
+const mockProgress: {get: () => number} = {get: () => 0}
+
+jest.mock('react-native-reanimated', () => ({
+ useSharedValue: (initial: number) => {
+ const {useState} = require('react') as typeof import('react')
+ return useState(() => {
+ let value = initial
+ const sharedValue = {
+ get: () => value,
+ set: (next: number) => (value = next),
+ }
+ mockProgress.get = sharedValue.get
+ return sharedValue
+ })[0]
+ },
+ withTiming: (value: number) => value,
+}))
+
+jest.mock('#/screens/Atmosphere/data/useAtmosphereAppsQuery', () => ({
+ useAtmosphereAppsQuery: jest.fn(),
+}))
+
+jest.mock('#/components/Layout', () => {
+ const {View} =
+ jest.requireActual('react-native')
+ return {Content: View}
+})
+
+jest.mock('#/components/Typography', () => {
+ const {Text} =
+ jest.requireActual('react-native')
+ return {Text}
+})
+
+jest.mock('#/components/Loader', () => {
+ const {View} =
+ jest.requireActual('react-native')
+ return {Loader: () => }
+})
+
+jest.mock('#/view/com/util/error/ErrorMessage', () => {
+ const {Pressable, Text, View} =
+ jest.requireActual('react-native')
+ return {
+ ErrorMessage: ({
+ message,
+ onPressTryAgain,
+ }: {
+ message: string
+ onPressTryAgain: () => void
+ }) => (
+
+ {message}
+
+
+ ),
+ }
+})
+
+jest.mock('#/screens/Atmosphere/components/AppCard', () => {
+ const {Text} =
+ jest.requireActual('react-native')
+ return {AppCard: ({app}: {app: {title: string}}) => {app.title}}
+})
+
+jest.mock('#/screens/Notifications/components/TabPills', () => {
+ const {Pressable, Text, View} =
+ jest.requireActual('react-native')
+ return {
+ TabPills: ({
+ tabs,
+ selectedTab,
+ onSelectTab,
+ }: {
+ tabs: {key: string; label: string}[]
+ selectedTab: string
+ onSelectTab: (key: string) => void
+ }) => (
+
+ {selectedTab}
+ {tabs.map(tab => (
+ onSelectTab(tab.key)}>
+ {tab.label}
+
+ ))}
+
+ ),
+ }
+})
+
+const mockQuery = jest.mocked(useAtmosphereAppsQuery)
+const refetch = jest.fn()
+
+function getRefreshControlProps() {
+ const {refreshControl} = screen.getByTestId('atmosphereAppsTab').props as {
+ refreshControl: React.ReactElement
+ }
+ return refreshControl.props
+}
+
+function setQuery(result: Partial>) {
+ mockQuery.mockReturnValue({
+ data: undefined,
+ isError: false,
+ isPending: false,
+ isRefetching: false,
+ refetch,
+ ...result,
+ } as never)
+}
+
+const url = 'https://example.com/app'
+const data: AtmosphereAppsData = {
+ apps: [
+ {id: 'blog', title: 'Blog app', url, category: 'writing'},
+ {id: 'photo', title: 'Photo app', url, category: 'photography'},
+ {id: 'game', title: 'Game app', url, category: 'games'},
+ {id: 'social', title: 'Social app', url, category: 'social'},
+ {id: 'dev', title: 'Dev app', url, category: 'dev'},
+ {id: 'audio', title: 'Audio app', url, category: 'audio'},
+ {id: 'event', title: 'Event app', url, category: 'events'},
+ {id: 'util', title: 'Util app', url, category: 'utils'},
+ {id: 'unknown', title: 'Unknown app', url, category: 'new'},
+ {id: 'missing', title: 'Missing app', url},
+ /* Invalid cards never render, so they must not create a pill. */
+ {id: 'invalid', title: '', url, category: 'video'},
+ {id: 'invalid-feed', title: 'No URL', category: 'feeds'},
+ ],
+}
+
+const populatedKeys = [
+ 'all',
+ 'writing',
+ 'photography',
+ 'games',
+ 'social',
+ 'dev',
+ 'audio',
+ 'events',
+ 'utils',
+]
+
+function pillKeys() {
+ return screen
+ .getAllByTestId(/^pill-/)
+ .map(pill => (pill.props as {testID: string}).testID.slice('pill-'.length))
+}
+
+beforeEach(() => {
+ jest.clearAllMocks()
+})
+
+describe('AtmosphereAppsTab', () => {
+ it('shows an accessible loader while the first request is pending', () => {
+ setQuery({isPending: true})
+ render()
+
+ expect(screen.getByTestId('atmosphereAppsTab')).toBeTruthy()
+ expect(screen.getByTestId('atmosphereAppsTabLoading')).toBeTruthy()
+ expect(screen.getByLabelText('Loading Atmosphere content')).toBeTruthy()
+ expect(screen.queryByTestId('selectedTab')).toBeNull()
+ })
+
+ it('offers retry when the first request fails', () => {
+ setQuery({isError: true})
+ render()
+
+ expect(
+ screen.getByText('Could not load Atmosphere content. Please try again.'),
+ ).toBeTruthy()
+ fireEvent.press(screen.getByTestId('retry'))
+ expect(refetch).toHaveBeenCalledTimes(1)
+ })
+
+ it('shows every valid app under All, including uncategorized ones', () => {
+ setQuery({data})
+ render()
+
+ expect(screen.getByTestId('selectedTab').props.children).toBe('all')
+ for (const title of [
+ 'Blog app',
+ 'Photo app',
+ 'Game app',
+ 'Social app',
+ 'Dev app',
+ 'Audio app',
+ 'Event app',
+ 'Util app',
+ 'Unknown app',
+ 'Missing app',
+ ]) {
+ expect(screen.getByText(title)).toBeTruthy()
+ }
+ expect(screen.queryByText('No apps in this category yet.')).toBeNull()
+ expect(screen.queryByTestId('retry')).toBeNull()
+ })
+
+ it.each([
+ ['writing', 'Blog app'],
+ ['photography', 'Photo app'],
+ ['games', 'Game app'],
+ ['social', 'Social app'],
+ ['dev', 'Dev app'],
+ ['audio', 'Audio app'],
+ ['events', 'Event app'],
+ ['utils', 'Util app'],
+ ])('filters %s locally without refetching', (key, title) => {
+ setQuery({data})
+ render()
+
+ fireEvent.press(screen.getByTestId(`pill-${key}`))
+
+ expect(screen.getByTestId('selectedTab').props.children).toBe(key)
+ expect(mockProgress.get()).toBe(populatedKeys.indexOf(key))
+ expect(screen.getByText(title)).toBeTruthy()
+ expect(screen.queryByText('Unknown app')).toBeNull()
+ expect(screen.queryByText('Missing app')).toBeNull()
+ expect(screen.getAllByText(/ app$/)).toHaveLength(1)
+ expect(refetch).not.toHaveBeenCalled()
+ })
+
+ it('shows only All and populated categories, in order', () => {
+ setQuery({data})
+ render()
+
+ expect(pillKeys()).toEqual(populatedKeys)
+ for (const label of ['Social', 'Dev', 'Audio', 'Events', 'Utils']) {
+ expect(screen.getByText(label)).toBeTruthy()
+ }
+ /* Video has only an invalid app and Feeds none that render. */
+ expect(screen.queryByText('Video')).toBeNull()
+ expect(screen.queryByText('Feeds')).toBeNull()
+ })
+
+ it('keeps All and the empty message for an empty response', () => {
+ setQuery({data: {apps: []}})
+ render()
+
+ expect(pillKeys()).toEqual(['all'])
+ expect(screen.getByText('No apps in this category yet.')).toBeTruthy()
+ })
+
+ it('returns to All when a refresh removes the selected category', () => {
+ setQuery({data})
+ const {rerender} = render()
+ fireEvent.press(screen.getByTestId('pill-dev'))
+ expect(screen.getByTestId('selectedTab').props.children).toBe('dev')
+
+ setQuery({data: {apps: data.apps.filter(app => app.category !== 'dev')}})
+ rerender()
+
+ expect(screen.getByTestId('selectedTab').props.children).toBe('all')
+ expect(mockProgress.get()).toBe(0)
+ expect(screen.getByText('Blog app')).toBeTruthy()
+ expect(screen.getByText('Unknown app')).toBeTruthy()
+ expect(screen.queryByTestId('pill-dev')).toBeNull()
+ })
+
+ it('moves the indicator when a refresh removes a category before the selected one', () => {
+ setQuery({data})
+ const {rerender} = render()
+ fireEvent.press(screen.getByTestId('pill-dev'))
+ expect(mockProgress.get()).toBe(5)
+
+ setQuery({
+ data: {apps: data.apps.filter(app => app.category !== 'photography')},
+ })
+ rerender()
+
+ expect(screen.getByTestId('selectedTab').props.children).toBe('dev')
+ expect(mockProgress.get()).toBe(4)
+ expect(screen.getByText('Dev app')).toBeTruthy()
+ expect(refetch).not.toHaveBeenCalled()
+ })
+
+ it('keeps cached apps and offers retry when a refetch fails', () => {
+ setQuery({data, isError: true})
+ render()
+
+ expect(screen.getByText('Blog app')).toBeTruthy()
+ fireEvent.press(screen.getByTestId('retry'))
+ expect(refetch).toHaveBeenCalledTimes(1)
+ })
+
+ it.each([
+ ['loading', {isPending: true}],
+ ['error', {isError: true}],
+ ['loaded', {data}],
+ ])('shows the spinner only for a pull while %s', async (_name, result) => {
+ const refresh = createDeferrable()
+ refetch.mockReturnValueOnce(refresh.complete)
+ setQuery({...result, isRefetching: true})
+ render()
+
+ expect(getRefreshControlProps().refreshing).toBe(false)
+ act(() => {
+ void getRefreshControlProps().onRefresh?.()
+ })
+ expect(refetch).toHaveBeenCalledTimes(1)
+ expect(getRefreshControlProps().refreshing).toBe(true)
+
+ await act(async () => {
+ refresh.resolve()
+ await refresh.complete
+ })
+ expect(getRefreshControlProps().refreshing).toBe(false)
+ })
+})
diff --git a/src/screens/Atmosphere/__tests__/ExploreTab.test.tsx b/src/screens/Atmosphere/__tests__/ExploreTab.test.tsx
index 0d4c30e14..0fc1b7c28 100644
--- a/src/screens/Atmosphere/__tests__/ExploreTab.test.tsx
+++ b/src/screens/Atmosphere/__tests__/ExploreTab.test.tsx
@@ -1,4 +1,6 @@
-import {fireEvent, render, screen} from '@testing-library/react-native'
+import {type RefreshControlProps} from 'react-native'
+import {createDeferrable} from '@atproto/common-web'
+import {act, fireEvent, render, screen} from '@testing-library/react-native'
import {exploreResponseFixture} from '#/screens/Atmosphere/__tests__/fixtures/exploreResponse'
import {livestreamPreviewFixture} from '#/screens/Atmosphere/__tests__/fixtures/livestreamPreview'
@@ -97,6 +99,13 @@ jest.mock('#/screens/Atmosphere/components/FeaturedPhotos', () => ({
const mockQuery = jest.mocked(useAtmosphereExploreQuery)
const refetch = jest.fn()
+function getRefreshControlProps() {
+ const {refreshControl} = screen.getByTestId('atmosphereExploreTab').props as {
+ refreshControl: React.ReactElement
+ }
+ return refreshControl.props
+}
+
function setQuery(
result: Partial>,
) {
@@ -104,6 +113,7 @@ function setQuery(
data: undefined,
isError: false,
isPending: false,
+ isRefetching: false,
refetch,
...result,
} as never)
@@ -165,7 +175,8 @@ describe('AtmosphereExploreTab', () => {
expect(screen.getByText('nux')).toBeTruthy()
expect(screen.getByText('banner:Launch')).toBeTruthy()
expect(screen.getByText('articles:Live article')).toBeTruthy()
- expect(screen.getByText('apps:Live app')).toBeTruthy()
+ /* Apps live in their own tab, even though the response includes them. */
+ expect(screen.queryByText(/^apps:/)).toBeNull()
expect(screen.queryByText(/^livestreams:/)).toBeNull()
expect(screen.queryByText(/^photos:/)).toBeNull()
expect(
@@ -207,7 +218,7 @@ describe('AtmosphereExploreTab', () => {
expect(screen.queryByText(/^articles:/)).toBeNull()
expect(screen.getByText(/^photos:/)).toBeTruthy()
expect(screen.getByText(/^livestreams:/)).toBeTruthy()
- expect(screen.getByText(/^apps:/)).toBeTruthy()
+ expect(screen.queryByText(/^apps:/)).toBeNull()
expect(screen.getByText(/^banner:/)).toBeTruthy()
})
@@ -268,4 +279,48 @@ describe('AtmosphereExploreTab', () => {
fireEvent.press(screen.getByTestId('retry'))
expect(refetch).toHaveBeenCalledTimes(1)
})
+
+ it.each([
+ ['loading', {isPending: true}],
+ ['error', {isError: true}],
+ ['loaded', {data}],
+ ])('shows the spinner only for a pull while %s', async (_name, result) => {
+ const refresh = createDeferrable()
+ refetch.mockReturnValueOnce(refresh.complete)
+ setQuery({...result, isRefetching: true})
+ render()
+
+ expect(getRefreshControlProps().refreshing).toBe(false)
+ act(() => {
+ void getRefreshControlProps().onRefresh?.()
+ })
+ expect(refetch).toHaveBeenCalledTimes(1)
+ expect(getRefreshControlProps().refreshing).toBe(true)
+
+ await act(async () => {
+ refresh.resolve()
+ await refresh.complete
+ })
+ expect(getRefreshControlProps().refreshing).toBe(false)
+ })
+
+ it('clears the pull spinner when refetch rejects', async () => {
+ const refresh = createDeferrable()
+ refetch.mockReturnValueOnce(refresh.complete)
+ setQuery({data})
+ render()
+
+ let completion: unknown
+ act(() => {
+ completion = getRefreshControlProps().onRefresh?.()
+ })
+ expect(getRefreshControlProps().refreshing).toBe(true)
+
+ await act(async () => {
+ refresh.reject(new Error('offline'))
+ await expect(completion).rejects.toThrow('offline')
+ })
+ expect(getRefreshControlProps().refreshing).toBe(false)
+ expect(screen.getByText('articles:Live article')).toBeTruthy()
+ })
})
diff --git a/src/screens/Atmosphere/components/AppCard.tsx b/src/screens/Atmosphere/components/AppCard.tsx
index 65d31e5c3..4d12c975b 100644
--- a/src/screens/Atmosphere/components/AppCard.tsx
+++ b/src/screens/Atmosphere/components/AppCard.tsx
@@ -1,15 +1,22 @@
import {View} from 'react-native'
import {Image} from 'expo-image'
-import {LinearGradient} from 'expo-linear-gradient'
import {useLingui} from '@lingui/react/macro'
+import {toNiceDomain} from '#/lib/strings/url-helpers'
+import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {type AtmosphereAppCardData} from '#/screens/Atmosphere/data/exploreData'
-import {atoms as a, utils} from '#/alf'
+import {atoms as a, tokens, useTheme} from '#/alf'
+import {
+ KnownFollowers,
+ shouldShowKnownFollowers,
+} from '#/components/KnownFollowers'
import {Link} from '#/components/Link'
import {Text} from '#/components/Typography'
export function AppCard({app}: {app: AtmosphereAppCardData}) {
const {t: l} = useLingui()
+ const t = useTheme()
+ const moderationOpts = useModerationOpts()
return (
- {app.backgroundImage ? (
+ {app.banner ? (
) : undefined}
- {app.overlayColor ? (
-
- ) : undefined}
+ style={[a.flex_row, a.w_full, a.gap_md, a.p_md, {paddingRight: 96}]}>
{app.logo ? (
) : undefined}
-
- {app.title}
-
- {app.description ? (
+
+
+ {app.title}
+ {' '}
+ style={[a.text_sm, t.atoms.text_contrast_medium]}
+ numberOfLines={1}>
+ • {toNiceDomain(app.href)}
+
+
+ {app.description ? (
+
{app.description}
) : undefined}
+ {/* KnownFollowers links internally, so it cannot nest inside the app link. */}
+ {app.profile &&
+ moderationOpts &&
+ shouldShowKnownFollowers(app.profile.viewer?.knownFollowers) ? (
+
+
+
+ ) : undefined}
)
}
diff --git a/src/screens/Atmosphere/data/__tests__/exploreData.test.ts b/src/screens/Atmosphere/data/__tests__/exploreData.test.ts
index 1331d8ac4..a105dbe95 100644
--- a/src/screens/Atmosphere/data/__tests__/exploreData.test.ts
+++ b/src/screens/Atmosphere/data/__tests__/exploreData.test.ts
@@ -1,6 +1,7 @@
import {exploreResponseFixture} from '#/screens/Atmosphere/__tests__/fixtures/exploreResponse'
import {livestreamPreviewFixture} from '#/screens/Atmosphere/__tests__/fixtures/livestreamPreview'
import {
+ type AtmosphereAppsData,
type AtmosphereData,
getAtmosphereAnnouncementBanner,
getAtmosphereApps,
@@ -25,6 +26,8 @@ const emptyData: AtmosphereData = {
apps: [],
}
+const emptyAppsData: AtmosphereAppsData = {apps: []}
+
const testProfile = {
$type: 'app.bsky.actor.defs#profileViewBasic',
did: 'did:plc:6ayddqghxhciedbaofoxkcbs',
@@ -271,18 +274,6 @@ describe('Atmosphere Explore response fixtures', () => {
authorProfile: {handle: 'author.test'},
})
- expect(getAtmosphereApps(fixtureData)).toEqual([
- {
- id: 'app',
- title: 'Test app',
- description: 'An app description',
- logo: 'https://example.com/app-logo.jpg',
- backgroundImage: 'https://example.com/app-background.jpg',
- overlayColor: '#123456',
- textColor: '#ffffff',
- href: 'https://example.com/app',
- },
- ])
expect(getAtmosphereAnnouncementBanner(fixtureData)).toEqual({
id: 'banner',
title: 'Test announcement',
@@ -423,7 +414,11 @@ describe('Atmosphere Explore response fixtures', () => {
livestreams: {items: livestreamPreviewFixture},
}).livestreams.items
const [publication] = fixtureData.publications.items
- const [firstApp] = fixtureData.apps
+ const firstApp = {
+ id: 'app',
+ title: 'Test app',
+ url: 'https://example.com/app' as const,
+ }
function twoOf(item: T) {
return {
@@ -459,13 +454,12 @@ describe('Atmosphere Explore response fixtures', () => {
it('in apps, keeping the first occurrence', () => {
const data = {
- ...emptyData,
apps: [
firstApp,
{...firstApp, id: 'other'},
{...firstApp, title: 'dupe'},
],
- } satisfies AtmosphereData
+ } satisfies AtmosphereAppsData
const result = getAtmosphereApps(data)
@@ -474,6 +468,132 @@ describe('Atmosphere Explore response fixtures', () => {
})
})
+ describe('getAtmosphereApps', () => {
+ const parseApps = (data: unknown): AtmosphereAppsData =>
+ app.bsky.unspecced.getAtmosphereApps.$output.schema.parse(data)
+
+ it('preserves the hydrated profile, logo and banner', () => {
+ const profile = {
+ did: testProfile.did,
+ handle: 'app.bsky.social',
+ viewer: {knownFollowers: {count: 1, followers: [testProfile]}},
+ }
+ const [card] = getAtmosphereApps(
+ parseApps({
+ apps: [
+ {
+ id: 'app',
+ title: 'Test app',
+ description: 'An app description',
+ logo: 'https://example.com/app-logo.jpg',
+ banner: 'https://example.com/app-banner.jpg',
+ url: 'https://example.com/app',
+ category: 'social',
+ profile,
+ },
+ ],
+ }),
+ )
+
+ expect(card).toEqual({
+ id: 'app',
+ title: 'Test app',
+ description: 'An app description',
+ logo: 'https://example.com/app-logo.jpg',
+ banner: 'https://example.com/app-banner.jpg',
+ href: 'https://example.com/app',
+ profile,
+ })
+ })
+
+ it('handles sparse and empty responses', () => {
+ expect(getAtmosphereApps(emptyAppsData)).toEqual([])
+ expect(
+ getAtmosphereApps(
+ parseApps({
+ apps: [
+ {id: 'sparse', title: 'Sparse app', url: 'https://example.com'},
+ ],
+ }),
+ ),
+ ).toEqual([
+ {
+ id: 'sparse',
+ title: 'Sparse app',
+ description: undefined,
+ logo: undefined,
+ banner: undefined,
+ href: 'https://example.com',
+ profile: undefined,
+ },
+ ])
+ })
+
+ it('validates the live response contract', () => {
+ expect(() => parseApps({apps: [{url: 'not a uri'}]})).toThrow()
+ })
+ })
+
+ describe('getAtmosphereApps categories', () => {
+ const url = 'https://example.com/app'
+ const data = {
+ apps: [
+ {id: 'writing', title: 'Writing', url, category: 'writing'},
+ {id: 'photo', title: 'Photo', url, category: 'photography'},
+ {id: 'video', title: 'Video', url, category: 'video'},
+ {id: 'feeds', title: 'Feeds', url, category: 'feeds'},
+ {id: 'games', title: 'Games', url, category: 'games'},
+ {id: 'social', title: 'Social', url, category: 'social'},
+ {id: 'dev', title: 'Dev', url, category: 'dev'},
+ {id: 'audio', title: 'Audio', url, category: 'audio'},
+ {id: 'events', title: 'Events', url, category: 'events'},
+ {id: 'utils', title: 'Utils', url, category: 'utils'},
+ {id: 'unknown', title: 'Unknown', url, category: 'new-category'},
+ {id: 'missing', title: 'Missing', url},
+ {id: 'invalid', title: '', url, category: 'writing'},
+ {id: 'writing', title: 'Duplicate', url, category: 'writing'},
+ ],
+ } satisfies AtmosphereAppsData
+
+ it('returns every valid app, including unknown and missing categories, without a category', () => {
+ expect(getAtmosphereApps(data).map(app => app.id)).toEqual([
+ 'writing',
+ 'photo',
+ 'video',
+ 'feeds',
+ 'games',
+ 'social',
+ 'dev',
+ 'audio',
+ 'events',
+ 'utils',
+ 'unknown',
+ 'missing',
+ ])
+ })
+
+ it.each([
+ ['writing', ['writing']],
+ ['photography', ['photo']],
+ ['video', ['video']],
+ ['feeds', ['feeds']],
+ ['games', ['games']],
+ ['social', ['social']],
+ ['dev', ['dev']],
+ ['audio', ['audio']],
+ ['events', ['events']],
+ ['utils', ['utils']],
+ ['empty', []],
+ ])(
+ 'filters raw category %s, still validating and deduping',
+ (category, ids) => {
+ expect(getAtmosphereApps(data, category).map(app => app.id)).toEqual(
+ ids,
+ )
+ },
+ )
+ })
+
it('adapts the active and ended local livestream previews', () => {
const previewData = parseData({
...emptyData,
@@ -534,7 +654,6 @@ describe('Atmosphere Explore response fixtures', () => {
href: 'https://example.com/announcement',
})
expect(getAtmosphereArticles(emptyData)).toEqual([])
- expect(getAtmosphereApps(emptyData)).toEqual([])
expect(getAtmosphereLivestreams(emptyData)).toEqual([])
expect(getAtmospherePhotos(emptyData)).toEqual([])
@@ -605,9 +724,6 @@ describe('Atmosphere Explore response fixtures', () => {
},
],
},
- apps: [
- {id: 'sparse-app', title: 'Sparse app', url: 'https://example.com'},
- ],
})
expect(getAtmosphereArticles(sparseData)[0]).toMatchObject({
@@ -628,18 +744,6 @@ describe('Atmosphere Explore response fixtures', () => {
},
])
expect(getAtmosphereLivestreams(sparseData)).toEqual([])
- expect(getAtmosphereApps(sparseData)).toEqual([
- {
- id: 'sparse-app',
- title: 'Sparse app',
- description: undefined,
- logo: undefined,
- backgroundImage: undefined,
- overlayColor: undefined,
- textColor: undefined,
- href: 'https://example.com',
- },
- ])
})
it('keeps associated profiles that omit $type and drops invalid ones', () => {
diff --git a/src/screens/Atmosphere/data/__tests__/useAtmosphereAppsQuery.test.tsx b/src/screens/Atmosphere/data/__tests__/useAtmosphereAppsQuery.test.tsx
new file mode 100644
index 000000000..213edfb7b
--- /dev/null
+++ b/src/screens/Atmosphere/data/__tests__/useAtmosphereAppsQuery.test.tsx
@@ -0,0 +1,146 @@
+import {type PropsWithChildren} from 'react'
+import {QueryClient, QueryClientProvider} from '@tanstack/react-query'
+import {act, renderHook, waitFor} from '@testing-library/react-native'
+
+import {useAppviewClient} from '#/state/session'
+import {useAtmosphereAppsQuery} from '#/screens/Atmosphere/data/useAtmosphereAppsQuery'
+import {app} from '#/lexicons'
+
+jest.mock('#/state/session', () => ({
+ useAppviewClient: jest.fn(),
+}))
+
+const data: app.bsky.unspecced.getAtmosphereApps.$OutputBody = {
+ apps: [{id: 'a', title: 'A', url: 'https://a.test', category: 'social'}],
+}
+const refreshed: app.bsky.unspecced.getAtmosphereApps.$OutputBody = {
+ apps: [{id: 'b', title: 'B', url: 'https://b.test', category: 'dev'}],
+}
+
+function setup(did: string | undefined = 'did:plc:viewer') {
+ const queryClient = new QueryClient()
+ const client = {did, call: jest.fn()}
+ jest.mocked(useAppviewClient).mockReturnValue(client as never)
+
+ const wrapper = ({children}: PropsWithChildren) => (
+ {children}
+ )
+
+ return {client, queryClient, wrapper}
+}
+
+/* The failed-refetch retry delay runs on a timer, so advance past it. */
+async function refetchAndFlush(refetch: () => Promise) {
+ await act(async () => {
+ const refetching = refetch()
+ await jest.advanceTimersByTimeAsync(5000)
+ await refetching
+ })
+}
+
+beforeEach(() => {
+ jest.clearAllMocks()
+ jest.useFakeTimers()
+})
+
+afterEach(() => {
+ jest.useRealTimers()
+})
+
+describe('useAtmosphereAppsQuery', () => {
+ it('calls the generated query once with no params, language, or category', async () => {
+ const {client, wrapper} = setup()
+ client.call.mockResolvedValue(data)
+
+ const {result} = renderHook(() => useAtmosphereAppsQuery(), {wrapper})
+ await waitFor(() => expect(result.current.isSuccess).toBe(true))
+
+ expect(result.current.data).toBe(data)
+ expect(client.call).toHaveBeenCalledTimes(1)
+ expect(client.call).toHaveBeenCalledWith(
+ app.bsky.unspecced.getAtmosphereApps,
+ {},
+ {signal: expect.any(AbortSignal)},
+ )
+ })
+
+ it('shares an in-flight request and refetches cached data on remount', async () => {
+ const {client, queryClient, wrapper} = setup()
+ client.call.mockResolvedValue(data)
+
+ const first = renderHook(
+ () => [useAtmosphereAppsQuery(), useAtmosphereAppsQuery()],
+ {wrapper},
+ )
+ await waitFor(() => expect(first.result.current[0].isSuccess).toBe(true))
+ expect(first.result.current[1].data).toBe(data)
+ expect(client.call).toHaveBeenCalledTimes(1)
+ first.unmount()
+
+ const second = renderHook(() => useAtmosphereAppsQuery(), {wrapper})
+ expect(second.result.current.data).toBe(data)
+ await waitFor(() => expect(client.call).toHaveBeenCalledTimes(2))
+ expect(queryClient.getQueryCache().getAll()).toHaveLength(1)
+ })
+
+ it.each(['did:plc:two', undefined])(
+ 'isolates the cache for viewer %s',
+ async did => {
+ const {client, queryClient, wrapper} = setup('did:plc:one')
+ client.call.mockResolvedValue(data)
+
+ const first = renderHook(() => useAtmosphereAppsQuery(), {wrapper})
+ await waitFor(() => expect(first.result.current.isSuccess).toBe(true))
+ first.unmount()
+
+ jest
+ .mocked(useAppviewClient)
+ .mockReturnValue({did, call: client.call} as never)
+ const second = renderHook(() => useAtmosphereAppsQuery(), {wrapper})
+ await waitFor(() => expect(second.result.current.isSuccess).toBe(true))
+
+ expect(client.call).toHaveBeenCalledTimes(2)
+ expect(queryClient.getQueryCache().getAll()).toHaveLength(2)
+ },
+ )
+
+ it('retries once, then recovers on an explicit refetch', async () => {
+ const {client, wrapper} = setup()
+ client.call.mockRejectedValue(new Error('offline'))
+
+ const {result} = renderHook(() => useAtmosphereAppsQuery(), {wrapper})
+ await act(async () => {
+ await jest.advanceTimersByTimeAsync(5000)
+ })
+ await waitFor(() => expect(result.current.isError).toBe(true))
+ expect(result.current.data).toBeUndefined()
+ expect(client.call).toHaveBeenCalledTimes(2)
+
+ client.call.mockResolvedValue(data)
+ await refetchAndFlush(result.current.refetch)
+
+ expect(result.current.data).toBe(data)
+ expect(client.call).toHaveBeenCalledTimes(3)
+ })
+
+ it('updates every consumer on an explicit refetch and keeps data when it fails', async () => {
+ const {client, wrapper} = setup()
+ client.call.mockResolvedValueOnce(data).mockResolvedValueOnce(refreshed)
+
+ const {result} = renderHook(
+ () => [useAtmosphereAppsQuery(), useAtmosphereAppsQuery()],
+ {wrapper},
+ )
+ await waitFor(() => expect(result.current[0].isSuccess).toBe(true))
+
+ await refetchAndFlush(result.current[0].refetch)
+ expect(result.current[0].data).toEqual(refreshed)
+ expect(result.current[1].data).toEqual(refreshed)
+
+ client.call.mockRejectedValue(new Error('offline'))
+ await refetchAndFlush(result.current[1].refetch)
+ expect(result.current[0].isError).toBe(true)
+ expect(result.current[0].data).toEqual(refreshed)
+ expect(result.current[1].data).toEqual(refreshed)
+ })
+})
diff --git a/src/screens/Atmosphere/data/__tests__/useAtmosphereExploreQuery.test.tsx b/src/screens/Atmosphere/data/__tests__/useAtmosphereExploreQuery.test.tsx
index c53a13809..97841fa5a 100644
--- a/src/screens/Atmosphere/data/__tests__/useAtmosphereExploreQuery.test.tsx
+++ b/src/screens/Atmosphere/data/__tests__/useAtmosphereExploreQuery.test.tsx
@@ -1,6 +1,6 @@
import {type PropsWithChildren} from 'react'
import {QueryClient, QueryClientProvider} from '@tanstack/react-query'
-import {renderHook, waitFor} from '@testing-library/react-native'
+import {act, renderHook, waitFor} from '@testing-library/react-native'
import {useLanguagePrefs} from '#/state/preferences/languages'
import {useAppviewClient} from '#/state/session'
@@ -29,10 +29,12 @@ function setLanguages(contentLanguages: string[]) {
.mockReturnValue({contentLanguages} as ReturnType)
}
-function setup(did: string | undefined = 'did:plc:viewer') {
- const queryClient = new QueryClient({
+function setup(
+ did: string | undefined = 'did:plc:viewer',
+ queryClient = new QueryClient({
defaultOptions: {queries: {gcTime: Infinity, retry: false}},
- })
+ }),
+) {
const client = {did, call: jest.fn()}
jest.mocked(useAppviewClient).mockReturnValue(client as never)
setLanguages(['en'])
@@ -137,20 +139,6 @@ describe('useAtmosphereExploreQuery', () => {
expect(result.current.data?.articles.recIdStr).toBe('18446744073709551615')
})
- it('reuses cached data before the stale time elapses', async () => {
- const {client, queryClient, wrapper} = setup()
- client.call.mockResolvedValue(data)
-
- const first = renderHook(() => useAtmosphereExploreQuery(), {wrapper})
- await waitFor(() => expect(first.result.current.isSuccess).toBe(true))
- first.unmount()
-
- const second = renderHook(() => useAtmosphereExploreQuery(), {wrapper})
- expect(second.result.current.data).toBe(data)
- expect(client.call).toHaveBeenCalledTimes(1)
- expect(queryClient.getQueryCache().getAll()).toHaveLength(1)
- })
-
it.each(['did:plc:two', undefined])(
'isolates the cache for viewer %s',
async did => {
@@ -218,4 +206,84 @@ describe('useAtmosphereExploreQuery', () => {
expect(result.current.data).toBe(data)
expect(client.call).toHaveBeenCalledTimes(3)
})
+
+ describe('cache and refresh', () => {
+ const refreshed = {
+ ...data,
+ apps: [{id: 'a', title: 'A', url: 'https://a.test'}],
+ }
+
+ function setupDefaults() {
+ return setup('did:plc:viewer', new QueryClient())
+ }
+
+ /*
+ * Notifications and the failed-refetch retry delay both run on timers, so
+ * advance past them instead of waiting in real time.
+ */
+ async function refetchAndFlush(refetch: () => Promise) {
+ await act(async () => {
+ const refetching = refetch()
+ await jest.advanceTimersByTimeAsync(5000)
+ await refetching
+ })
+ }
+
+ beforeEach(() => {
+ jest.useFakeTimers()
+ })
+
+ afterEach(() => {
+ jest.useRealTimers()
+ })
+
+ it('coalesces concurrent consumers into one request', async () => {
+ const {client, wrapper} = setupDefaults()
+ client.call.mockResolvedValue(data)
+
+ const {result} = renderHook(
+ () => [useAtmosphereExploreQuery(), useAtmosphereExploreQuery()],
+ {wrapper},
+ )
+ await waitFor(() => expect(result.current[0].isSuccess).toBe(true))
+
+ expect(client.call).toHaveBeenCalledTimes(1)
+ expect(result.current[1].data).toBe(data)
+ })
+
+ it('shows cached data and refetches on remount', async () => {
+ const {client, queryClient, wrapper} = setup()
+ client.call.mockResolvedValue(data)
+
+ const first = renderHook(() => useAtmosphereExploreQuery(), {wrapper})
+ await waitFor(() => expect(first.result.current.isSuccess).toBe(true))
+ first.unmount()
+
+ const second = renderHook(() => useAtmosphereExploreQuery(), {wrapper})
+ expect(second.result.current.data).toBe(data)
+ await waitFor(() => expect(client.call).toHaveBeenCalledTimes(2))
+ expect(queryClient.getQueryCache().getAll()).toHaveLength(1)
+ })
+
+ it('updates every consumer on an explicit refetch and keeps data when it fails', async () => {
+ const {client, wrapper} = setupDefaults()
+ client.call.mockResolvedValueOnce(data).mockResolvedValueOnce(refreshed)
+
+ const {result} = renderHook(
+ () => [useAtmosphereExploreQuery(), useAtmosphereExploreQuery()],
+ {wrapper},
+ )
+ await waitFor(() => expect(result.current[0].isSuccess).toBe(true))
+
+ await refetchAndFlush(result.current[0].refetch)
+ expect(result.current[0].data).toEqual(refreshed)
+ expect(result.current[1].data).toEqual(refreshed)
+
+ client.call.mockRejectedValue(new Error('offline'))
+ await refetchAndFlush(result.current[1].refetch)
+ expect(result.current[0].isError).toBe(true)
+ expect(result.current[0].data).toEqual(refreshed)
+ expect(result.current[1].data).toEqual(refreshed)
+ })
+ })
})
diff --git a/src/screens/Atmosphere/data/exploreData.ts b/src/screens/Atmosphere/data/exploreData.ts
index 5fc0f1c1d..de949d500 100644
--- a/src/screens/Atmosphere/data/exploreData.ts
+++ b/src/screens/Atmosphere/data/exploreData.ts
@@ -6,6 +6,8 @@ import * as bsky from '#/types/bsky'
export type AtmosphereData =
app.bsky.unspecced.getAtmosphereExploreTab.$OutputBody
+export type AtmosphereAppsData =
+ app.bsky.unspecced.getAtmosphereApps.$OutputBody
type AtmosphereProfileView = l.InferOutput<
typeof app.bsky.actor.defs.profileViewBasic
@@ -34,10 +36,9 @@ export type AtmosphereAppCardData = {
title: string
description?: string
logo?: string
- backgroundImage?: string
- overlayColor?: string
- textColor?: string
+ banner?: string
href: string
+ profile?: app.bsky.actor.defs.ProfileViewDetailed
}
export type AtmosphereAnnouncementBannerData = {
@@ -169,12 +170,19 @@ export function getAtmospherePublications(
)
}
+/**
+ * Returns the valid apps, optionally limited to a raw backend `category`.
+ * Omit `category` for all apps, including those with a missing or unknown
+ * category.
+ */
export function getAtmosphereApps(
- data: AtmosphereData,
+ data: AtmosphereAppsData,
+ category?: string,
): AtmosphereAppCardData[] {
return dedupeById(
data.apps.flatMap(app => {
if (!app.id || !app.title || !app.url) return []
+ if (category !== undefined && app.category !== category) return []
return [
{
@@ -182,10 +190,9 @@ export function getAtmosphereApps(
title: app.title,
description: app.description || undefined,
logo: app.logo,
- backgroundImage: app.backgroundImage,
- overlayColor: app.overlayColor,
- textColor: app.textColor,
+ banner: app.banner,
href: app.url,
+ profile: app.profile,
},
]
}),
diff --git a/src/screens/Atmosphere/data/useAtmosphereAppsQuery.ts b/src/screens/Atmosphere/data/useAtmosphereAppsQuery.ts
new file mode 100644
index 000000000..d6b1ca0c1
--- /dev/null
+++ b/src/screens/Atmosphere/data/useAtmosphereAppsQuery.ts
@@ -0,0 +1,22 @@
+import {useQuery} from '@tanstack/react-query'
+
+import {createQueryKey} from '#/state/queries/util'
+import {useAppviewClient} from '#/state/session'
+import {app} from '#/lexicons'
+
+export const useAtmosphereAppsQueryRoot = 'useAtmosphereAppsQuery'
+
+/**
+ * Fetches the full curated apps catalog. The endpoint also accepts a
+ * `category`, but we omit it and filter the response in memory instead.
+ */
+export function useAtmosphereAppsQuery() {
+ const client = useAppviewClient()
+
+ return useQuery({
+ queryKey: createQueryKey(useAtmosphereAppsQueryRoot, {did: client.did}),
+ retry: 1,
+ queryFn: ({signal}) =>
+ client.call(app.bsky.unspecced.getAtmosphereApps, {}, {signal}),
+ })
+}
diff --git a/src/screens/Atmosphere/data/useAtmosphereExploreQuery.ts b/src/screens/Atmosphere/data/useAtmosphereExploreQuery.ts
index 36099f347..3c09deb5d 100644
--- a/src/screens/Atmosphere/data/useAtmosphereExploreQuery.ts
+++ b/src/screens/Atmosphere/data/useAtmosphereExploreQuery.ts
@@ -1,7 +1,6 @@
import {useQuery} from '@tanstack/react-query'
import {useLanguagePrefs} from '#/state/preferences/languages'
-import {STALE} from '#/state/queries'
import {createQueryKey} from '#/state/queries/util'
import {useAppviewClient} from '#/state/session'
import {app} from '#/lexicons'
@@ -18,7 +17,6 @@ export function useAtmosphereExploreQuery() {
did: client.did,
acceptLanguage,
}),
- staleTime: STALE.MINUTES.FIVE,
retry: 1,
queryFn: ({signal}) =>
client.call(
diff --git a/src/screens/Atmosphere/index.tsx b/src/screens/Atmosphere/index.tsx
index 973becd5b..4c208d3bd 100644
--- a/src/screens/Atmosphere/index.tsx
+++ b/src/screens/Atmosphere/index.tsx
@@ -9,6 +9,7 @@ import {BetaTag} from '#/components/BetaTag'
import * as Layout from '#/components/Layout'
import {useAnalytics} from '#/analytics'
import {AtmosphereActivityTab} from './ActivityTab'
+import {AtmosphereAppsTab} from './AppsTab'
import {AtmosphereExploreTab} from './ExploreTab'
export function AtmosphereScreen() {
@@ -40,11 +41,12 @@ export function AtmosphereScreen() {
testID="atmospherePager"
renderTabBar={props => (
-
+
)}>
+
)
diff --git a/src/screens/Notifications/components/TabPills.tsx b/src/screens/Notifications/components/TabPills.tsx
index 09ac75756..9a20b1a93 100644
--- a/src/screens/Notifications/components/TabPills.tsx
+++ b/src/screens/Notifications/components/TabPills.tsx
@@ -1,4 +1,4 @@
-import {useEffect, useLayoutEffect, useRef, useState} from 'react'
+import {useCallback, useEffect, useLayoutEffect, useRef, useState} from 'react'
import {
PixelRatio,
Pressable,
@@ -41,6 +41,7 @@ export function TabPills({
onSelectTab,
contentContainerStyle,
gutterWidth = tokens.space.lg,
+ getAccessibilityHint,
}: {
tabs: TabPillItem[]
selectedTab: string
@@ -48,6 +49,8 @@ export function TabPills({
onSelectTab: (tab: string) => void
contentContainerStyle?: StyleProp
gutterWidth?: number
+ /** Defaults to a hint that the tab shows notifications. */
+ getAccessibilityHint?: (tab: TabPillItem) => string
}) {
const t = useTheme()
const {t: l} = useLingui()
@@ -63,14 +66,21 @@ export function TabPills({
const tabLayoutKey = tabs.map(tab => `${tab.key}:${tab.label}`).join('|')
const tabCount = tabs.length
- useLayoutEffect(() => {
+ /*
+ * Also runs on layout events, since the whole bar can be mounted hidden
+ * (e.g. `display: none` in an inactive web pager page) and only get real
+ * dimensions when revealed, without re-rendering. Hidden measurements are
+ * all zero, so they're skipped rather than overwriting the last good ones.
+ */
+ const measure = useCallback(() => {
const viewportRect = listRef.current?.getBoundingClientRect()
const contentRect = contentRef.current?.getBoundingClientRect()
if (!viewportRect || !contentRect) return
+ if (!hasSize(viewportRect) || !hasSize(contentRect)) return
const layouts = Array.from({length: tabCount}, (_, index) => {
const rect = tabRefs.current[index]?.getBoundingClientRect()
- if (!rect) return null
+ if (!rect || !hasSize(rect)) return null
return {
x: rect.left - contentRect.left,
y: rect.top - contentRect.top,
@@ -101,7 +111,11 @@ export function TabPills({
})
}
didMeasure.current = true
- }, [selectedTab, tabLayoutKey, tabCount, tabs, windowWidth])
+ }, [selectedTab, tabCount, tabs])
+
+ useLayoutEffect(() => {
+ measure()
+ }, [measure, tabLayoutKey, windowWidth])
function handleSelectTab(index: number) {
const tab = tabs[index]
@@ -219,6 +233,7 @@ export function TabPills({
))}
{tabOffsets.map((layout, index) => (
@@ -389,23 +407,29 @@ function TabPill({
tab,
active,
index,
+ onLayout,
onSelectTab,
+ getAccessibilityHint,
}: {
elementRef: React.Ref>
tab: TabPillItem
active: boolean
index: number
+ onLayout: () => void
onSelectTab: (index: number) => void
+ getAccessibilityHint?: (tab: TabPillItem) => string
}) {
const {t: l} = useLingui()
return (
-
+
onSelectTab(index)}
@@ -436,6 +460,11 @@ type PillLayout = {
height: number
}
+/** Hidden (`display: none`) or detached nodes measure as all zeros. */
+function hasSize(rect: {width: number; height: number}) {
+ return rect.width > 0 && rect.height > 0
+}
+
function areLayoutsEqual(a: PillLayout[], b: PillLayout[]) {
return (
a.length === b.length &&