Skip to content

Commit

Permalink
Improve placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Awesome-E committed Jan 13, 2025
1 parent 101ce17 commit 5cdfee4
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions site/src/pages/RoadmapPage/SearchSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Course from './Course';
import { courseSearchSortable } from '../../helpers/sortable';
import { Spinner } from 'react-bootstrap';
import { useNamedAcademicTerm } from '../../hooks/namedAcademicTerm';
import noResultsImg from '../../asset/no-results-crop.webp';

const CloseRoadmapSearchButton = () => {
const isMobile = useIsMobile();
Expand All @@ -32,6 +33,25 @@ const CloseRoadmapSearchButton = () => {
);
};

interface SearchPlaceholderProps {
searchInProgress: boolean;
showCourseBag: boolean;
}
const SearchPlaceholder = ({ searchInProgress, showCourseBag }: SearchPlaceholderProps) => {
if (searchInProgress) return <Spinner animation="border" role="status" />;

const placeholderText = showCourseBag
? 'No courses saved. Try searching for something!'
: "Sorry, we couldn't find any results for that search!";

return (
<>
<img src={noResultsImg} alt="No results found" />
{placeholderText}
</>
);
};

const SearchSidebar = () => {
const isMobile = useIsMobile();
const showSearch = useAppSelector((state) => state.roadmap.showSearch);
Expand Down Expand Up @@ -59,36 +79,32 @@ const SearchSidebar = () => {
dispatch(setActiveCourse(course));
};

const coursebagTitle = coursebag.length ? (
<h3 className="coursebag-title">Saved Courses</h3>
) : (
<p className="coursebag-title">No courses saved. Try searching for something!</p>
);

return (
<>
{isMobile && showSearch && <UIOverlay onClick={closeSearch} zIndex={449} passedRef={overlayRef} />}
<div className={`search-sidebar ${isMobile ? 'mobile' : ''}`} ref={sidebarRef}>
<div className="search-sidebar-search-module">
<SearchModule index="courses" />
</div>
{showCourseBag && coursebagTitle}

<ReactSortable
{...courseSearchSortable}
list={shownCourses}
onStart={setDraggedItem}
disabled={isMobile}
className={'search-body' + (isMobile ? ' disabled' : '')}
>
{searchInProgress ? (
<div className="no-results">
<Spinner animation="border" role="status" />
</div>
) : (
shownCourses.map((course, i) => <Course {...course} key={i} addMode={isMobile ? 'tap' : 'drag'} />)
)}
</ReactSortable>
{showCourseBag && <h3 className="coursebag-title">Saved Courses</h3>}

{!searchInProgress && shownCourses.length ? (
<ReactSortable
{...courseSearchSortable}
list={shownCourses}
onStart={setDraggedItem}
disabled={isMobile}
className={'search-body' + (isMobile ? ' disabled' : '')}
>
{shownCourses.map((course, i) => (
<Course {...course} key={i} addMode={isMobile ? 'tap' : 'drag'} />
))}
</ReactSortable>
) : (
<div className="no-results">
<SearchPlaceholder searchInProgress={searchInProgress} showCourseBag={showCourseBag} />
</div>
)}
<CloseRoadmapSearchButton />
</div>
</>
Expand Down

0 comments on commit 5cdfee4

Please sign in to comment.