Skip to content

Commit

Permalink
refactor: organise icons (freeCodeCamp#57498)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Dec 12, 2024
1 parent 4b4aa2b commit 70f20b9
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 198 deletions.
30 changes: 30 additions & 0 deletions client/src/assets/chapter-icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { FsdChapters } from '../../../shared/config/chapters';
import DatabaseIcon from './icons/database';
import JavaScriptIcon from './icons/javascript';
import ReactIcon from './icons/react';
import ResponsiveDesign from './icons/responsive-design';
import FreeCodeCampIcon from './icons/freecodecamp';
import Html from './icons/html';
import Css from './icons/css';

const iconMap = {
[FsdChapters.Welcome]: FreeCodeCampIcon,
[FsdChapters.Html]: Html,
[FsdChapters.Css]: Css,
[FsdChapters.Javascript]: JavaScriptIcon,
[FsdChapters.FrontendLibraries]: ReactIcon,
[FsdChapters.RelationalDatabases]: DatabaseIcon,
[FsdChapters.Security]: ResponsiveDesign
};

type ChapterIconProps = {
chapter: FsdChapters;
} & React.SVGProps<SVGSVGElement>;

export function ChapterIcon(props: ChapterIconProps): JSX.Element {
const { chapter, ...iconProps } = props;
const Icon = iconMap[chapter] ?? ResponsiveDesign;

return <Icon {...iconProps} />;
}
31 changes: 0 additions & 31 deletions client/src/assets/icons/chapter-icon.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions client/src/assets/icons/freecodecamp-icon.tsx

This file was deleted.

114 changes: 114 additions & 0 deletions client/src/assets/icons/freecodecamp-logo.tsx

Large diffs are not rendered by default.

109 changes: 5 additions & 104 deletions client/src/assets/icons/freecodecamp.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React from 'react';
import { SuperBlocks } from '../../../../shared/config/curriculum';
import APIIcon from './api';
import D3Icon from './d3';
import DatabaseIcon from './database';
import JavaScriptIcon from './javascript';
import ReactIcon from './react';
import TensorflowIcon from './tensorflow';
import Algorithm from './algorithm';
import Analytics from './analytics';
import Clipboard from './clipboard';
import PythonIcon from './python';
import ResponsiveDesign from './responsive-design';
import Shield from './shield';
import VikingHelmet from './viking-helmet';
import Graduation from './graduation';
import CollegeAlgebra from './college-algebra';
import CSharpLogo from './c-sharp-logo';
import A2EnglishIcon from './a2-english';
import B1EnglishIcon from './b1-english';
import RosettaCodeIcon from './rosetta-code';
import Code from './code';
import { SuperBlocks } from '../../../shared/config/curriculum';
import APIIcon from './icons/api';
import D3Icon from './icons/d3';
import DatabaseIcon from './icons/database';
import JavaScriptIcon from './icons/javascript';
import ReactIcon from './icons/react';
import TensorflowIcon from './icons/tensorflow';
import Algorithm from './icons/algorithm';
import Analytics from './icons/analytics';
import Clipboard from './icons/clipboard';
import PythonIcon from './icons/python';
import ResponsiveDesign from './icons/responsive-design';
import Shield from './icons/shield';
import VikingHelmet from './icons/viking-helmet';
import Graduation from './icons/graduation';
import CollegeAlgebra from './icons/college-algebra';
import CSharpLogo from './icons/c-sharp-logo';
import A2EnglishIcon from './icons/a2-english';
import B1EnglishIcon from './icons/b1-english';
import RosettaCodeIcon from './icons/rosetta-code';
import Code from './icons/code';

const iconMap = {
[SuperBlocks.RespWebDesignNew]: ResponsiveDesign,
Expand Down Expand Up @@ -52,9 +52,8 @@ type SuperBlockIconProps = {
} & React.SVGProps<SVGSVGElement>;

export function SuperBlockIcon(props: SuperBlockIconProps): JSX.Element {
const { superBlock, className, ...iconProps } = props;
// fallback in case super block doesn't exist and for tests
const { superBlock, ...iconProps } = props;
const Icon = iconMap[superBlock] ? iconMap[superBlock] : ResponsiveDesign;

return <Icon className={className} {...iconProps} />;
return <Icon {...iconProps} />;
}
2 changes: 1 addition & 1 deletion client/src/client-only-routes/show-certification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Container, Col, Row, Image, Button, Spacer } from '@freecodecamp/ui';

import envData from '../../config/env.json';
import { getLangCode } from '../../../shared/config/i18n';
import FreeCodeCampLogo from '../assets/icons/freecodecamp';
import FreeCodeCampLogo from '../assets/icons/freecodecamp-logo';
import MicrosoftLogo from '../assets/icons/microsoft-logo';
import { createFlashMessage } from '../components/Flash/redux';
import { Loader } from '../components/helpers';
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Header/components/exam-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import FreeCodeCampLogo from '../../../assets/icons/freecodecamp';
import FreeCodeCampLogo from '../../../assets/icons/freecodecamp-logo';
import MicrosoftLogo from '../../../assets/icons/microsoft-logo';

import './exam-nav.css';
Expand Down
16 changes: 0 additions & 16 deletions client/src/components/Header/components/nav-logo.tsx

This file was deleted.

10 changes: 7 additions & 3 deletions client/src/components/Header/components/universal-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { useMediaQuery } from 'react-responsive';
import { isLanding } from '../../../utils/path-parsers';
import { Link, SkeletonSprite } from '../../helpers';
import { SEARCH_EXPOSED_WIDTH } from '../../../../config/misc';
import FreeCodeCampLogo from '../../../assets/icons/freecodecamp-logo';
import MenuButton from './menu-button';
import NavLinks, { type NavLinksProps } from './nav-links';
import NavLogo from './nav-logo';
import './universal-nav.css';
import AuthOrProfile from './auth-or-profile';
import LanguageList from './language-list';

import './universal-nav.css';

const SearchBar = Loadable(() => import('../../search/searchBar/search-bar'));
const SearchBarOptimized = Loadable(
() => import('../../search/searchBar/search-bar-optimized')
Expand Down Expand Up @@ -62,7 +63,10 @@ const UniversalNav = ({
to='/learn'
data-playwright-test-label='header-universal-nav-logo'
>
<NavLogo />
<FreeCodeCampLogo
aria-label={t('aria.fcc-curriculum')}
data-playwright-test-label='header-logo'
/>
</Link>
<div className='universal-nav-right main-nav'>
{pending ? (
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getStageOrder,
superBlockStages
} from '../../../../shared/config/curriculum';
import { SuperBlockIcon } from '../../assets/icons/superblock-icon';
import { SuperBlockIcon } from '../../assets/superblock-icon';
import LinkButton from '../../assets/icons/link-button';
import { ButtonLink } from '../helpers';
import { getSuperBlockTitleForMap } from '../../utils/superblock-map-titles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DropDown from '../../../assets/icons/dropdown';
// TODO: See if there's a nice way to incorporate the structure into data Gatsby
// sources from the curriculum, rather than importing it directly.
import superBlockStructure from '../../../../../curriculum/superblock-structure/full-stack.json';
import { ChapterIcon } from '../../../assets/icons/chapter-icon';
import { ChapterIcon } from '../../../assets/chapter-icon';
import { FsdChapters } from '../../../../../shared/config/chapters';
import Block from './block';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { Alert, Spacer } from '@freecodecamp/ui';
import { SuperBlocks } from '../../../../../shared/config/curriculum';
import { SuperBlockIcon } from '../../../assets/icons/superblock-icon';
import { SuperBlockIcon } from '../../../assets/superblock-icon';
import { Link } from '../../../components/helpers';

interface SuperBlockIntroProps {
Expand Down
1 change: 1 addition & 0 deletions shared/config/chapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum FsdChapters {
Html = 'html',
Css = 'css',
Javascript = 'javascript',
FrontendLibraries = 'frontend-libraries',
RelationalDatabases = 'relational-databases',
Security = 'security-and-privacy'
}

0 comments on commit 70f20b9

Please sign in to comment.