A Political Alignment Trivia Game
LeftRight is an engaging political alignment quiz web application designed with a modern swiping interface. Mimicking the interaction style of Tinder, users can swipe right to agree or left to disagree with a series of trivia questions. The game calculates their political alignment based on their responses and provides a summary of their alignment in a results screen.
- Users interact by swiping cards left or right to answer questions.
- Each swipe indicates agreement (right) or disagreement (left) with the question.
- Questions are dynamically selected and shuffled from four predefined categories: Economic, Social, Foreign, and Domestic.
- Ensures a balanced question set for each quiz session.
- Swipes are registered instantly, and the interface updates dynamically.
- Smooth animations enhance user experience.
- Uses user responses to calculate their political alignment (e.g., left-leaning, right-leaning, or centrist).
- Displays results on a dedicated summary screen.
- Optimized for mobile, tablet, and desktop devices.
- Dynamically adjusts padding and card heights to prevent overflow and ensure usability.
- Provides feedback for specific actions (e.g., copying a link) using toast notifications.
-
React + TypeScript:
- Provides a type-safe and modular structure for building interactive UI components.
- Key components:
CardStack
: Manages the stack of swipable cards.QuestionCard
: Displays individual trivia cards.ResultScreen
: Shows the user's political alignment after completing the quiz.
-
Framer Motion:
- Enables smooth animations for swiping and gestures.
- Handles drag gestures for interactive swiping mechanics.
-
Tailwind CSS:
- Ensures clean, utility-first responsive styling.
- useState and useEffect:
- Tracks game state, user responses, and whether the game is complete.
- Dynamic Question Selection:
- Shuffles and selects questions using
lodash.shuffle
. - Categorizes questions to ensure balanced representation.
- Shuffles and selects questions using
- Uses a custom
useDeviceType
hook to detect device type and adjust layout dynamically. - Ensures a consistent experience across screen sizes.
- Questions are divided into four categories:
- Economic, Social, Foreign, Domestic.
- Three questions are selected randomly from each category.
- Users swipe cards left to disagree or right to agree.
- Swipes trigger animations and update the user’s responses.
- A custom alignment algorithm processes the responses and determines the user's political stance.
- Results are displayed in a visually appealing summary screen.
- Users start the quiz by swiping through trivia cards.
- For each question, users swipe left or right to register their responses.
- After all questions are answered, the app calculates their political alignment and displays the result.
- On initialization:
- Questions are shuffled and categorized.
- State variables (
responses
,gameComplete
, etc.) are initialized.
- During the game:
- Swiping a card updates the
responses
state. - Animation and feedback are provided in real-time.
- Swiping a card updates the
- After the game:
- Results are calculated using
calculateAlignment
. - The result screen is displayed.
- Results are calculated using
- Resolved overflow and spacing issues by dynamically adjusting padding and height based on the device type.
- Optimized swipe animations with Framer Motion to ensure responsiveness on mobile and desktop.
- Designed a modern, intuitive interface to make the game fun and accessible.
-
Customizable Questions:
- Allow users to add or select questions for a personalized experience.
-
Social Sharing:
- Enable users to share their results on social media platforms.
-
Detailed Analysis:
- Provide detailed insights and breakdowns of the user’s political alignment.
-
Gamification:
- Introduce badges or achievements to enhance engagement.
-
AI-Generated Questions:
- Use AI to dynamically generate unique questions tailored to user preferences.
- Use Chrome DevTools to analyze performance and FPS.
- Optimize animations and event handlers for responsiveness.
- Test on different devices using browser DevTools or physical devices.
- Built with ❤️ using React, TypeScript, Tailwind CSS, and Framer Motion.
- Inspired by interactive quiz platforms and swipe-based apps like Tinder.