diff --git a/components/Loader.js b/components/Loader.js new file mode 100644 index 0000000..ad4cbac --- /dev/null +++ b/components/Loader.js @@ -0,0 +1,10 @@ +import css from "challenges/styles/loader.module.scss"; + +/** + * Simple Loading component which can be styled afterwards + * @param {props} props + * @returns Loader Component + */ +export default function Loader(props) { + return
; +} \ No newline at end of file diff --git a/layouts/Header.js b/layouts/Header.js index a6c9c16..d571366 100644 --- a/layouts/Header.js +++ b/layouts/Header.js @@ -1,7 +1,9 @@ import { Component, createRef } from "react"; +import { withRouter } from "next/router"; +import Link from "next/link"; + import css from "challenges/styles/header.module.scss"; -import Link from "next/link"; import Logo from "challenges/assets/logo.svg"; @@ -18,21 +20,25 @@ import { import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -export class Header extends Component { - constructor() { - super(); +class Header extends Component { + constructor(props) { + super(props); + + this.props = props; this.header = createRef(null); this.headerPlaceholder = createRef(null); this.buttonText = createRef(null); - this.toggleWidth = this.toggleWidth.bind(this); - /** * true = expanded * false = collapsed - */ + */ this.width = true; + + + this.toggleWidth = this.toggleWidth.bind(this); + this.highlightActiveLink = this.highlightActiveLink.bind(this); } @@ -57,20 +63,64 @@ export class Header extends Component { } + /** + * Highlights the current route by adding a the + * css.active class + */ + highlightActiveLink() { + + const pathname = this.props.router.asPath; + + const results = document.querySelectorAll(`.${css.scrollSection} a[href="${pathname}"]`); + const oldRouteElements = document.querySelectorAll(`.${css.scrollSection} a.${css.active}`); + + for (let i = 0; i < oldRouteElements.length; i++) { + const old = oldRouteElements[i]; + old.classList.remove(css.active); + + } + + for (let i = 0; i < results.length; i++) { + const result = results[i]; + result.classList.add(css.active); + } + + } + + + componentDidMount() { + + this.props.router.events.on("routeChangeComplete", this.highlightActiveLink); + this.props.router.events.on("routeChangeError", this.highlightActiveLink); + this.highlightActiveLink(); + + } + + + componentWillUnmount() { + + this.props.router.events.off("routeChangeComplete", this.highlightActiveLink); + this.props.router.events.off("routeChangeError", this.highlightActiveLink); + + } + + render() { + const router = this.router; + return <>