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

Make AdminLessonNav more generic #2272

Merged
merged 5 commits into from
Sep 10, 2022
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
78 changes: 38 additions & 40 deletions __tests__/__snapshots__/storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -866,46 +866,6 @@ Array [
]
`;

exports[`Storyshots Components/AdminLessonNav Basic 1`] = `
<div>
<div
className="lessons_tabsNav"
>
<div
className="lessons__tabsNav__nav"
>
<a
className="lessons_tabsNav__nav__item--inactive nav-pills"
href="/admin/lessons/1/introduction"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
INTRODUCTION
</a>
<a
className="lessons_tabsNav__nav__item--inactive nav-pills"
href="/admin/lessons/1/modules"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
MODULES
</a>
<a
className="lessons_tabsNav__nav__item--inactive nav-pills"
href="/admin/lessons/1/challenges"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
CHALLENGES
</a>
</div>
</div>
</div>
`;

exports[`Storyshots Components/AdminLessonSideNav Basic 1`] = `
<div
className="container"
Expand Down Expand Up @@ -12203,6 +12163,44 @@ exports[`Storyshots Components/ModalCard Small 1`] = `
</button>
`;

exports[`Storyshots Components/NavCard Basic 1`] = `
Copy link
Collaborator Author

@bryanjenningz bryanjenningz Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snapshot is identical to the snapshot that got removed above with the only difference being the name is now "Storyshots Components/NavCard Basic 1" instead of "Storyshots Components/AdminLessonNav Basic 1" and the classNames now use the more generic "navCard__" prefix instead of "lesson__".

I figured the name NavCard made more sense because it's a Card and it also contains Nav items and when I searched NavCard (https://github.com/garageScript/c0d3-app/search?q=NavCard), this name wasn't taken so it seemed like a nice short name that describes what it is pretty well.

<div
className="navCard__tabsNav"
>
<div
className="navCard__tabsNav__nav"
>
<a
className="navCard__tabsNav__nav__item--inactive nav-pills"
href="/admin/lessons/1/introduction"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
INTRODUCTION
</a>
<a
className="navCard__tabsNav__nav__item--inactive nav-pills"
href="/admin/lessons/1/modules"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
MODULES
</a>
<a
className="navCard__tabsNav__nav__item--inactive nav-pills"
href="/admin/lessons/1/challenges"
onClick={[Function]}
onMouseEnter={[Function]}
onTouchStart={[Function]}
>
CHALLENGES
</a>
</div>
</div>
`;

exports[`Storyshots Components/NavLink Active Link 1`] = `
Array [
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('modules', () => {
await act(() => new Promise(res => setTimeout(res, 0)))

expect(screen.getByText('MODULES').className).not.toEqual(
'lessons_tabsNav__nav__item'
'navCard__tabsNav__nav__item'
)
})
})
47 changes: 47 additions & 0 deletions components/NavCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Link from 'next/link'
import React from 'react'
import styles from '../scss/navCard.module.scss'

type Tab = {
text: string
url: string
}

type NavCardProps = {
tabSelected: number
tabs: Tab[]
}

const NavCard = ({ tabSelected, tabs }: NavCardProps) => {
return (
<div className={styles.navCard__tabsNav}>
<div className={styles.navCard__tabsNav__nav}>
{tabs.map((tab, i) => (
<NavCardItem key={i} isSelected={i === tabSelected} tab={tab} />
))}
</div>
</div>
)
}

type NavCardItemProps = {
isSelected: boolean
tab: Tab
}

const NavCardItem = ({ isSelected, tab }: NavCardItemProps) => {
const className =
styles[
isSelected
? 'navCard__tabsNav__nav__item'
: 'navCard__tabsNav__nav__item--inactive'
]

return (
<Link href={tab.url}>
<a className={`${className} nav-pills`}>{tab.text.toUpperCase()}</a>
</Link>
)
}

export default NavCard
25 changes: 0 additions & 25 deletions components/admin/lessons/AdminLessonSideNavLayout.tsx

This file was deleted.

41 changes: 9 additions & 32 deletions pages/admin/lessons/[lessonSlug]/[pageName]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { gql, useQuery } from '@apollo/client'
import { GetAppProps, withGetApp } from '../../../../../graphql'
import { toUpper } from 'lodash'
import React, { useMemo, useState } from 'react'
import AdminLessonNav from '../../../../../components/admin/lessons/AdminLessonSideNavLayout'
import AdminLessonSideNav from '../../../../../components/admin/lessons/AdminLessonSideNav'
import AdminLessonInputs from '../../../../../components/admin/lessons/AdminLessonInputs'
import { Props } from '../../../../../components/admin/lessons/AdminLessonInputs/AdminLessonInputs'
import Breadcrumbs from '../../../../../components/Breadcrumbs'
import styles from '../../../../../scss/modules.module.scss'
import navStyles from '../../../../../scss/adminLessonNav.module.scss'
import { AdminLayout } from '../../../../../components/admin/AdminLayout'
import { useRouter } from 'next/router'
import Link from 'next/link'
import { compose, filter, get, sortBy } from 'lodash/fp'
import NavCard from '../../../../../components/NavCard'

const MAIN_PATH = '/admin/lessons'

Expand Down Expand Up @@ -114,25 +111,13 @@ const Lessons = ({ data }: GetAppProps) => {
return sortModules(modulesData)
}, [lesson.id, get('modules', modulesData)])

const LessonNav = ({
tab
}: {
tab: { tabName: string; urlPageName: string }
}) => {
const isSelected = tab.urlPageName === pageName
const className =
navStyles[
isSelected
? 'lessons_tabsNav__nav__item'
: 'lessons_tabsNav__nav__item--inactive'
]

return (
<Link href={`${MAIN_PATH}/${lessonSlug}/${tab.urlPageName}`}>
<a className={`${className} nav-pills`}>{toUpper(tab.tabName)}</a>
</Link>
)
}
const tabs = [
{
text: 'modules',
url: `${MAIN_PATH}/${lesson.slug}/modules`
}
]
const tabSelected = tabs.findIndex(tab => tab.text === pageName)

return (
<AdminLayout data={data}>
Expand All @@ -148,15 +133,7 @@ const Lessons = ({ data }: GetAppProps) => {
/>
</header>
<section>
<AdminLessonNav
tabs={[
{
tabName: 'modules',
urlPageName: 'modules'
}
]}
Component={LessonNav}
/>
<NavCard tabSelected={tabSelected} tabs={tabs} />
</section>
<section>
<Content
Expand Down
16 changes: 6 additions & 10 deletions scss/adminLessonNav.module.scss → scss/navCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $light: hsl(0, 0%, 98.4%);
$dark_primary: color.adjust(variables.$primary, $lightness: -20%);
$light_primary: color.adjust(variables.$primary, $lightness: 28%);

.lessons_tabsNav {
.navCard__tabsNav {
font-family: 'PT Mono';
max-width: fit-content;
padding: 8px 16px;
Expand All @@ -20,15 +20,15 @@ $light_primary: color.adjust(variables.$primary, $lightness: 28%);
border: 1px solid $light_primary;
}

.lessons__tabsNav__nav {
.navCard__tabsNav__nav {
display: flex;
column-gap: 20px;
justify-content: center;
row-gap: 20px;
flex-wrap: nowrap;
}

.lessons_tabsNav__nav__item {
.navCard__tabsNav__nav__item {
padding: 7px 16px;
border-radius: 4px;
background-color: variables.$primary;
Expand All @@ -39,11 +39,11 @@ $light_primary: color.adjust(variables.$primary, $lightness: 28%);
font-size: 14px;
}

.lessons_tabsNav__nav__item:hover {
.navCard__tabsNav__nav__item:hover {
color: white;
}

.lessons_tabsNav__nav__item--inactive {
.navCard__tabsNav__nav__item--inactive {
padding: 7px 16px;
border-radius: 4px;
color: $dark_primary;
Expand All @@ -55,12 +55,8 @@ $light_primary: color.adjust(variables.$primary, $lightness: 28%);
font-size: 14px;
}

.lessons_tabsNav__nav__item--inactive:hover {
.navCard__tabsNav__nav__item--inactive:hover {
background-color: color.change(variables.$primary, $lightness: 95%);
color: $dark_primary;
transition: background-color 0.3s ease-out;
}

.lessons_tabs {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .lessons_tabs CSS class wasn't being used (https://github.com/garageScript/c0d3-app/search?q=lessons_tabs) so I deleted it.

margin-top: 40px;
}
55 changes: 0 additions & 55 deletions stories/components/AdminLessonSideNavLayout.stories.tsx

This file was deleted.

28 changes: 28 additions & 0 deletions stories/components/NavCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useRouter } from 'next/router'
import * as React from 'react'
import NavCard from '../../components/NavCard'

export default {
component: NavCard,
title: 'Components/NavCard'
}

export const Basic = () => {
const router = useRouter()
const pageName = router.asPath.split('/').slice(-1)[0]
const tabs = ['introduction', 'modules', 'challenges'].map(text => ({
text,
url: `/admin/lessons/1/${text}`
}))
const tabSelected = tabs.findIndex(tab => tab.text === pageName)

return <NavCard tabSelected={tabSelected} tabs={tabs} />
}

const parameters = {
nextRouter: {
asPath: 'c0d3.com/admin/lessons/1/introduction'
}
}

Basic.parameters = parameters