mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-05-18 04:05:51 +00:00
Imrpovements to discord message pulling
This commit is contained in:
parent
1ee4dfe84e
commit
f53f23b939
@ -38,16 +38,16 @@ const Sidebar = () => {
|
|||||||
className="unstyled border-none bg-transparent">
|
className="unstyled border-none bg-transparent">
|
||||||
<AccordionTab header={"Community"}>
|
<AccordionTab header={"Community"}>
|
||||||
<div onClick={() => router.push('/feed')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/feed') ? 'bg-gray-700' : ''}`}>
|
<div onClick={() => router.push('/feed')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/feed') ? 'bg-gray-700' : ''}`}>
|
||||||
<p className="rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> global</p>
|
<p className="pl-2 rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> global</p>
|
||||||
</div>
|
</div>
|
||||||
<div onClick={() => router.push('/chat/nostr')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/chat/nostr') ? 'bg-gray-700' : ''}`}>
|
<div onClick={() => router.push('/chat/nostr')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/chat/nostr') ? 'bg-gray-700' : ''}`}>
|
||||||
<p className="rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> nostr</p>
|
<p className="pl-2 rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> nostr</p>
|
||||||
</div>
|
</div>
|
||||||
<div onClick={() => router.push('/chat/discord')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/chat/discord') ? 'bg-gray-700' : ''}`}>
|
<div onClick={() => router.push('/chat/discord')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/chat/discord') ? 'bg-gray-700' : ''}`}>
|
||||||
<p className="rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> discord</p>
|
<p className="pl-2 rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> discord</p>
|
||||||
</div>
|
</div>
|
||||||
<div onClick={() => router.push('/chat/stackernews')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/chat/stackernews') ? 'bg-gray-700' : ''}`}>
|
<div onClick={() => router.push('/chat/stackernews')} className={`w-full cursor-pointer py-2 my-2 hover:bg-gray-700 rounded-lg ${isActive('/chat/stackernews') ? 'bg-gray-700' : ''}`}>
|
||||||
<p className="rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> stackernews</p>
|
<p className="pl-2 rounded-md font-bold"><i className="pi pi-hashtag text-sm"></i> stackernews</p>
|
||||||
</div>
|
</div>
|
||||||
</AccordionTab>
|
</AccordionTab>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
@ -40,14 +40,20 @@ export default async function handler(req, res) {
|
|||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
||||||
const messagesArray = await Promise.all(messagesPromises);
|
const results = await Promise.allSettled(messagesPromises);
|
||||||
const messages = messagesArray.flat();
|
const messages = results
|
||||||
|
.filter(result => result.status === 'fulfilled')
|
||||||
|
.flatMap(result => result.value);
|
||||||
|
|
||||||
const filteredMessages = messages.filter(msg => msg.content.length > 0);
|
const filteredMessages = messages.filter(msg => msg.content.length > 0);
|
||||||
filteredMessages.sort((a, b) => b.timestamp - a.timestamp);
|
filteredMessages.sort((a, b) => b.timestamp - a.timestamp);
|
||||||
|
|
||||||
res.setHeader('Cache-Control', 's-maxage=60, stale-while-revalidate');
|
if (filteredMessages.length === 0) {
|
||||||
res.status(200).json(filteredMessages.slice(0, 50));
|
res.status(204).end(); // No Content
|
||||||
|
} else {
|
||||||
|
res.setHeader('Cache-Control', 's-maxage=60, stale-while-revalidate');
|
||||||
|
res.status(200).json(filteredMessages.slice(0, 50));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
res.status(500).json({ error: 'An error occurred while fetching messages' });
|
res.status(500).json({ error: 'An error occurred while fetching messages' });
|
||||||
|
@ -133,16 +133,20 @@ const Feed = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="mx-4 mt-4">
|
<div className="mx-4 mt-4">
|
||||||
{data && data.map(message => (
|
{data && data.length > 0 ? (
|
||||||
<Card
|
data.map(message => (
|
||||||
key={message.id}
|
<Card
|
||||||
header={() => header(message)}
|
key={message.id}
|
||||||
footer={() => footer(message)}
|
header={() => header(message)}
|
||||||
className="w-full bg-gray-700 shadow-lg hover:shadow-xl transition-shadow duration-300 mb-4"
|
footer={() => footer(message)}
|
||||||
>
|
className="w-full bg-gray-700 shadow-lg hover:shadow-xl transition-shadow duration-300 mb-4"
|
||||||
<p className="m-0 text-lg text-gray-200">{message.content}</p>
|
>
|
||||||
</Card>
|
<p className="m-0 text-lg text-gray-200">{message.content}</p>
|
||||||
))}
|
</Card>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="text-gray-400 text-center p-4">No messages available.</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user