Skip to content

Commit

Permalink
allow searching during page load
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveDarsa committed Dec 11, 2023
1 parent 8213d17 commit 4dd864c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
27 changes: 18 additions & 9 deletions src/components/Projects/ProjectsSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import Box from 'components/Box';

import { ProjectsHeader, ProjectsPage, SearchInput, StyledProject } from './StyledProjects';

const ProjectsSkeleton = () => {
interface Props {
setSearch: (text: string) => React.SetStateAction<string>;
}
const ProjectsSkeleton = ({ setSearch }: Props) => {
const RenderSkeletonBox = (index: number) => {
return (
<Box className="box">
Expand All @@ -22,14 +25,20 @@ const ProjectsSkeleton = () => {

return (
<ProjectsPage>
<ProjectsHeader>
<label>
<Skeleton width={'20%'} />
</label>
<label></label>
<SearchInput aria-labelledby="search" className="searchInput" type="text" placeholder="Type to search" />
</ProjectsHeader>
<>{[...Array<undefined>(numberOfItems)].map((_, idx) => RenderSkeletonBox(idx))}</>
<ProjectsHeader>
<label>
<Skeleton width={'20%'} />
</label>
<label></label>
<SearchInput
onChange={e => setSearch(e.target.value)}
aria-labelledby="search"
className="searchInput"
type="text"
placeholder="Type to search"
/>
</ProjectsHeader>
<>{[...Array<undefined>(numberOfItems)].map((_, idx) => RenderSkeletonBox(idx))}</>
</ProjectsPage>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
/**
* The primary list of projects.
*/
const Projects = ({ projects = [] }) => {
const [searchInput, setSearchInput] = useState('');
const Projects = ({ projects = [], initialSearch }) => {
const [searchInput, setSearchInput] = useState(initialSearch);

const filteredProjects = projects.filter(key => {
const sortByName = key.name.toLowerCase().includes(searchInput.trim().toLowerCase());
Expand Down
11 changes: 8 additions & 3 deletions src/pages/projects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';

import Head from 'next/head';

Expand All @@ -18,6 +18,8 @@ import { useTourContext } from '../tours/TourContext';
const ProjectsPage = () => {
const { startTour } = useTourContext();

const [searchInput, setSearchInput] = useState('');

const { data, loading, error } = useQuery(AllProjectsQuery, {
displayName: 'AllProjectsQuery',
});
Expand All @@ -42,9 +44,12 @@ const ProjectsPage = () => {
<CommonWrapper>
<h2>Projects</h2>
<div className="content">
{loading ? <ProjectsSkeleton /> : <Projects projects={data.allProjects || []} />}
{loading ? (
<ProjectsSkeleton setSearch={setSearchInput} />
) : (
<Projects initialSearch={searchInput} projects={data.allProjects || []} />
)}
</div>

</CommonWrapper>
</MainLayout>
</>
Expand Down

0 comments on commit 4dd864c

Please sign in to comment.