Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

Github User Search App

sass/scss, fetch
Andrew Simons•290
@AndrewSimons3
A solution to the GitHub user search app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I found the most difficult part to be the light/dark mode. Perhaps I went the wrong way about it but I ended up selecting all of the html tags specifically to assign colors and backgrounds and toggling a "light-mode" class on and off.

Also updating each innerHTML element with the data became quite meticulous as well. Not sure if there is a better way to go about this in pure JS. The error handling may also need work. All in all it was a really fun challenge and am proud of the result. Any feedback is greatly appreciated!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Elaine•11,360
    @elaineleung
    Posted almost 3 years ago

    Hi Andrew, about the light/dark mode, you can check out Adam Argyle's post here, which helped me a lot when I was building my calculator with 3 themes: https://web.dev/building-a-theme-switch-component/. This is useful if you want to use prefers-color-scheme before the page loads. His tutorial also shows how the icon can be changed, so that might help you out as well! Also, if you're interested, here is the calculator app I built using his tutorial.

    Marked as helpful
  • Md5 dalton•1,430
    @md5dalton
    Posted almost 3 years ago

    Hello Andrew. Congratulations on finishing the challenge.

    Here is one of multiple ways you can achieve switching between light and dark mode.

    • First let's setup some CSS custom properties for colors
    :root {
        --color-bg: #FFFFFF;
        --color-text: #222731;
    }
    body.dark {
        --color-bg: #141d2f;
        --color-text: #FFFFFF;
    }
    body {
        background-color: var(--color-bg);
        color: var(--color-text);
    }
    
    • Second let's write a JavaScript class to handle the logic:
    // Helper fn for getting DOM Element
    const getDOM = selector => document.querySelector(selector)
    
    class ThemeToggler
    {
        defaultTheme = "light"
        altTheme = "dark"
    
        theme = ""
    
        constructor (elm) {
            this.getTheme()
            this.updateUI()
            elm.addEventListener("click", () => this.toggleTheme())
        }
    
        getTheme () {
            this.theme = localStorage.getItem("theme") || this.defaultTheme
        }
    
        setTheme (theme) {
            this.theme = theme
            localStorage.setItem("theme", theme)
        }
    
        toggleTheme () {
    
            this.getTheme()
    
            const newTheme = this.theme !== this.defaultTheme ? this.defaultTheme : this.altTheme  
            
            this.setTheme(newTheme)
            this.updateUI()
    
        }
    
        updateUI () {
            document.body.classList.remove(this.defaultTheme, this.altTheme)
            document.body.classList.add(this.theme)
    
            const span = getDOM(".toggle span")
            const icon = getDOM(".toggle img")
    
            span.innerText = this.theme
            icon.src = `./assets/icon-${this.theme === this.altTheme ? "sun" : "moon"}.svg`
    
        }
    }
    
    new ThemeToggler(getDOM(".toggle"))
    
    • Lastly modify your HTML a bit by removing the 2 spans and replace them with just one <span></span>. The same goes for the icon image tags: <img alt="theme icon" />

    You may check the original code on my GitHub repo: Theme Toggler

    I hope that helps👌

    Marked as helpful
  • Vanza Setia•27,715
    @vanzasetia
    Posted almost 3 years ago

    Hello, Andrew Simons! 👋

    Congratulations on completing this challenge! 🎉

    Before diving into JavaScript, we need to get the HTML right first for the theme switcher.

    • First, it is not a link (anchor tag). It should be either a button or a checkbox input. Remember that, anchor tags are for navigation. For doing an action (like in this case switching theme), use the button element (or checkbox input).
    • Second, the users should be able to click the text content to switch the theme. The icon itself is a very small target to click or touch (for mobile users).
    • Lastly, I recommend reading the inclusive component article about Toggle Buttons to help create an accessible theme switcher.

    I notice that the value for the office is the GitHub URL of the user's profile. It should be the company value. So, I would recommend fixing this. 🙂

    Hope this helps! 🙂

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub