Feedback

Adding an album changes a badge and a number in the header. A toast makes it unmistakable.

$ puzzle add piece toast
puzzle add piece · npm:@magic-spells/puzzle-pieces@0.9.0
  ✓ toast · 2 files

  Next steps
    → add `@import './pieces.css';` to app/styles/styles.css (after `@import "tailwindcss";`)

styles.css imports the tokens already, so there is nothing else to do. The piece is two files:

  • toast.js exports toast(), a plain function you call from anywhere: toast({ title, message, variant }). Variants are default, success and danger; toasts dismiss themselves after five seconds and pause while the pointer is over them.
  • Toaster.pzl is the host that shows them. Mount it once, in the layout, so every page has it.

Your turn

  1. In Default.pzl, import Toaster from ../components/ui/Toaster.pzl and put <Toaster/> after </main>.
  2. In Shop.pzl, import { toast } from '@/components/ui/toast.js', and make add say so:
add: (album) => {
  album.update({ inPlaylist: true });
  toast({ title: 'Added to playlist', message: album.title, variant: 'success' });
},

Add a few albums. The toasts stack in the corner and leave on their own.

Chapters