Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented music player #35

Closed
wants to merge 2 commits into from
Closed

Conversation

roopeshsn
Copy link

Implemented a minimal music player.

@vercel
Copy link

vercel bot commented Nov 4, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
bio ✅ Ready (Inspect) Visit Preview Nov 4, 2022 at 0:04AM (UTC)

@roopeshsn
Copy link
Author

Hi, @heysagnik! I have to migrate this code to packages/Linkees. I'll do that ASAP. However, how is the music player? Do you like it? https://bio-qfmwydhpi-heysagnik.vercel.app/

@heysagnik
Copy link
Owner

Ok 👌


function App(): JSX.Element {
const [view, setView] = React.useState(false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make it more clear.

If we are using view, then its type should be an enum value instead of a boolean because we want to make the view more declarative.

Here, we are just using the state if we want to show music player or not and hide or show it. We can create a custom hook named useVisibilityToggle for it and use it here

const useVisibilityToggle = (initialState: boolean): {
  isVisible: boolean;
  show: () => void;
  hide: () => void;
  toggleVisibility: () => void
} => {
  const [isVisible, setIsVisible] = React.useState(initialState);

  const show = useCallback(() => {
    setIsVisible(true);
  }, []);

    const hide = useCallback(() => {
      setIsVisible(true);
    }, []);

   const toggleVisibility = useCallback(() => {
    setIsVisible(visible => !visible);
   }, []);

  return { isVisible, show, hide, toggleVisibility }
}

@@ -58,4 +64,17 @@ const items: ItemType[] = [{
"link": "https://telegram.me/heysagnik" //Telegram Pofile
}]

export default items
const songs: SongType[] = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

This contract looks good for the package. @heysagnik do we need to give a default song player? I don't think that is required. If we do that, we will have to find an extension to bundle mp3 files with webpack. It's better to leave that head ache for the consumers

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah


export default function MusicPlayer(props: any) {
const [isPlaying, setIsPlaying] = useState(true)
const [isPlayAnime, setIsPlayAnime] = useState(false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like a redundant state. Why can't we govern the same behaviour with isPlaying state?

const [isPlayAnime, setIsPlayAnime] = useState(false)
const totalSongs = songs.length
let songIdx = 0
const [song, setSong] = useState({info: songs[songIdx], audioSrc: new Audio(songs[songIdx].audio)})
Copy link
Collaborator

Choose a reason for hiding this comment

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

React state should have minimal information. All the information which are kept in this state is derived information and can be retrieved easily with currentSongIndex. So, keep state for currentSongIndex only and derive this information on rerenders.

@taksuparth
Copy link
Collaborator

@roopeshsn thank you for taking out time to contribute to this project 🎉 Please resolve merge conflicts and try to move this code in the packages/Linkees. Looking forward for your contributions!

@roopeshsn
Copy link
Author

roopeshsn commented Nov 10, 2022

Hi, @taksuparth! Thanks for the feedback! Will make the necessary changes as said by you!

@taksuparth
Copy link
Collaborator

Hi @roopeshsn! Any update on this?

@roopeshsn roopeshsn closed this Jul 11, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants