Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News Navigator Plugin #2557

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lucifergene
Copy link

Signed-off-by: Avik Kundu [email protected]

New year, new plugin 🎉

Introducing the News Navigator plugin!

This simple plugin helps you stay informed with the latest news updates across categories like sports, politics, technology, and more. Why would you want a news plugin, you ask? Staying up to date is crucial in today’s fast-paced world, and this plugin makes it easy to explore top stories or dive deep into specific topics with keyword-based searches. Whether you’re catching up on headlines or exploring trends, this tool keeps you in the know.

Tab-22-01-2025_00_12.mp4

Future Work / Enhancement Ideas

  • Implement caching to reduce API calls
  • Store recently searched topics/keywords
  • Add location-based niche headlines
  • Enable user preferences for favorite categories
  • Introduce push notifications for breaking news

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@Lucifergene Lucifergene requested review from backstage-service and a team as code owners January 21, 2025 18:56
@Lucifergene Lucifergene requested a review from nickboldt January 21, 2025 18:56
@Lucifergene Lucifergene changed the title Initial version showing news and allow searching topics News Navigator Plugin Jan 21, 2025
@backstage-goalie
Copy link
Contributor

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage-community/plugin-news-navigator-backend workspaces/news-navigator/plugins/news-navigator-backend major v0.0.0
@backstage-community/plugin-news-navigator workspaces/news-navigator/plugins/news-navigator major v0.0.0

Copy link
Member

@christoph-jerolimov christoph-jerolimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Lucifergene, thanks for that plugin!

To be honest, I'm not sure if this is a plugin for this community. That's a topic on it's own...

Or if it's possible to support multiple news providers.

But I like to share some feedback on your code anyway.

To be transparent: I worked with @Lucifergene before and shared most if this feedback in a short call already.

Comment on lines +12 to +13
csp:
connect-src: ["'self'", 'http:', 'https:']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one of the reasons I'm unsure if backstage is a good candidate to have this as a plugin. Maybe it's an option to build this as an entire app (think of it as a container image) where users just need one enviroment variable to have a news app running?

You can also drop all other parts like catalog, search, kubernetes from that app. Just an idea.

"scripts": {
"dev": "yarn workspaces foreach -A --include @backstage-community/plugin-news-navigator-backend --include @backstage-community/plugin-news-navigator --parallel -v -i run start",
"tsc": "tsc",
"tsc:full": "tsc --skipLibCheck false --incremental false",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your build fails with an backstage/cli TS issue. You might want ignore node_modules from type checks:

Suggested change
"tsc:full": "tsc --skipLibCheck false --incremental false",
"tsc:full": "tsc --skipLibCheck true --incremental false",

* Configuration for the NewsAPI plugin.
* @visibility secret
*/
newsAPI?: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious that this is newsAPI and not News navigator. I would expect that both matches, also if this isn't required.

"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"newsapi": "^2.4.1",
"zod": "^3.22.4"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you doesn't use zod, or?

return newsapi.v2
.topHeadlines({
category,
country: 'us',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you want make that configurable in the app-config.yaml as well?

Comment on lines +100 to +107
{[
{ path: '/', title: 'General' },
{ path: '/science', title: 'Science' },
{ path: '/technology', title: 'Technology' },
{ path: '/health', title: 'Health' },
{ path: '/sports', title: 'Sports' },
{ path: '/business', title: 'Business' },
{ path: '/entertainment', title: 'Entertainment' },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you want allow users to specify which categories are shown? With this as default of course.

Comment on lines +73 to +80
const { data, isError, isLoading, isRefetching } = useQuery({
queryKey: category ? ['category-news'] : ['search-news'],
queryFn: () =>
category
? newsApi.getNewsByCategory(category)
: newsApi.searchNewsByKeyword(keyword),
staleTime: 30 * 60 * 1000, // Cache data for 30 minutes
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is your issue that you're code needs to invalidate data. You should use the category and keyword value as part of the queryKey, like:

Suggested change
const { data, isError, isLoading, isRefetching } = useQuery({
queryKey: category ? ['category-news'] : ['search-news'],
queryFn: () =>
category
? newsApi.getNewsByCategory(category)
: newsApi.searchNewsByKeyword(keyword),
staleTime: 30 * 60 * 1000, // Cache data for 30 minutes
});
const { data, isError, isLoading, isRefetching } = useQuery({
queryKey: category ? ['category-news', category] : ['search-news', keyword],
queryFn: () =>
category
? newsApi.getNewsByCategory(category)
: newsApi.searchNewsByKeyword(keyword),
staleTime: 30 * 60 * 1000, // Cache data for 30 minutes
});

staleTime: 30 * 60 * 1000, // Cache data for 30 minutes
});

if (isLoading || isRefetching) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not jump back to the progress indicator when refetching happen, but that might be just an optinion:

Suggested change
if (isLoading || isRefetching) {
if (isLoading) {

const handleKeyPress = (event: { key: string }) => {
if (event.key === 'Enter') {
setSearchSubmitted(true);
queryClient.invalidateQueries({ queryKey: ['search-news'] });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be needed, see comment above.

Suggested change
queryClient.invalidateQueries({ queryKey: ['search-news'] });

Comment on lines +52 to +53
const [searchText, setSearchText] = useState('');
const [searchSubmitted, setSearchSubmitted] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of useState I like to recommend useQueryParamState from Backstage core-components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants