fix: drafts always unfiltered and visible
This commit is contained in:
@@ -360,14 +360,15 @@ const PostsList: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Determine which posts to display
|
// Determine which posts to display
|
||||||
const displayPosts = searchResults ?? filteredPosts ?? posts;
|
// Filters only apply to published/archived posts — drafts are always shown unfiltered
|
||||||
const isFiltered = searchResults !== null || filteredPosts !== null;
|
const filteredDisplayPosts = searchResults ?? filteredPosts ?? null;
|
||||||
|
const isFiltered = filteredDisplayPosts !== null;
|
||||||
const hasActiveFilters = searchQuery || selectedYear || selectedTags.length > 0 || selectedCategories.length > 0;
|
const hasActiveFilters = searchQuery || selectedYear || selectedTags.length > 0 || selectedCategories.length > 0;
|
||||||
|
|
||||||
const groupedPosts = {
|
const groupedPosts = {
|
||||||
draft: displayPosts.filter(p => p.status === 'draft'),
|
draft: posts.filter(p => p.status === 'draft'),
|
||||||
published: displayPosts.filter(p => p.status === 'published'),
|
published: (filteredDisplayPosts ?? posts).filter(p => p.status === 'published'),
|
||||||
archived: displayPosts.filter(p => p.status === 'archived'),
|
archived: (filteredDisplayPosts ?? posts).filter(p => p.status === 'archived'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearAllFilters = () => {
|
const clearAllFilters = () => {
|
||||||
@@ -436,7 +437,7 @@ const PostsList: React.FC = () => {
|
|||||||
{hasActiveFilters && (
|
{hasActiveFilters && (
|
||||||
<div className="filter-status">
|
<div className="filter-status">
|
||||||
<span>
|
<span>
|
||||||
{displayPosts.length} result{displayPosts.length !== 1 ? 's' : ''}
|
{groupedPosts.published.length + groupedPosts.archived.length} result{groupedPosts.published.length + groupedPosts.archived.length !== 1 ? 's' : ''}
|
||||||
{searchQuery && ` for "${searchQuery}"`}
|
{searchQuery && ` for "${searchQuery}"`}
|
||||||
</span>
|
</span>
|
||||||
<button onClick={clearAllFilters} title="Clear all filters">
|
<button onClick={clearAllFilters} title="Clear all filters">
|
||||||
@@ -529,14 +530,14 @@ const PostsList: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{displayPosts.length === 0 && !isFiltered && (
|
{posts.length === 0 && !isFiltered && (
|
||||||
<div className="sidebar-empty">
|
<div className="sidebar-empty">
|
||||||
<p>No posts yet</p>
|
<p>No posts yet</p>
|
||||||
<button onClick={handleCreatePost}>Create your first post</button>
|
<button onClick={handleCreatePost}>Create your first post</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{displayPosts.length === 0 && isFiltered && (
|
{groupedPosts.published.length === 0 && groupedPosts.archived.length === 0 && isFiltered && (
|
||||||
<div className="sidebar-empty">
|
<div className="sidebar-empty">
|
||||||
<p>No matching posts</p>
|
<p>No matching posts</p>
|
||||||
<button onClick={clearAllFilters}>Clear filters</button>
|
<button onClick={clearAllFilters}>Clear filters</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user