|
| 1 | +--- |
| 2 | +title: Headlines Feed |
| 3 | +description: Learn how the main news feed is managed, including filtering and dynamic content. |
| 4 | +--- |
| 5 | +import { Card, CardGrid } from '@astrojs/starlight/components'; |
| 6 | + |
| 7 | +The Headlines Feed is the core feature of the mobile client, providing users with a scrollable list of news articles. It is a sophisticated system that supports pagination, pull-to-refresh, complex filtering, and dynamic content injection. |
| 8 | + |
| 9 | +## Core Components |
| 10 | + |
| 11 | +The feed is managed by a collection of BLoCs that handle different aspects of its functionality. |
| 12 | + |
| 13 | +- **`HeadlinesFeedBloc`**: The central BLoC that manages the state of the main feed. It is responsible for fetching headlines from the `HeadlinesRepository`, handling pagination (`HeadlinesFeedFetchRequested`), and applying filters (`HeadlinesFeedFiltersApplied`). |
| 14 | + |
| 15 | +- **`FeedInjectorService`**: A crucial service that dynamically injects non-headline content, such as advertisements (`Ad`) and account-related calls-to-action (`FeedAction`), into the list of headlines. It uses business logic based on the user's status and remote configuration to determine where and when to place this content. |
| 16 | + |
| 17 | +- **Filter BLoCs**: A set of specialized BLoCs manage the state for the filter selection pages: |
| 18 | + - `TopicsFilterBloc`: Fetches and manages the list of available topics for filtering. |
| 19 | + - `SourcesFilterBloc`: Manages the complex logic for filtering by source, which also includes sub-filters for country and source type. |
| 20 | + - `CountriesFilterBloc`: Fetches and manages the list of countries for filtering. |
| 21 | + |
| 22 | +## Key Functionalities |
| 23 | + |
| 24 | +<CardGrid> |
| 25 | + <Card title="Infinite Scrolling" icon="arrow-down"> |
| 26 | + The feed uses pagination to load headlines continuously as the user scrolls. The `_onScroll` listener in `HeadlinesFeedPage` detects when the user is near the bottom of the list and dispatches a `HeadlinesFeedFetchRequested` event to load the next page of content. |
| 27 | + </Card> |
| 28 | + <Card title="Pull-to-Refresh" icon="refresh"> |
| 29 | + Users can pull down from the top of the feed to refresh the content. This action triggers a `HeadlinesFeedRefreshRequested` event, which re-fetches the first page of headlines with the currently active filters. |
| 30 | + </Card> |
| 31 | + <Card title="Advanced Filtering" icon="filter"> |
| 32 | + Users can tap the filter icon in the AppBar to open the `HeadlinesFilterPage`. This page allows them to apply filters based on topics and sources. A unique feature is the "Apply my followed items" checkbox, which automatically creates a filter based on the user's followed topics and sources. |
| 33 | + </Card> |
| 34 | + <Card title="Dynamic Content" icon="add-circle"> |
| 35 | + The `FeedInjectorService` intelligently inserts ads and calls-to-action (e.g., "Link your account") into the feed. This logic is based on rules defined in the `RemoteConfig`, such as ad frequency per user role, ensuring a tailored experience. |
| 36 | + </Card> |
| 37 | +</CardGrid> |
0 commit comments