@@ -4,6 +4,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
44import { useFeedsStore } from "@/store/feeds-store" ;
55
66import { POSTS_PER_PAGE } from "../_constants" ;
7+ import { SYSTEM_POST } from "../_constants/system-post" ;
78import Post from "./PostCard" ;
89import PostCardSkeleton from "./PostCardSkeleton" ;
910
@@ -31,11 +32,20 @@ export default function Feed({
3132 fetchPosts ( ) ;
3233 } , [ ] ) ;
3334
35+ // Always prepend system post to regular posts
36+ const allPosts = useMemo ( ( ) => {
37+ return [ SYSTEM_POST , ...posts ] ;
38+ } , [ posts ] ) ;
39+
3440 // Filter posts
3541 const filteredPosts = useMemo ( ( ) => {
36- if ( ! searchQuery || searchQuery . trim ( ) === "" ) return posts ;
42+ if ( ! searchQuery || searchQuery . trim ( ) === "" ) return allPosts ;
43+
3744 const query = searchQuery . toLowerCase ( ) ;
38- return posts . filter ( ( post ) => {
45+ return allPosts . filter ( ( post ) => {
46+ // Always include system post
47+ if ( post . id === "00000000-0000-0000-0000-000000000001" ) return true ;
48+
3949 const titleMatch = post . title ?. toLowerCase ( ) . includes ( query ) ;
4050 const firstNameMatch = post . author_id ?. first_name
4151 ?. toLowerCase ( )
@@ -45,12 +55,16 @@ export default function Feed({
4555 . includes ( query ) ;
4656 return titleMatch || firstNameMatch || lastNameMatch ;
4757 } ) ;
48- } , [ posts , searchQuery ] ) ;
58+ } , [ allPosts , searchQuery ] ) ;
4959
5060 // Sort posts
5161 const sortedPosts = useMemo ( ( ) => {
5262 const sorted = [ ...filteredPosts ] ;
5363 sorted . sort ( ( a , b ) => {
64+ // Always keep system post at the top regardless of sorting
65+ if ( a . id === "00000000-0000-0000-0000-000000000001" ) return - 1 ;
66+ if ( b . id === "00000000-0000-0000-0000-000000000001" ) return 1 ;
67+
5468 let aVal : string | number = "" ;
5569 let bVal : string | number = "" ;
5670
@@ -106,7 +120,11 @@ export default function Feed({
106120 if ( currentLoader ) observer . unobserve ( currentLoader ) ;
107121 } ;
108122 } , [ sortedPosts . length ] ) ;
123+
109124 const handleDeletePost = ( deletedPostId : string | number ) => {
125+ // Prevent deletion of system post
126+ if ( deletedPostId === "00000000-0000-0000-0000-000000000001" ) return ;
127+
110128 useFeedsStore . setState ( ( state ) => ( {
111129 posts : state . posts . filter ( ( post ) => post . id !== deletedPostId ) ,
112130 } ) ) ;
@@ -149,4 +167,4 @@ export default function Feed({
149167 ) }
150168 </ >
151169 ) ;
152- }
170+ }
0 commit comments