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
Create a new Vite app:
Install dependencies:
Open your editor and confirm the generated files:
package.json,vite.config.jssrc/anddata/andcomponents/directory. If not created, create them now.
Step 2. Project Structure
Step 3. Data Source (data/emojis.js)
data/emojis.js)Contains a default export: an array of hundreds of emoji strings.
Used by
getRandomEmojis()to pick three at random each round.
4. Styling (style.css)
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)
AppEmojiPersonality.jsx)The following is the complete AppEmojiPersonality.jsx file with comments highlighting each part:
Main Logic (Step 5)
State Initialization: Five
useStatehooks manage distinct parts of the UI:likedEmojisandpassedEmojiscollect user choices over time.currentEmojisholds the three emojis displayed each round, initialized by callinggetRandomEmojis.showResultsandresultsReadycontrol the flow and timing of the results modal.
Emojis Selection Flow (
handleClick):Identify Clicked Emoji: using
event.target.innerText.Update Liked List: appends the clicked emoji to the existing array (
setLikedEmojis(prev => [...prev, clicked])).Update Passed List: filters out the clicked emoji and appends the remaining two (
setPassedEmojis(prev => [...prev, ...others])).Next Round: refreshes
currentEmojisby re-invokinggetRandomEmojis, triggering a re-render with new choices.
Randomization (
getRandomEmojis):Chooses three emojis independently by randomly indexing into the imported
emojisarray.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
showResultstrue, and an effect hook starts a 2 s timer before markingresultsReady— enabling a simple "loading" animation via CSS.
Utility Helpers:
generateListItemsensures each list item has a uniquekey, preventing React warnings and enabling proper reconciliation.
Step 6. Display Components
components/EmojiLists.jsx
components/EmojiLists.jsxcomponents/ResultsModal.jsx
components/ResultsModal.jsxExplanation for Display Components (Step 6)
Props-Driven Rendering:
Both
EmojiListsandResultsModalreceive state and helper functions via props — keeping them stateless and reusable.
Conditional UI (ResultsModal):
Returns
nulluntilshowResultsis true.Inside, it toggles between two states: a Get Results button (waiting on user click) and the final emoji list (once
resultsReadyis 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
Appcomponent; display-only components simply render based on props, simplifying testing and maintenance.
Display Components (Section 6)
Props-Driven Rendering:
Both
EmojiListsandResultsModalreceive state and helper functions via props — keeping them stateless and reusable.
Conditional UI (ResultsModal):
Returns
nulluntilshowResultsis true.Inside, it toggles between two states: a Get Results button (waiting on user click) and the final emoji list (once
resultsReadyis 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
Appcomponent; display-only components simply render based on props, simplifying testing and maintenance.
Step 7. Run & Test
Start the dev server:
Interact with the three emojis.
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