Skip to content

Commit

Permalink
implement jukebox object, store, network, add info to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
IkeHunter committed Oct 30, 2024
1 parent 1a125ee commit f4460d6
Show file tree
Hide file tree
Showing 32 changed files with 369 additions and 802 deletions.
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SocketProvider, Theme } from './context'
import { SpotifyPlayerProvider } from './context/PlayerContext'
import {
fetchCurrentClubInfo,
fetchJukeboxes,
fetchUserInfo,
initializeUser,
logoutUser,
Expand Down Expand Up @@ -41,6 +42,7 @@ export const App = () => {
setCurrentClub(resUserInfo.clubs[0])
setAllClubs(resUserInfo.clubs)
await fetchCurrentClubInfo()
await fetchJukeboxes()
})
} else if (userInfo || userIsLoggedIn === false) {
logoutUser()
Expand All @@ -49,7 +51,7 @@ export const App = () => {

return (
<Theme>
<SpotifyPlayerProvider token={spotifyAuth?.accessToken}>
<SpotifyPlayerProvider token={spotifyAuth?.access_token}>
<SocketProvider />
<Outlet />
</SpotifyPlayerProvider>
Expand Down
3 changes: 2 additions & 1 deletion src/apps/admin/components/Topbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const Topbar = () => {
const user = useSelector(selectUser)
const clubs = useSelector(selectAllClubs)
const currentClub = useSelector(selectCurrentClub)
// const jukeboxes = useSelector()

const handleClubChange = (e: ChangeEvent<HTMLSelectElement>) => {
const selectedClubId = e.target.value
Expand Down Expand Up @@ -43,7 +44,7 @@ export const Topbar = () => {
</button>
</div>
<button className="topbar__profile">
{user && <img src={user.image} alt={user.lastName} />}
{user && <img src={user.image} alt={user.last_name} />}
{!user && <p>Login required.</p>}
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/apps/admin/pages/MusicSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ export const MusicSearch = () => {
</div>
</div>
)
}
}
111 changes: 52 additions & 59 deletions src/apps/admin/pages/Overview.scss
Original file line number Diff line number Diff line change
@@ -1,85 +1,78 @@
.disk {
align-items: center;
float: right;
display: flex;
height: 100%;
position: relative;
align-items: center;
float: right;
display: flex;
height: 100%;
position: relative;

z-index: 2;
z-index: 2;
}

.card {
display: flex;
flex-direction: column;
margin: auto;
width: 100%;
position: relative;
transform: translate(0, -25%);

display: flex;
flex-direction: column;
margin: auto;
width: 100%;
position: relative;
transform: translate(0, -25%);
}

.song-desc{
.song-desc {
margin: 2vh 0 3vh 0;
}

.song-title {
font-family: Chango;
padding-bottom: 2vh;
padding-top: 1vh;
font-size: 1.8vw;
font-weight: 100;
@include font-display('sm');
padding-bottom: 1.5rem;

&--small {
@include font-display('xs');
}
}

.song-queue {
background-color: var(--color-surface);
display: flex;
min-height: 49.5vh;

flex-direction: column;
padding-top: 4vh;
padding-bottom: 4vh;
padding-left: 0.5vw;
padding-right: 0.5vw;
border-radius: 10px;
margin-top: -10.5vh;

position: relative;
z-index: 3;
overflow: overlay;

background-color: var(--color-surface);
display: flex;
min-height: 49.5vh;

flex-direction: column;
padding-top: 4vh;
padding-bottom: 4vh;
padding-left: 0.5vw;
padding-right: 0.5vw;
border-radius: 10px;
margin-top: -10.5vh;

position: relative;
z-index: 3;
overflow: overlay;
}

.curr-song{
.curr-song {
@include absCenter;
border-radius: 50%;
border-color: #CA6B4F;
border-color: #ca6b4f;
border-width: 3px;
border-style: solid;
width: 28vh;

}

}

::-webkit-scrollbar {
width: 1vh;
background : var(--color-surface);
border-radius: 10px;
}

width: 1vh;
background: var(--color-surface);
border-radius: 10px;
}

::-webkit-scrollbar-track {
border-radius: 1vh;
}

::-webkit-scrollbar-track {
border-radius: 1vh;
}

::-webkit-scrollbar-thumb {
background: #818181;
border-radius: 1vh;
width : 1vh;
}

::-webkit-scrollbar-thumb {
background: #818181;
border-radius: 1vh;
width: 1vh;
}

::-webkit-scrollbar-thumb:hover {
background: #8F8F8F;
}
::-webkit-scrollbar-thumb:hover {
background: #8f8f8f;
}
16 changes: 10 additions & 6 deletions src/apps/admin/pages/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useContext, useEffect, useState } from 'react'
import { useContext, useEffect, useRef, useState } from 'react'

import { AudioPlayer } from 'src/components'

import './Overview.scss'

import Disk from 'src/assets/svg/Disk.svg?react'
import { SpotifyPlayerContext } from 'src/context'
import { mockTrack } from 'src/mock'
import Disk from 'src/assets/svg/Disk.svg?react'

import { Track } from './Track'

Expand All @@ -15,11 +15,9 @@ export const Overview = () => {
const [author, setAuthor] = useState('')
const { currentTrack } = useContext(SpotifyPlayerContext)
const [currentTrackImage, setCurrentTrackImage] = useState('')
const songTitleRef = useRef<HTMLHeadingElement>(null)

useEffect(() => {
console.log('Hello')
console.log('Current track:', currentTrack)
console.log()
if (currentTrack == undefined) {
setSong('No song Playing')
setAuthor('No Author')
Expand All @@ -32,6 +30,10 @@ export const Overview = () => {
.join(', '),
)
setCurrentTrackImage(currentTrack?.album?.images[0].url)

if (currentTrack.name.length > 15) {
songTitleRef.current?.classList.add('song-title--small')
}
}
}, [currentTrack])

Expand All @@ -41,7 +43,9 @@ export const Overview = () => {
<div className="grid">
<div className="col-5 card">
<div className="song-desc">
<div className="song-title">{song}</div>
<h2 className="song-title" ref={songTitleRef}>
{song}
</h2>
<div className="song-author">{author}</div>
</div>
<AudioPlayer />
Expand Down
46 changes: 46 additions & 0 deletions src/apps/admin/pages/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useSelector } from 'react-redux'
import { selectAllClubs, selectUser } from 'src/store'
import { selectAllJukeboxes } from 'src/store/jukebox'

export const Settings = () => {
const clubs = useSelector(selectAllClubs)
const user = useSelector(selectUser)
const jukeboxes = useSelector(selectAllJukeboxes)

return (
<div>
<section>
<h2>Current User</h2>
<ul>
<li>
Name: {user?.first_name} {user?.last_name}
</li>
<li>Email: {user?.email}</li>
<li>Username: {user?.username}</li>
</ul>
</section>
<br />
<section>
<h2>Clubs</h2>
<ul>
{clubs.map((club) => (
<li key={club.id}>{club.name}</li>
))}
</ul>
</section>
<section>
<h2>Jukeboxes</h2>
<ul>
{jukeboxes.map((jbx) => (
<li key={jbx.id}>
{jbx.name} (
{clubs.find((club) => +club.id === +jbx.club_id)?.name ??
'No Club Found'}
)
</li>
))}
</ul>
</section>
</div>
)
}
2 changes: 1 addition & 1 deletion src/apps/admin/pages/Track.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatDuration } from 'src/utils'

export const Track = (props: { track: Nullable<Track> }) => {
export const Track = (props: { track: Nullable<ITrack> }) => {
const { track } = props
return (
<li className="track-list__track">
Expand Down
7 changes: 4 additions & 3 deletions src/apps/admin/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Outlet, type RouteObject } from 'react-router-dom'
import { type RouteObject } from 'react-router-dom'
import { Dashboard } from './layout/Dashboard'
import { Overview } from './pages'
import { AdminBoard } from './pages/AdminBoard'
import { MusicSearch } from './pages/MusicSearch'
import { Music } from './pages/Music'
import { MusicQueue } from './pages/MusicQueue'
import { MusicSearch } from './pages/MusicSearch'
import { Settings } from './pages/Settings'

export const adminOutlet = <Dashboard />

Expand Down Expand Up @@ -61,6 +62,6 @@ export const adminRoutes: RouteObject[] = [
},
{
path: 'settings',
element: <div>Settings</div>,
element: <Settings />,
},
]
2 changes: 1 addition & 1 deletion src/apps/boards/components/TrackItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { formatDuration } from 'src/utils'
/**
* TODO: MOVE THIS COMPONENT TO GLOBAL SCOPE
*/
export const TrackItem = (props: { track: Nullable<Track> }) => {
export const TrackItem = (props: { track: Nullable<ITrack> }) => {
const { track } = props
return (
<li className="track-list__track">
Expand Down
4 changes: 2 additions & 2 deletions src/apps/boards/components/TracksPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AudioPlayer } from 'src/components'
import { TrackItem } from './TrackItem'

export const TracksPanel = (props: {
currentTrack?: Nullable<Track>
nextTracks: Track[]
currentTrack?: Nullable<ITrack>
nextTracks: ITrack[]
}) => {
const { currentTrack, nextTracks } = props

Expand Down
2 changes: 1 addition & 1 deletion src/components/audio/AudioPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ProgressBar } from './ProgressBar'
import './ProgressBar.scss'

export const AudioPlayerContext = createContext({
currentTrack: undefined as Nullable<Track>,
currentTrack: undefined as Nullable<ITrack>,
isPlaying: false,
timeProgress: 0,
duration: 0,
Expand Down
6 changes: 3 additions & 3 deletions src/mock/mock-clubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ export const mockClubs: IClub[] = [
{
id: 0,
name: 'Test Club 1',
ownerId: 0,
members: [],
},
{
id: 1,
name: 'Test Club 2',
ownerId: 1,
members: [],
},
{
id: 2,
name: 'Test Club 3',
ownerId: 1,
members: [],
},
]
2 changes: 1 addition & 1 deletion src/mock/mock-track.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const mockTrack: Track = {
export const mockTrack: ITrack = {
album: {
// album_type: 'compilation',
// total_tracks: 9,
Expand Down
11 changes: 4 additions & 7 deletions src/mock/mock-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ export const mockUser: IUser & { token: string } = {
id: 0,
token: 'test-token',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
clubs: mockClubs.map((club) => ({
id: club.id,
name: club.name,
ownerId: 0,
})),
username: '[email protected]',
first_name: 'John',
last_name: 'Doe',
clubs: mockClubs,
image:
'https://static.vecteezy.com/system/resources/thumbnails/001/840/618/small_2x/picture-profile-icon-male-icon-human-or-people-sign-and-symbol-free-vector.jpg',
}
Loading

0 comments on commit f4460d6

Please sign in to comment.