Follow along as we build out a gamified study platform using Trophy with achievements, a daily streak and engaging automated email campaigns.
npm
:
--force
but you should choose whichever setting you feel suits your requirements.
front
property to store questions that the student wants to learn the answer to, and the back
property to store the answers to each question:
carousel
and card
components from shadcn/ui so we need to add these to our project:
<Flashcards />
component that combines these into a working solution, specifying that we can pass along any list of IFlashcard
objects as props
page.tsx
file to display our <Flashcards />
component, passing in our example flashcard data:
<Flashcard />
component that will be responsible for all the logic for each flashcard:
<Flashcards />
component to instead just render out a list of the individual <Flashcard />
components:
side
state variable that will hold the current side of the flashcard that’s showing.onClick()
callback to the <Card />
component that will update the side
state to back
when clicked if the front of the card is currently showing.<Card />
based on the value of the side
state variable.<motion.div />
with a light spring animation in the y-axis to create the effect:
<Card />
is flipping, the ‘backface’ isn’t visible during the animation with backface-visibility: hidden;
<Card />
component is a child of the <motion.div />
, usually it would appear flat when it’s parent rotates in 3D. Adding transform-style: preserve-3d;
to the <Card />
ensures it keeps it’s 3D effect when it’s parent animates.motion
to literally flip over our card in the Y-axis, we need to make sure we write our answers backwards as well.
First, we’ll add a little CSS snippet to handle writing text backwards:
progress
component from shadcn/ui to our project:
Create the metric
flashcards-viewed
as the metric key
. This is what we’ll use to reference the metric in our code when sending events.Create achievements
Configure daily streak
Configure emails
achievements
array which is a list of newly unlocked achievements as a result of the event.currentStreak
object which is the users most up to date streak data after the event has taken place.sonner
component from shadcn/ui to our project:
<Toast />
UI component we need to display toasts and a toast()
utility function to trigger them:
page.tsx
file with the main <Toaster />
component. This is the component from sonner
which is responsible for displaying our toasts on the screen when we trigger them:
<Flashcards />
component to read the response from Trophy and display toasts for any unlocked achievements:
currentStreak.extended
property from Trophy and handle showing another toast with a new if
statement:
public/sounds
directory. Feel free to use them or pick others you like!play()
method on each when we want to actually play the sound:
<StudyJourney />
component that takes in the achievements and streak data as props and renders it nicely in a dialog. Before adding this we need to add the shadcn/ui dialog
component to our project, and while we’re at it, we’ll add the seperator
component too:
dayjs
to help us with displaying dates nicely as well:
demo
branch in the GitHub repo.