mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-20 22:24:28 +01:00
new celebration effect
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version 0.1.4
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- new effect when redeeming wishlist
|
||||||
|
|
||||||
## Version 0.1.3
|
## Version 0.1.3
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect, useRef } from 'react'
|
||||||
import { Plus, Gift } from 'lucide-react'
|
import { Plus, Gift } from 'lucide-react'
|
||||||
import EmptyState from './EmptyState'
|
import EmptyState from './EmptyState'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
@@ -29,8 +29,9 @@ export default function WishlistManager() {
|
|||||||
itemId: null
|
itemId: null
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
const itemRefs = useRef<Record<string, HTMLDivElement | null>>({})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
// Check URL for highlight parameter
|
// Check URL for highlight parameter
|
||||||
const params = new URLSearchParams(window.location.search)
|
const params = new URLSearchParams(window.location.search)
|
||||||
const highlightId = params.get('highlight')
|
const highlightId = params.get('highlight')
|
||||||
@@ -38,7 +39,7 @@ export default function WishlistManager() {
|
|||||||
setHighlightedItemId(highlightId)
|
setHighlightedItemId(highlightId)
|
||||||
// Scroll the element into view after a short delay to ensure rendering
|
// Scroll the element into view after a short delay to ensure rendering
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const element = document.getElementById(`wishlist-${highlightId}`)
|
const element = itemRefs.current[highlightId]
|
||||||
if (element) {
|
if (element) {
|
||||||
element.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
element.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||||
}
|
}
|
||||||
@@ -78,19 +79,27 @@ export default function WishlistManager() {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
wishlistItems.map((item) => (
|
wishlistItems.map((item) => (
|
||||||
<WishlistItem
|
<div
|
||||||
key={item.id}
|
key={item.id}
|
||||||
item={item}
|
ref={(el) => {
|
||||||
isHighlighted={item.id === highlightedItemId}
|
if (el) {
|
||||||
isRecentlyRedeemed={item.id === recentlyRedeemedId}
|
itemRefs.current[item.id] = el
|
||||||
onEdit={() => {
|
}
|
||||||
setEditingItem(item)
|
}}
|
||||||
setIsModalOpen(true)
|
>
|
||||||
}}
|
<WishlistItem
|
||||||
onDelete={() => setDeleteConfirmation({ isOpen: true, itemId: item.id })}
|
item={item}
|
||||||
onRedeem={() => handleRedeem(item)}
|
isHighlighted={item.id === highlightedItemId}
|
||||||
canRedeem={canRedeem(item.coinCost)}
|
isRecentlyRedeemed={item.id === recentlyRedeemedId}
|
||||||
/>
|
onEdit={() => {
|
||||||
|
setEditingItem(item)
|
||||||
|
setIsModalOpen(true)
|
||||||
|
}}
|
||||||
|
onDelete={() => setDeleteConfirmation({ isOpen: true, itemId: item.id })}
|
||||||
|
onRedeem={() => handleRedeem(item)}
|
||||||
|
canRedeem={canRedeem(item.coinCost)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -50,9 +50,7 @@ export function useWishlist() {
|
|||||||
|
|
||||||
// Randomly choose a celebration effect
|
// Randomly choose a celebration effect
|
||||||
const celebrationEffects = [
|
const celebrationEffects = [
|
||||||
celebrations.basic,
|
celebrations.emojiParty
|
||||||
celebrations.fireworks,
|
|
||||||
celebrations.shower
|
|
||||||
]
|
]
|
||||||
const randomEffect = celebrationEffects[Math.floor(Math.random() * celebrationEffects.length)]
|
const randomEffect = celebrationEffects[Math.floor(Math.random() * celebrationEffects.length)]
|
||||||
randomEffect()
|
randomEffect()
|
||||||
|
|||||||
10
package-lock.json
generated
10
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "habittrove",
|
"name": "habittrove",
|
||||||
"version": "0.1.1",
|
"version": "0.1.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "habittrove",
|
"name": "habittrove",
|
||||||
"version": "0.1.1",
|
"version": "0.1.3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@next/font": "^14.2.15",
|
"@next/font": "^14.2.15",
|
||||||
"@radix-ui/react-dialog": "^1.1.4",
|
"@radix-ui/react-dialog": "^1.1.4",
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^3.6.0",
|
||||||
|
"js-confetti": "^0.12.0",
|
||||||
"lucide-react": "^0.469.0",
|
"lucide-react": "^0.469.0",
|
||||||
"next": "15.1.3",
|
"next": "15.1.3",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
@@ -5021,6 +5022,11 @@
|
|||||||
"jiti": "bin/jiti.js"
|
"jiti": "bin/jiti.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/js-confetti": {
|
||||||
|
"version": "0.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-confetti/-/js-confetti-0.12.0.tgz",
|
||||||
|
"integrity": "sha512-1R0Akxn3Zn82pMqW65N1V2NwKkZJ75bvBN/VAb36Ya0YHwbaSiAJZVRr/19HBxH/O8x2x01UFAbYI18VqlDN6g=="
|
||||||
|
},
|
||||||
"node_modules/js-tokens": {
|
"node_modules/js-tokens": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "habittrove",
|
"name": "habittrove",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^3.6.0",
|
||||||
|
"js-confetti": "^0.12.0",
|
||||||
"lucide-react": "^0.469.0",
|
"lucide-react": "^0.469.0",
|
||||||
"next": "15.1.3",
|
"next": "15.1.3",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
|
|||||||
@@ -1,6 +1,24 @@
|
|||||||
import confetti from 'canvas-confetti'
|
import confetti from 'canvas-confetti'
|
||||||
|
import JSConfetti from 'js-confetti'
|
||||||
|
|
||||||
|
let jsConfetti: JSConfetti | null = null
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
jsConfetti = new JSConfetti()
|
||||||
|
}
|
||||||
|
|
||||||
export const celebrations = {
|
export const celebrations = {
|
||||||
|
emojiParty: () => {
|
||||||
|
if (jsConfetti) {
|
||||||
|
// 20% chance to use only coin emoji
|
||||||
|
const useCoinsOnly = Math.random() < 0.2
|
||||||
|
jsConfetti.addConfetti({
|
||||||
|
emojis: useCoinsOnly ? ['💰', '🪙'] : ['🎉', '✨', '🦄', '🌈', '⚡️', '🌸', '💫', '🌟'],
|
||||||
|
emojiSize: 50,
|
||||||
|
confettiNumber: useCoinsOnly ? 50 : 30, // More coins when it's coin-only
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
basic: () => {
|
basic: () => {
|
||||||
confetti({
|
confetti({
|
||||||
particleCount: 200,
|
particleCount: 200,
|
||||||
@@ -14,7 +32,7 @@ export const celebrations = {
|
|||||||
const animationEnd = Date.now() + duration
|
const animationEnd = Date.now() + duration
|
||||||
const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 }
|
const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 }
|
||||||
|
|
||||||
const interval: any = setInterval(function() {
|
const interval: any = setInterval(function () {
|
||||||
const timeLeft = animationEnd - Date.now()
|
const timeLeft = animationEnd - Date.now()
|
||||||
|
|
||||||
if (timeLeft <= 0) {
|
if (timeLeft <= 0) {
|
||||||
@@ -34,25 +52,25 @@ export const celebrations = {
|
|||||||
const end = Date.now() + 2000
|
const end = Date.now() + 2000
|
||||||
|
|
||||||
const colors = ['#ff0000', '#00ff00', '#0000ff']
|
const colors = ['#ff0000', '#00ff00', '#0000ff']
|
||||||
;(function frame() {
|
; (function frame() {
|
||||||
confetti({
|
confetti({
|
||||||
particleCount: 2,
|
particleCount: 2,
|
||||||
angle: 60,
|
angle: 60,
|
||||||
spread: 55,
|
spread: 55,
|
||||||
origin: { x: 0 },
|
origin: { x: 0 },
|
||||||
colors: colors
|
colors: colors
|
||||||
})
|
})
|
||||||
confetti({
|
confetti({
|
||||||
particleCount: 2,
|
particleCount: 2,
|
||||||
angle: 120,
|
angle: 120,
|
||||||
spread: 55,
|
spread: 55,
|
||||||
origin: { x: 1 },
|
origin: { x: 1 },
|
||||||
colors: colors
|
colors: colors
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Date.now() < end) {
|
if (Date.now() < end) {
|
||||||
requestAnimationFrame(frame)
|
requestAnimationFrame(frame)
|
||||||
}
|
}
|
||||||
}())
|
}())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user