Skip to content

Commit

Permalink
Merge pull request #80 from G-Techs/ft-scrolltop-on-selected-element
Browse files Browse the repository at this point in the history
  • Loading branch information
Derick1530 authored Dec 30, 2022
2 parents 85d2027 + 9f3665d commit 12eb6bf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions components/modules/NewReleases/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @next/next/no-img-element */
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import { songs } from "../utils/dummy";
import { VDots, VStar } from "../__modules__/_Vectors";
import AudioPlayer from "../utils/config/audioPlayer";
Expand All @@ -8,12 +8,16 @@ import liveBg from "../static/images/livebg.jpg";
import Equalizer from "./Equalizer";
import { ISong } from "../../../types";
import PlayerController from "./PlayerController";
import { type } from "os";

const NewReleases = () => {
const [isPlaying, setIsPlaying] = useState(-1);
const [isPaused, setIsPaused] = useState(false);
const [tracks, setTracks] = useState<ISong[]>(songs);

const offsetH= useRef<HTMLDivElement>(null);
const clientH= useRef<HTMLDivElement>(null);

return (
<div className="mt-20 mr-5 bg-white shadow-lg rounded-bl-[3.125rem]">
<p className="text-2xl py-5 px-5 bg-white text-gray-700 font-bold">
Expand All @@ -40,12 +44,20 @@ const NewReleases = () => {
</div>
</div>
</div>
<div className="m-5 overflow-y-hidden lg:mt-0 mt-6">
<div ref={offsetH} className="m-5 overflow-y-scroll scroll-smooth no-scrollbar lg:mt-0 mt-6">
{songs.map((item, index) => {
return (
<div
<div
key={index}
onClick={() => setIsPlaying(index)}
ref={clientH}
// this behavior scroll the selected element to the top of the parent div
onClick={() => {
if(offsetH.current){
offsetH.current.scrollTop = 90 *index
}
setIsPlaying(index)}

}
className={`flex cursor-pointer hover:bg-opacity-50 hover:placeholder:bg-black my-4 p-2 items-center justify-between rounded-md ${
isPlaying === index ? "bg-black/40 backdrop-blur-md" : ""
}`}
Expand Down

1 comment on commit 12eb6bf

@vercel
Copy link

@vercel vercel bot commented on 12eb6bf Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

yokaa-frontend – ./

yokaa-frontend.vercel.app
yokaa-frontend-yokaa.vercel.app
yokaa-frontend-git-main-yokaa.vercel.app

Please sign in to comment.