Skip to content

Commit

Permalink
Merge pull request #2272 from bryanjenningz/make-admin-lesson-nav-gen…
Browse files Browse the repository at this point in the history
…eric

Make AdminLessonNav more generic
  • Loading branch information
bryanjenningz authored Sep 10, 2022
2 parents 1784a86 + c708bfd commit 5a78298
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 163 deletions.
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`] = `
<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 {
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

1 comment on commit 5a78298

@vercel
Copy link

@vercel vercel bot commented on 5a78298 Sep 10, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.