Level 2 Team Project

Emoji Personality Test App

Overview

This guide walks you through building the Emoji Personality Test App using Vite with the React (JavaScript) template. By the end, you’ll understand how each part works and how to complete the handleClick function to move emojis between columns, track the count, and reveal results.

Step 1. Initialize the Project

  1. Create a new Vite app:

  2. Install dependencies:

  3. Open your editor and confirm the generated files:

    • package.json, vite.config.js

    • src/ and data/ and components/ directory. If not created, create them now.


Step 2. Project Structure


Step 3. Data Source (data/emojis.js)

  • Contains a default export: an array of hundreds of emoji strings.

  • Used by getRandomEmojis() to pick three at random each round.

17KB
Open

4. Styling (style.css)

Key classes:

  • .wrapper: centers and sizes the app container

  • .overall-emojis-container: lays out the three buttons horizontally

  • .overall-emoji-lists-container: holds the two list columns

  • .individual-emoji-list-container: styles each column

  • .results-modal-container: full-screen overlay for results

No changes are needed here unless you want to customize visuals.

Adjusting Emoji Size in Lists

If your emoji list items overflow, reduce their font sizes in style.css:


Step 5. Main Logic (AppEmojiPersonality.jsx)

The following is the complete AppEmojiPersonality.jsx file with comments highlighting each part:

Main Logic (Step 5)

  • State Initialization: Five useState hooks manage distinct parts of the UI:

    • likedEmojis and passedEmojis collect user choices over time.

    • currentEmojis holds the three emojis displayed each round, initialized by calling getRandomEmojis.

    • showResults and resultsReady control the flow and timing of the results modal.

  • Emojis Selection Flow (handleClick):

    1. Identify Clicked Emoji: using event.target.innerText.

    2. Update Liked List: appends the clicked emoji to the existing array (setLikedEmojis(prev => [...prev, clicked])).

    3. Update Passed List: filters out the clicked emoji and appends the remaining two (setPassedEmojis(prev => [...prev, ...others])).

    4. Next Round: refreshes currentEmojis by re-invoking getRandomEmojis, triggering a re-render with new choices.

  • Randomization (getRandomEmojis):

    • Chooses three emojis independently by randomly indexing into the imported emojis array.

    • Ensures every round offers fresh, unpredictable options.

  • Results Cycle:

    • Trigger: After 10 selections (reflected by likedEmojis.length), the Get Results button becomes visible.

    • Timing: Clicking it sets showResults true, and an effect hook starts a 2 s timer before marking resultsReady — enabling a simple "loading" animation via CSS.

  • Utility Helpers:

    • generateListItems ensures each list item has a unique key, preventing React warnings and enabling proper reconciliation.

Step 6. Display Components

components/EmojiLists.jsx

components/ResultsModal.jsx

Explanation for Display Components (Step 6)

  • Props-Driven Rendering:

    • Both EmojiLists and ResultsModal receive state and helper functions via props — keeping them stateless and reusable.

  • Conditional UI (ResultsModal):

    • Returns null until showResults is true.

    • Inside, it toggles between two states: a Get Results button (waiting on user click) and the final emoji list (once resultsReady is true), plus a Try Again button to reset.

  • Flex Layout:

    • <div className="overall-emoji-lists-container"> uses CSS flexboxes to lay out columns side by side.

    • Each <ul> wraps emojis with appropriate font sizes for visual hierarchy.

  • Separation of Concerns:

    • Core logic resides in the main App component; display-only components simply render based on props, simplifying testing and maintenance.

Display Components (Section 6)

  • Props-Driven Rendering:

    • Both EmojiLists and ResultsModal receive state and helper functions via props — keeping them stateless and reusable.

  • Conditional UI (ResultsModal):

    • Returns null until showResults is true.

    • Inside, it toggles between two states: a Get Results button (waiting on user click) and the final emoji list (once resultsReady is true), plus a Try Again button to reset.

  • Flex Layout:

    • <div className="overall-emoji-lists-container"> uses CSS flexboxes to lay out columns side by side.

    • Each <ul> wraps emojis with appropriate font sizes for visual hierarchy.

  • Separation of Concerns:

    • Core logic resides in the main App component; display-only components simply render based on props, simplifying testing and maintenance.


Step 7. Run & Test

  1. Start the dev server:

  2. Interact with the three emojis.

  3. Observe:

    • Emojis move into the correct columns.

    • Counter increments from 0 → 10.

    • At 10, click Get Results, then Try Again to reset.

Output:

Last updated