Skip to content

Commit

Permalink
Merge pull request #42 from UNIZAR-30226-2024-03/DashboardCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
Arejula11 authored Mar 30, 2024
2 parents 632f42f + 98fcf7e commit 87c1003
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 15 deletions.
15 changes: 15 additions & 0 deletions playbeat/src/components/Contador.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { numProgressives } from '@/hooks/numProgressives'
import { useEffect} from 'react'

export const Contador = (
{ initial, final, decimals, duration }:
{ initial: number, final: number, decimals?: number, duration?: number }
) => {
const [count, setCount] = numProgressives(initial, duration, decimals)

useEffect(() => {
setCount(String(final))
}, [final])

return <span className=' text-3xl font-bold'>{count}</span>
}
54 changes: 54 additions & 0 deletions playbeat/src/hooks/numProgressives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useCallback, useEffect, useState } from 'react'

export const numProgressives = (
initialValue: number | (() => number),
duration = 1500,
decimals = 0,
delay = 5
): [string, (value: string | ((prevTarget: number) => number)) => void] => {
const [target, setTarget] = useState(initialValue)
const [current, setCurrent] = useState(initialValue)
const [steps, setSteps] = useState(1)
const [currentStep, setCurrentStep] = useState(1);

const initial = typeof initialValue === 'function' ? initialValue() : initialValue;

const setValue = useCallback(
(value: string | ((prevTarget: number) => number)) => {
const nextTarget = typeof value === 'function' ? value(target) : value
const steps = Math.max(Math.floor(duration / delay), 1)
setSteps(steps)
setTarget(Number(nextTarget))
setCurrentStep(1);
setCurrent(lerp(initial, Number(nextTarget), easeOutCubic(1 / steps)))
},
[delay, duration, target]
)

useEffect(() => {
const timeout = setTimeout(
() => {
const progress = currentStep / steps;
if (progress === 1) {
setCurrent(target);
} else {
setCurrent(lerp(initial, target, easeOutCubic(progress)))
setCurrentStep(currentStep + 1)
}
},
delay
)

return () => clearTimeout(timeout)
}, [delay, currentStep, target])
const value = current.toFixed(decimals)
return [value, setValue]
}

const lerp = (a: number, b: number, alpha: number): number => {
return a + (alpha * (b - a))
}

const easeOutCubic = (value: number): number => {
return 1 - Math.pow(1 - value, 3)
}
38 changes: 23 additions & 15 deletions playbeat/src/pages/creator.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import CreatorLayout from '@layouts/CreatorLayout.astro';
import HeaderCreator from '@components/HeaderCreator.astro';
import CarrouselTop from '@components/CarrouselTop.astro';
import Carrousel from '@components/Carrousel.astro';
import {Contador} from '@components/Contador.tsx';
const canciones = [
{
title: 'Canción 1',
Expand Down Expand Up @@ -109,7 +111,7 @@ const canciones = [
]
const canciones2 = {num:5,name:"Tu biblioteca", ref:"/creator/tusalbums", items:[{audio:"Cancion1", descripcion:"Artista1"}, {audio:"Cancion2", descripcion:"Artista2"}, {audio:"Cancion3", descripcion:"Artista3"}, {audio:"Cancion4", descripcion:"Artista4"}, {audio:"Cancion5", descripcion:"Artista5"}, {audio:"audio6", descripcion:"Artista6"}, {audio:"audio7", descripcion:"Artista7"}, {audio:"audio8", descripcion:"Artista8"}, {audio:"audio9", descripcion:"Artista9"}, {audio:"audio10", descripcion:"Artista10"}, {audio:"audio11", descripcion:"Artista11"}, {audio:"audio12", descripcion:"Artista12"}, {audio:"audio13", descripcion:"Artista13"}, {audio:"audio14", descripcion:"Artista14"}, {audio:"audio15", descripcion:"Artista15"}, {audio:"audio16", descripcion:"Artista16"}, {audio:"audio17", descripcion:"Artista17"}, {audio:"audio18", descripcion:"Artista18"}, {audio:"audio19", descripcion:"Artista19"}, {audio:"audio20", descripcion:"Artista20"}, {audio:"audio21", descripcion:"Artista21"}, {audio:"audio22", descripcion:"Artista22"}, {audio:"audio23", descripcion:"Artista23"}, {audio:"audio24", descripcion:"Artista24"}, {audio:"audio25", descripcion:"Artista25"}, {audio:"audio26", descripcion:"Artista26"}, {audio:"audio27", descripcion:"Artista27"}, {audio:"audio28", descripcion:"Artista28"}, {audio:"audio29", descripcion:"Artista29"}, {audio:"audio30", descripcion:"Artista30"}, {audio:"audio31", descripcion:"Artista31"}, {audio:"audio32", descripcion:"Artista32"}]}
const canciones2 = {num:3,name:"Tu biblioteca", ref:"/creator/tusalbums", items:[{audio:"Cancion1", descripcion:"Artista1"}, {audio:"Cancion2", descripcion:"Artista2"}, {audio:"Cancion3", descripcion:"Artista3"}, {audio:"Cancion4", descripcion:"Artista4"}, {audio:"Cancion5", descripcion:"Artista5"}, {audio:"audio6", descripcion:"Artista6"}, {audio:"audio7", descripcion:"Artista7"}, {audio:"audio8", descripcion:"Artista8"}, {audio:"audio9", descripcion:"Artista9"}, {audio:"audio10", descripcion:"Artista10"}, {audio:"audio11", descripcion:"Artista11"}, {audio:"audio12", descripcion:"Artista12"}, {audio:"audio13", descripcion:"Artista13"}, {audio:"audio14", descripcion:"Artista14"}, {audio:"audio15", descripcion:"Artista15"}, {audio:"audio16", descripcion:"Artista16"}, {audio:"audio17", descripcion:"Artista17"}, {audio:"audio18", descripcion:"Artista18"}, {audio:"audio19", descripcion:"Artista19"}, {audio:"audio20", descripcion:"Artista20"}, {audio:"audio21", descripcion:"Artista21"}, {audio:"audio22", descripcion:"Artista22"}, {audio:"audio23", descripcion:"Artista23"}, {audio:"audio24", descripcion:"Artista24"}, {audio:"audio25", descripcion:"Artista25"}, {audio:"audio26", descripcion:"Artista26"}, {audio:"audio27", descripcion:"Artista27"}, {audio:"audio28", descripcion:"Artista28"}, {audio:"audio29", descripcion:"Artista29"}, {audio:"audio30", descripcion:"Artista30"}, {audio:"audio31", descripcion:"Artista31"}, {audio:"audio32", descripcion:"Artista32"}]}
---

Expand All @@ -122,29 +124,35 @@ const canciones2 = {num:5,name:"Tu biblioteca", ref:"/creator/tusalbums", items:
</div>
<div class="w-full flex flex-row justify-between mt-5">

<div class="flex flex-col items-center rounded-sm ml-28">
<div class="flex flex-col w-1/4 items-center rounded-sm ml-28">
<h3 class="text-lg p-2">REPRODUCCIONES</h3>
<div class="bg-grey h-[300px] w-[300px]"></div>
<div class="bg-grey h-[200px] w-full flex justify-center items-center">
<Contador initial={0} final={145549} client:load/>
</div>
</div>
<div class="flex flex-col items-center rounded-sm">
<div class="flex flex-col w-1/4 items-center rounded-sm">
<h3 class="text-lg p-2">USUARIOS MENSUALES</h3>
<div class="bg-grey h-[300px] w-[500px]"></div>
<div class="bg-grey h-[200px] w-full flex justify-center items-center">
<Contador initial={0} final={89332} client:load/>
</div>
</div>
<div class="flex flex-col items-center rounded-sm mr-28 ">
<div class="flex flex-col w-1/4 items-center rounded-sm mr-28 ">
<h3 class="text-lg p-2">OYENTES TOTALES</h3>
<div class="bg-grey h-[300px] w-[300px]"></div>
<div class="bg-grey h-[200px] w-full flex justify-center items-center">
<Contador initial={0} final={234332} client:load/>
</div>
</div>
</div>
<div class="w-full flex flex-row justify-between mt-10">
<div class="mx-20">
<a href="/creator/tusaudios"><h3 class="text-4xl mx-[26%] font-semibold hover:underline">TUS CANCIONES</h3></a>
<div class="w-[600px]">
<CarrouselTop info={canciones} num={5}/>
</div>
<div class="ml-20 flex flex-col items-center">
<a href="/creator/tusaudios"><h3 class="text-4xl font-semibold hover:underline">TUS CANCIONES</h3></a>
<div class="w-[600px]">
<CarrouselTop info={canciones} num={5}/>
</div>
</div>
<div class="mx-16 w-[700px]">
<a href="/creator/tusalbums"><h3 class="text-4xl ml-[29%] font-semibold hover:underline">TUS ALBUMS</h3></a>
<Carrousel info={canciones2} />
<div class="ml-8 w-[40%] flex flex-col mr-20">
<a href="/creator/tusalbums" class="self-center"><h3 class="text-4xl font-semibold hover:underline">TUS ALBUMS</h3></a>
<Carrousel info={canciones2} />
</div>
</div>
</div>
Expand Down

0 comments on commit 87c1003

Please sign in to comment.