[resumes][feat] add loading screens for resumes/comments (#342)

pull/344/head
Keane Chan 2 years ago committed by GitHub
parent c196dcea32
commit 53433787eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,35 @@
import { Spinner } from '@tih/ui';
import ResumseListItem from './ResumeListItem';
import type { Resume } from '~/types/resume';
type Props = Readonly<{
isLoading: boolean;
resumes: Array<Resume>;
}>;
export default function ResumeListItems({ isLoading, resumes }: Props) {
if (isLoading) {
return (
<div className="col-span-10 pt-4">
<Spinner display="block" size="lg" />
</div>
);
}
return (
<div className="col-span-10 pr-8">
<ul role="list">
{resumes.map((resumeObj: Resume) => (
<li key={resumeObj.id}>
<ResumseListItem
href={`resumes/${resumeObj.id}`}
resumeInfo={resumeObj}
/>
</li>
))}
</ul>
</div>
);
}

@ -54,7 +54,7 @@ export const EXPERIENCE = [
export const LOCATION = [ export const LOCATION = [
{ checked: false, label: 'Singapore', value: 'Singapore' }, { checked: false, label: 'Singapore', value: 'Singapore' },
{ checked: false, label: 'United States', value: 'US' }, { checked: false, label: 'United States', value: 'United States' },
{ checked: false, label: 'India', value: 'India' }, { checked: false, label: 'India', value: 'India' },
]; ];

@ -0,0 +1,35 @@
import { useSession } from 'next-auth/react';
import { Spinner } from '@tih/ui';
import Comment from './comment/Comment';
import type { ResumeComment } from '~/types/resume-comments';
type Props = Readonly<{
comments: Array<ResumeComment>;
isLoading: boolean;
}>;
export default function CommentListItems({ comments, isLoading }: Props) {
const { data: session } = useSession();
if (isLoading) {
return (
<div className="col-span-10 pt-4">
<Spinner display="block" size="lg" />
</div>
);
}
return (
<div className="m-2 flow-root h-[calc(100vh-20rem)] w-full flex-col space-y-3 overflow-y-scroll">
{comments.map((comment) => (
<Comment
key={comment.id}
comment={comment}
userId={session?.user?.id}
/>
))}
</div>
);
}

@ -1,10 +1,9 @@
import { useSession } from 'next-auth/react';
import { useState } from 'react'; import { useState } from 'react';
import { Tabs } from '@tih/ui'; import { Tabs } from '@tih/ui';
import { trpc } from '~/utils/trpc'; import { trpc } from '~/utils/trpc';
import Comment from './comment/Comment'; import CommentListItems from './CommentListItems';
import CommentsListButton from './CommentsListButton'; import CommentsListButton from './CommentsListButton';
import { COMMENTS_SECTIONS } from './constants'; import { COMMENTS_SECTIONS } from './constants';
@ -18,12 +17,9 @@ export default function CommentsList({
setShowCommentsForm, setShowCommentsForm,
}: CommentsListProps) { }: CommentsListProps) {
const [tab, setTab] = useState(COMMENTS_SECTIONS[0].value); const [tab, setTab] = useState(COMMENTS_SECTIONS[0].value);
const { data: session } = useSession();
const commentsQuery = trpc.useQuery(['resumes.reviews.list', { resumeId }]); const commentsQuery = trpc.useQuery(['resumes.reviews.list', { resumeId }]);
// TODO: Add loading prompt
return ( return (
<div className="space-y-3"> <div className="space-y-3">
<CommentsListButton setShowCommentsForm={setShowCommentsForm} /> <CommentsListButton setShowCommentsForm={setShowCommentsForm} />
@ -33,20 +29,10 @@ export default function CommentsList({
value={tab} value={tab}
onChange={(value) => setTab(value)} onChange={(value) => setTab(value)}
/> />
<CommentListItems
<div className="m-2 flow-root h-[calc(100vh-20rem)] w-full flex-col space-y-3 overflow-y-scroll"> comments={commentsQuery.data?.filter((c) => c.section === tab) ?? []}
{commentsQuery.data isLoading={commentsQuery.isFetching}
?.filter((c) => c.section === tab) />
.map((comment) => {
return (
<Comment
key={comment.id}
comment={comment}
userId={session?.user?.id}
/>
);
})}
</div>
</div> </div>
); );
} }

@ -10,9 +10,8 @@ import {
PlusIcon, PlusIcon,
} from '@heroicons/react/20/solid'; } from '@heroicons/react/20/solid';
import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'; import { MagnifyingGlassIcon } from '@heroicons/react/24/outline';
import { Spinner, Tabs, TextInput } from '@tih/ui'; import { Tabs, TextInput } from '@tih/ui';
import BrowseListItem from '~/components/resumes/browse/BrowseListItem';
import { import {
BROWSE_TABS_VALUES, BROWSE_TABS_VALUES,
EXPERIENCE, EXPERIENCE,
@ -22,8 +21,11 @@ import {
TOP_HITS, TOP_HITS,
} from '~/components/resumes/browse/constants'; } from '~/components/resumes/browse/constants';
import FilterPill from '~/components/resumes/browse/FilterPill'; import FilterPill from '~/components/resumes/browse/FilterPill';
import ResumeListItems from '~/components/resumes/browse/ResumeListItems';
import ResumeReviewsTitle from '~/components/resumes/ResumeReviewsTitle'; import ResumeReviewsTitle from '~/components/resumes/ResumeReviewsTitle';
import { trpc } from '~/utils/trpc';
import type { Resume } from '~/types/resume'; import type { Resume } from '~/types/resume';
const filters = [ const filters = [
@ -44,8 +46,6 @@ const filters = [
}, },
]; ];
import { trpc } from '~/utils/trpc';
export default function ResumeHomePage() { export default function ResumeHomePage() {
const { data: sessionData } = useSession(); const { data: sessionData } = useSession();
const router = useRouter(); const router = useRouter();
@ -140,6 +140,7 @@ export default function ResumeHomePage() {
<div className="col-span-1 justify-self-center"> <div className="col-span-1 justify-self-center">
<Menu as="div" className="relative inline-block text-left"> <Menu as="div" className="relative inline-block text-left">
<div> <div>
{/* TODO: Sort logic */}
<Menu.Button className="group inline-flex justify-center text-sm font-medium text-gray-700 hover:text-gray-900"> <Menu.Button className="group inline-flex justify-center text-sm font-medium text-gray-700 hover:text-gray-900">
Sort Sort
<ChevronDownIcon <ChevronDownIcon
@ -269,26 +270,14 @@ export default function ResumeHomePage() {
</form> </form>
</div> </div>
</div> </div>
{allResumesQuery.isLoading || <ResumeListItems
starredResumesQuery.isLoading || isLoading={
myResumesQuery.isLoading ? ( allResumesQuery.isFetching ||
<div className="col-span-10 pt-4"> starredResumesQuery.isFetching ||
<Spinner display="block" size="lg" /> myResumesQuery.isFetching
</div> }
) : ( resumes={resumes}
<div className="col-span-10 pr-8"> />
<ul role="list">
{resumes.map((resumeObj) => (
<li key={resumeObj.id}>
<BrowseListItem
href={`resumes/${resumeObj.id}`}
resumeInfo={resumeObj}
/>
</li>
))}
</ul>
</div>
)}
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save