plebdevs/src/components/feeds/DiscordFeed.js

51 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-09-10 15:44:08 -05:00
import React from 'react';
2024-09-01 20:29:33 -05:00
import { ProgressSpinner } from 'primereact/progressspinner';
2024-09-02 12:09:27 -05:00
import { useDiscordQuery } from '@/hooks/communityQueries/useDiscordQuery';
import { useRouter } from 'next/router';
2024-09-09 15:56:51 -05:00
import { highlightText } from '@/utils/text';
2024-09-10 15:44:08 -05:00
import CommunityMessage from '@/components/feeds/messages/CommunityMessage';
import useWindowWidth from '@/hooks/useWindowWidth';
2024-09-01 22:16:44 -05:00
2024-09-09 15:56:51 -05:00
const DiscordFeed = ({ searchQuery }) => {
2024-09-02 12:09:27 -05:00
const router = useRouter();
const { data, error, isLoading } = useDiscordQuery({page: router.query.page});
2024-09-10 15:44:08 -05:00
const windowWidth = useWindowWidth();
2024-09-02 12:09:27 -05:00
2024-09-01 20:29:33 -05:00
if (isLoading) {
2024-09-02 12:09:27 -05:00
return (
2024-09-06 16:57:27 -05:00
<div className="h-[100vh] min-bottom-bar:w-[86vw] max-sidebar:w-[100vw]">
2024-09-02 12:09:27 -05:00
<ProgressSpinner className='w-full mt-24 mx-auto' />
</div>
);
2024-09-01 20:29:33 -05:00
}
if (error) {
return <div className="text-red-500 text-center p-4">Failed to load messages. Please try again later.</div>;
}
2024-09-09 15:56:51 -05:00
const filteredData = data.filter(message =>
message.content.toLowerCase().includes(searchQuery.toLowerCase())
);
2024-09-01 20:29:33 -05:00
return (
2024-09-06 16:57:27 -05:00
<div className="bg-gray-900 h-full w-full min-bottom-bar:w-[86vw]">
2024-09-10 15:44:08 -05:00
<div className="mx-4">
2024-09-09 15:56:51 -05:00
{filteredData && filteredData.length > 0 ? (
filteredData.map(message => (
2024-09-10 15:44:08 -05:00
<CommunityMessage
key={message.id}
message={message}
searchQuery={searchQuery}
windowWidth={windowWidth}
platform="discord"
/>
))
) : (
<div className="text-gray-400 text-center p-4">No messages available.</div>
)}
</div>
2024-09-01 20:29:33 -05:00
</div>
);
};
2024-09-02 12:09:27 -05:00
export default DiscordFeed;