mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Updated search behavior with local data
- removes section on no search result - updates clear to remove search string - updates authors and tags with correct matching data
This commit is contained in:
parent
ef921843f4
commit
72aa270282
1 changed files with 29 additions and 7 deletions
|
@ -6,7 +6,7 @@ import {useContext} from 'react';
|
||||||
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
|
|
||||||
const tags = [
|
const tagsData = [
|
||||||
{
|
{
|
||||||
title: 'Nomad life'
|
title: 'Nomad life'
|
||||||
},
|
},
|
||||||
|
@ -15,7 +15,7 @@ const tags = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const posts = [
|
const postsData = [
|
||||||
{
|
{
|
||||||
title: 'How to ergonomically optimize your workspace',
|
title: 'How to ergonomically optimize your workspace',
|
||||||
excerpt: 'Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.'
|
excerpt: 'Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.'
|
||||||
|
@ -30,7 +30,7 @@ const posts = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const authors = [
|
const authorsData = [
|
||||||
{
|
{
|
||||||
name: 'Norman Foster'
|
name: 'Norman Foster'
|
||||||
},
|
},
|
||||||
|
@ -128,6 +128,7 @@ function SearchBox() {
|
||||||
<div className='flex items-center py-6 px-7'>
|
<div className='flex items-center py-6 px-7'>
|
||||||
<SearchIcon className='mr-3' alt='Search' />
|
<SearchIcon className='mr-3' alt='Search' />
|
||||||
<input
|
<input
|
||||||
|
autoFocus
|
||||||
value={searchValue || ''}
|
value={searchValue || ''}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
dispatch('update', {
|
dispatch('update', {
|
||||||
|
@ -137,7 +138,14 @@ function SearchBox() {
|
||||||
className='grow text-[1.65rem] focus-visible:outline-none placeholder:text-gray-300'
|
className='grow text-[1.65rem] focus-visible:outline-none placeholder:text-gray-300'
|
||||||
placeholder='Search posts, tags, authors..'
|
placeholder='Search posts, tags, authors..'
|
||||||
/>
|
/>
|
||||||
<ClearIcon className='ml-3 fill-neutral-400' alt='Clear' />
|
<ClearIcon
|
||||||
|
className='ml-3 fill-neutral-400 cursor-pointer' alt='Clear'
|
||||||
|
onClick={() => {
|
||||||
|
dispatch('update', {
|
||||||
|
searchValue: ''
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +164,9 @@ function TagResults({tags}) {
|
||||||
const filteredTags = tags.filter((d) => {
|
const filteredTags = tags.filter((d) => {
|
||||||
return d.title?.toLowerCase().includes(searchValue?.toLowerCase());
|
return d.title?.toLowerCase().includes(searchValue?.toLowerCase());
|
||||||
});
|
});
|
||||||
|
if (!filteredTags?.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const TagItems = filteredTags.map((d) => {
|
const TagItems = filteredTags.map((d) => {
|
||||||
return (
|
return (
|
||||||
<TagListItem
|
<TagListItem
|
||||||
|
@ -190,6 +200,11 @@ function PostResults({posts}) {
|
||||||
const filteredPosts = posts.filter((d) => {
|
const filteredPosts = posts.filter((d) => {
|
||||||
return d.title?.toLowerCase().includes(searchValue.toLowerCase()) || d.excerpt?.toLowerCase().includes(searchValue?.toLowerCase());
|
return d.title?.toLowerCase().includes(searchValue.toLowerCase()) || d.excerpt?.toLowerCase().includes(searchValue?.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!filteredPosts?.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const PostItems = filteredPosts.map((d) => {
|
const PostItems = filteredPosts.map((d) => {
|
||||||
return (
|
return (
|
||||||
<PostListItem
|
<PostListItem
|
||||||
|
@ -233,6 +248,9 @@ function AuthorResults({authors}) {
|
||||||
const filteredAuthors = authors.filter((d) => {
|
const filteredAuthors = authors.filter((d) => {
|
||||||
return d.name?.toLowerCase().includes(searchValue?.toLowerCase());
|
return d.name?.toLowerCase().includes(searchValue?.toLowerCase());
|
||||||
});
|
});
|
||||||
|
if (!filteredAuthors?.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const AuthorItems = filteredAuthors.map((d) => {
|
const AuthorItems = filteredAuthors.map((d) => {
|
||||||
return (
|
return (
|
||||||
|
@ -253,10 +271,10 @@ function AuthorResults({authors}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function SearchResultBox() {
|
function SearchResultBox() {
|
||||||
const hasResults = posts?.length || authors?.length || tags?.length;
|
const hasResults = postsData?.length || authorsData?.length || tagsData?.length;
|
||||||
if (hasResults) {
|
if (hasResults) {
|
||||||
return (
|
return (
|
||||||
<Results posts={posts} authors={authors} tags={tags} />
|
<Results posts={postsData} authors={authorsData} tags={tagsData} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,6 +284,10 @@ function SearchResultBox() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Results({posts, authors, tags}) {
|
function Results({posts, authors, tags}) {
|
||||||
|
const {searchValue} = useContext(AppContext);
|
||||||
|
if (!searchValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<AuthorResults authors={authors} />
|
<AuthorResults authors={authors} />
|
||||||
|
|
Loading…
Add table
Reference in a new issue