Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix k12 resources section #2682

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/components/tablist/tablist.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.tabs {
display: flex;
flex-direction: column;
width: 100%;

.vertical {
flex-direction: row;
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/k12/subject/resources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
width: 100%;
}

.content-group {
[role="tabpanel"] {
padding: 6rem 0;

.card-grid:not([hidden]) {
Expand Down
68 changes: 41 additions & 27 deletions src/app/pages/k12/subject/resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {TrackedMouseEvent} from '~/components/shell/router-helpers/use-link-hand
import bookTitles from '~/models/book-titles';
import './resources.scss';

function LinkWithGiveDialog({href, book, track}: {
function LinkWithGiveDialog({
href,
book,
track
}: {
href: string;
book: string;
track: string;
Expand All @@ -33,10 +37,14 @@ function LinkWithGiveDialog({href, book, track}: {

return (
<React.Fragment>
<a href={href} onClick={openGiveDialog} data-track={track}>{book}</a>
<a href={href} onClick={openGiveDialog} data-track={track}>
{book}
</a>
<GiveDialog
link={href} variant='K12 resource' track={track}
onDownload={trackDownloadClick}
link={href}
variant="K12 resource"
track={track}
onDownload={trackDownloadClick}
/>
</React.Fragment>
);
Expand All @@ -50,20 +58,17 @@ type LinkData = {
linkDocumentUrl: string;
};

function ResourceLink({ data, track }: {
data: LinkData;
track: string;
}) {
function ResourceLink({data, track}: {data: LinkData; track: string}) {
const url = data.linkExternal || data.linkDocumentUrl;
const {isVerified} = useUserContext();

return (
<li>
{
data.resourceUnlocked || isVerified ?
<LinkWithGiveDialog href={url} book={data.book} track={track} /> :
{data.resourceUnlocked || isVerified ? (
<LinkWithGiveDialog href={url} book={data.book} track={track} />
) : (
<span>{data.book} (verified instructor only)</span>
}
)}
</li>
);
}
Expand All @@ -82,9 +87,9 @@ type ResourceHeader = LinkData & {
};
type ResourceDict = {
[name: string]: ResourceHeader[];
}
};

function ResourceToContent({ resources }: {resources: ResourceDict}) {
function ResourceToContent({resources}: {resources: ResourceDict}) {
return (
<div className="card-grid">
{(Reflect.ownKeys(resources) as string[])?.map((name) => {
Expand All @@ -98,7 +103,11 @@ function ResourceToContent({ resources }: {resources: ResourceDict}) {
</div>
<ul>
{resourceList.map((r) => (
<ResourceLink key={r.book} data={r} track={name} />
<ResourceLink
key={r.book}
data={r}
track={name}
/>
))}
</ul>
</div>
Expand All @@ -124,7 +133,8 @@ type HeaderKeys = 'facultyResourceHeaders' | 'studentResourceHeaders';
export default function Resources({
data,
labels,
selectedLabel
selectedLabel,
setSelectedLabel
}: {
data: {
resourcesHeading: string;
Expand All @@ -133,26 +143,30 @@ export default function Resources({
};
labels: string[];
selectedLabel: string;
setSelectedLabel: (s: unknown) => void;
}) {
const resources = React.useMemo(
() => ['facultyResourceHeaders', 'studentResourceHeaders'].map(
(k) => resourceHeadersToResources(data[k as HeaderKeys])
),
() =>
['facultyResourceHeaders', 'studentResourceHeaders'].map((k) =>
resourceHeadersToResources(data[k as HeaderKeys])
),
[data]
);

return (
<section id="resources">
<div className="boxed">
<h1>{data.resourcesHeading}</h1>
<Tabs aria-label="Resource tabs" selectedKey={selectedLabel}>
{
labels.map((label, i) =>
<Item key={label} title={label}>
<ResourceToContent resources={resources[i]} />
</Item>
)
}
<Tabs
aria-label="Resource tabs"
selectedKey={selectedLabel}
onSelectionChange={setSelectedLabel}
>
{labels.map((label, i) => (
<Item key={label} title={label}>
<ResourceToContent resources={resources[i]} />
</Item>
))}
</Tabs>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/k12/subject/subject.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Subject({ data }) {
<QuickLinks {...{ labels, setSelectedLabel }} />
<Books data={data} />
<WhatTeachersSay data={data} />
<Resources {...{ data, labels, selectedLabel }} />
<Resources {...{ data, labels, selectedLabel, setSelectedLabel }} />
{/* <Blogs data={data} /> */}
<Contact data={data} />
</div>
Expand Down
4 changes: 4 additions & 0 deletions test/src/pages/k12/resources.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('k12 subject resources', () => {
}}
labels={['one', 'two']}
selectedLabel="one"
setSelectedLabel={jest.fn()}
/>
</MemoryRouter>
);
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('k12 subject resources', () => {
}}
labels={['one', 'two']}
selectedLabel="one"
setSelectedLabel={jest.fn()}
/>
);
expect(screen.queryAllByRole('link')).toHaveLength(0);
Expand Down Expand Up @@ -126,6 +128,7 @@ describe('k12 subject resources', () => {
}}
labels={['one', 'two']}
selectedLabel="one"
setSelectedLabel={jest.fn()}
/>
</MemoryRouter>
);
Expand Down Expand Up @@ -169,6 +172,7 @@ describe('k12 subject resources', () => {
}}
labels={['one', 'two']}
selectedLabel="one"
setSelectedLabel={jest.fn()}
/>
</MemoryRouter>
);
Expand Down
Loading