diff --git a/src/components/BottomBar.js b/src/components/BottomBar.js
index f3f8d07..bc8c68b 100644
--- a/src/components/BottomBar.js
+++ b/src/components/BottomBar.js
@@ -12,13 +12,13 @@ const BottomBar = () => {
return (
router.push('/')} className={`cursor-pointer p-2 rounded-lg ${isActive('/') ? 'bg-gray-700' : ''}`}>
-
+
router.push('/content')} className={`cursor-pointer p-2 rounded-lg ${isActive('/content') ? 'bg-gray-700' : ''}`}>
-
+
router.push('/feed')} className={`cursor-pointer p-2 rounded-lg ${isActive('/feed') ? 'bg-gray-700' : ''}`}>
-
+
);
diff --git a/src/pages/api/stackernews.js b/src/pages/api/stackernews.js
new file mode 100644
index 0000000..f313bf7
--- /dev/null
+++ b/src/pages/api/stackernews.js
@@ -0,0 +1,37 @@
+import axios from 'axios';
+
+export default async function handler(req, res) {
+ try {
+ const response = await axios.post('https://stacker.news/api/graphql', {
+ query: `
+ query RecentItems {
+ items(
+ limit: 10,
+ sort: "NEW"
+ ) {
+ items {
+ id
+ title
+ url
+ createdAt
+ user {
+ name
+ }
+ sats
+ }
+ }
+ }
+ `
+ }, {
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ }
+ });
+
+ res.status(200).json(response.data);
+ } catch (error) {
+ console.error('Error fetching from Stacker News:', error.response ? error.response.data : error.message);
+ res.status(500).json({ error: 'An error occurred while fetching data' });
+ }
+}
diff --git a/src/pages/feed/index.js b/src/pages/feed/index.js
index 31a048f..87cada1 100644
--- a/src/pages/feed/index.js
+++ b/src/pages/feed/index.js
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import { InputText } from 'primereact/inputtext';
import CommunityMenuTab from '@/components/menutab/CommunityMenuTab';
import NostrFeed from './nostr';
@@ -18,8 +18,13 @@ const Feed = () => {
router.push(`/feed?channel=${topic}`);
};
+ // initialize the selected topic to the query parameter
+ useEffect(() => {
+ setSelectedTopic(router.query.channel);
+ }, [router.query.channel]);
+
return (
-
+
Community
{
+ const response = await axios.get('/api/stackernews');
+ return response.data.data.items.items; // Note the change here
+};
const StackerNewsFeed = () => {
- const router = useRouter();
- const { data, error, isLoading } = useDiscordQuery({page: router.query.page});
+ const { data: items, isLoading, error } = useQuery({queryKey: ['stackerNews'], queryFn: fetchStackerNews});
- if (isLoading) {
- return (
-
- );
- }
+ if (isLoading) {
+ return (
+
+ );
+ }
- if (error) {
- return Failed to load messages. Please try again later.
;
- }
+ if (error) {
+ console.error('Error fetching Stacker News:', error);
+ return Error loading data. Please try again later.
;
+ }
- const header = (message) => (
-
- );
-
- const footer = (message) => (
-
-
- {new Date(message.timestamp).toLocaleString()}
-
-
- );
-
- return (
-
-
- {data && data.length > 0 ? (
- data.map(message => (
-
header(message)}
- footer={() => footer(message)}
- className="w-full bg-gray-700 shadow-lg hover:shadow-xl transition-shadow duration-300 mb-4"
- >
- {message.content}
-
- ))
- ) : (
-
No messages available.
- )}
-
-
- );
+ return (
+
+
+ {items && items.length > 0 ? (
+ items.map(item => (
+
+ {item.title}
+ Posted by: {item.user.name}
+
+ Comments: {item.commentCount} | Sats: {item.sats}
+
+
+ Created at: {new Date(item.createdAt).toLocaleString()}
+
+ {item.url && (
+
+ View on Stacker News
+
+ )}
+
+ ))
+ ) : (
+
No items available.
+ )}
+
+
+ );
};
export default StackerNewsFeed;
\ No newline at end of file