Skip to content

Commit 7a726a4

Browse files
authored
Merge pull request #68 from stanleyowen/next
Version 0.2.1
2 parents 0d9e68e + 34a9377 commit 7a726a4

File tree

9 files changed

+140
-231
lines changed

9 files changed

+140
-231
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ debug.log
1616
.env.production.local
1717

1818
**/img/*[.png][.jpg]
19+
dist
1920
docs
2021
node_modules
2122
dist

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lofi-player",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"private": true,
55
"author": "Stanley Owen <stanleyowen06@gmail.com>",
66
"dependencies": {
@@ -9,14 +9,13 @@
99
"@testing-library/jest-dom": "^5.14.1",
1010
"@testing-library/react": "^12.0.0",
1111
"@testing-library/user-event": "^13.2.1",
12-
"@types/node": "^16.7.4",
12+
"@types/node": "^16.7.10",
1313
"@types/react": "^17.0.19",
1414
"@types/react-dom": "^17.0.9",
1515
"@types/react-router-dom": "^5.1.8",
16-
"algoliasearch": "^4.10.5",
1716
"cross-env": "^7.0.3",
1817
"electron-is-dev": "^2.0.0",
19-
"firebase": "^9.0.0",
18+
"firebase": "^9.0.1",
2019
"react": "^17.0.2",
2120
"react-dom": "^17.0.2",
2221
"react-router-dom": "^5.2.1",

src/App.css

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ h1, h2, h3, h4, h5, h6, p { margin: 0; padding: 0; }
123123
.navbar div.mrl-10:last-child { margin-left: auto }
124124

125125
/* Base Layout */
126-
.app { margin-left: 225px }
126+
.app {
127+
display: flex;
128+
height: 100vh;
129+
flex-direction: column;
130+
margin-left: 225px;
131+
}
127132
.base { margin-top: 100px }
128133
.app-ui {
129-
height: 84vh;
134+
flex: 9;
130135
overflow: auto;
131136
}
132137
.card {
@@ -208,7 +213,7 @@ input:disabled { pointer-events: none !important }
208213
.w-40 { width: 40% !important }
209214
.w-50 { width: 50% !important }
210215
.w-70 { width: 70% !important }
211-
.w-80 { width: 80% !important; }
216+
.w-80 { width: 80% !important }
212217
.w-100 { width: 100%; }
213218
.p-10 { padding: 10px !important }
214219
.p-15 { padding: 15px !important }
@@ -218,8 +223,8 @@ input:disabled { pointer-events: none !important }
218223
.ml-10 { margin-left: 10px !important }
219224
.m-auto { margin: auto !important }
220225
svg {
221-
display: block;
222226
margin: auto;
227+
display: block;
223228
}
224229
#version svg { margin: auto 0px; }
225230
#version p { font-weight: normal; }
@@ -301,16 +306,24 @@ button {
301306
}
302307

303308
/* Search */
304-
.search { width: 50%; }
309+
.search { width: 50% }
305310

306311
@media only screen and (max-width: 1200px) {
307312
.col-3 { grid-template-columns: 50% 50% }
308313
.col-4 { grid-template-columns: 33.3% 33.3% 33.3% }
309-
.search { width: 60%; }
314+
.search { width: 60% }
310315
}
311-
@media only screen and (max-width: 700px) {
316+
@media only screen and (max-width: 800px) {
312317
.col-3 { grid-template-columns: 100% }
318+
.col-4 { grid-template-columns: 50% 50% }
319+
#version .w-50 { width: 90% !important }
320+
}
321+
@media only screen and (max-width: 700px) {
322+
.search { width: 100% }
323+
.navbar div.mrl-10:last-child {
324+
display: none;
325+
visibility: hidden;
326+
}
313327
.col-4 { grid-template-columns: 100% }
314-
#version .w-50 { width: 100% !important; }
315-
.search { width: 100%; }
328+
#version .w-50 { width: 100% !important }
316329
}

src/components/base.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const BaseLayout = ({ song, config, properties, handleSong }: any) => {
99
{ properties.activeTab === 'home' ?
1010
<Home properties={properties} handleSong={handleSong} config={config} song={song} /> :
1111
properties.activeTab === 'search' ?
12-
<Search properties={properties} handleSong={handleSong} /> :
12+
<Search properties={properties} handleSong={handleSong} config={config} /> :
1313
<About /> }
1414
</div>
1515
)

src/components/home.component.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ const Home = ({ song, config, handleSong }: any) => {
2424

2525
useEffect(() => {
2626
initializeApp(config)
27-
onValue(ref(getDatabase(), 'data/'), (snapshot) => setData(snapshot.val()))
27+
onValue(ref(getDatabase(), 'data-dev/'), (snapshot) => {
28+
var rawData = snapshot.val(), index = rawData.length, randIndex
29+
while(index !== 0) {
30+
randIndex = Math.floor(Math.random() * index)
31+
index--
32+
[rawData[index], rawData[randIndex]] = [rawData[randIndex], rawData[index]]
33+
}
34+
setData(rawData)
35+
})
2836
setTimeout(() =>
2937
onValue(ref(getDatabase(), '.info/connected'), (snapshot) => snapshot.val() ? null : console.log("Client Disconnected from Server"))
3038
, 5000)
@@ -41,13 +49,14 @@ const Home = ({ song, config, handleSong }: any) => {
4149
<h2 className="m-10">Good {greeting}</h2>
4250
<div className="col-3" id="recent-playlist">
4351
{
44-
data?.music ? data.music.map((album: any, index: number) => {
52+
data ? data.map((song: any, index: number) => {
53+
if(index > 5) return;
4554
return (
4655
<div className="m-10" key={index}>
47-
<a className="card flex" href={album.link}>
48-
<img src={album.image} alt={album.title} />
49-
<p className="m-auto w-50">{album.title}</p>
50-
<button className="play-btn m-auto" onClick={e => triggerAudio(e, album)} id={(album.title+album.author).replace(/\s/g, "-")}></button>
56+
<a className="card flex" href={song.link}>
57+
<img src={song.image} alt={song.title} />
58+
<p className="m-auto w-50">{song.title}</p>
59+
<button className="play-btn m-auto" onClick={e => triggerAudio(e, song)} id={(song.title+song.author).replace(/\s/g, "-")}></button>
5160
</a>
5261
</div>
5362
)
@@ -56,17 +65,18 @@ const Home = ({ song, config, handleSong }: any) => {
5665
</div>
5766
<div className="mt-30 col-4" id="playlist">
5867
{
59-
data?.album ? data.album.map((album: any, index: number) => {
68+
data ? data.map((song: any, index: number) => {
69+
if(index < 6 || index >= 14) return;
6070
return (
6171
<div className="m-10" key={index}>
62-
<a className="large-card" href={album.link}>
63-
<img src={album.image} alt={album.title} />
72+
<a className="large-card" href={song.link}>
73+
<img src={song.image} alt={song.title} />
6474
<div className="flex">
6575
<div className="m-auto w-70">
66-
<h3 className="mt-10">{album.title}</h3>
67-
<p className="author">{album.author}</p>
76+
<h3 className="mt-10">{song.title}</h3>
77+
<p className="author">{song.author}</p>
6878
</div>
69-
<button className="play-btn m-auto" onClick={e => triggerAudio(e, album)} id={(album.title+album.author).replace(/\s/g, "-")}></button>
79+
<button className="play-btn m-auto" onClick={e => triggerAudio(e, song)} id={(song.title+song.author).replace(/\s/g, "-")}></button>
7080
</div>
7181
</a>
7282
</div>

src/components/navbar.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const Navbar = ({ properties, handleChange }: any) => {
2222
<div className="navbar">
2323
<div className="mrl-10">
2424
<Tooltip title="Go Back"><span>
25-
<IconButton onClick={goBackward} disabled={property.disablePrevious}><ChevronLeft /></IconButton>
25+
<IconButton onClick={goBackward} disabled={property.disablePrevious}><ChevronLeft /></IconButton>
2626
</span></Tooltip>
2727
</div>
2828
<div className="mrl-10">
2929
<Tooltip title="Go Forward"><span>
30-
<IconButton onClick={goForward} disabled={property.disableForward}><ChevronRight /></IconButton>
30+
<IconButton onClick={goForward} disabled={property.disableForward}><ChevronRight /></IconButton>
3131
</span></Tooltip>
3232
</div>
3333
<div className="mrl-10">

src/components/search.component.tsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
import React, { useState, useEffect } from 'react'
2-
import algoliasearch from 'algoliasearch'
32
import { Skeleton } from '@material-ui/lab'
3+
import { initializeApp } from 'firebase/app'
44
import { Close } from '../lib/icons.component'
55
import { TextField, IconButton } from '@material-ui/core'
6+
import { getDatabase, ref, onValue } from 'firebase/database'
67

7-
const Search = ({ properties }: any) => {
8+
const Search = ({ properties, config }: any) => {
89
const items: any = []
10+
const [results, setResult] = useState<any>()
11+
const [rawData, setRawData] = useState<any>()
912
const [keyword, setKeyword] = useState<string>('')
10-
const [data, setData] = useState<any>({
11-
isFetching: false,
12-
keyword: '',
13-
result: ''
14-
})
13+
const [isFetching, setFetching] = useState<boolean>(false)
1514

1615
useEffect(() => {
17-
setData({ ...data, isFetching: true})
18-
if(keyword)
19-
algoliasearch(String(process.env.REACT_APP_ALGOLIA_ID), String(process.env.REACT_APP_ALGOLIA_API_KEY)).initIndex('music').search(keyword)
20-
.then(({ hits }) => setData({ ...data, isFetching: false, result: hits }))
21-
// eslint-disable-next-line
16+
onValue(ref(getDatabase(), 'data-dev/'), (snapshot) => setRawData(snapshot.val()))
17+
}, [config])
18+
19+
useEffect(() => {
20+
setFetching(true)
21+
if(keyword) {
22+
var result: any = []
23+
for (let i=0; i<rawData.length; i++) {
24+
if(String(rawData[i].title).toLowerCase().includes(keyword)) {
25+
result.push(rawData[i])
26+
}
27+
}
28+
setResult(result)
29+
}
30+
setFetching(false)
31+
// eslint-disable-next-line
2232
}, [keyword])
2333

2434
if(keyword)
25-
if(data.result?.length === 0 && data.isFetching)
35+
if(results?.length === 0 && isFetching)
2636
for(let i=0; i<4; i++) {
2737
items.push(
2838
<div className="m-10" key={i}>
@@ -36,8 +46,8 @@ const Search = ({ properties }: any) => {
3646
</div>
3747
)
3848
}
39-
else if (data.result?.length > 0)
40-
data.result?.map((music: any, index: any) => {
49+
else if (results?.length > 0)
50+
results.map((music: any, index: any) => {
4151
return items.push(
4252
<div className="m-10" key={index}>
4353
<a className="large-card" href={music.link}>
@@ -53,7 +63,7 @@ const Search = ({ properties }: any) => {
5363
</div>
5464
)
5565
})
56-
else if(!data.isFetching && data.result?.length === 0) items.push(<div>No Results Found for <b>{keyword}</b></div>)
66+
else if(!isFetching && results?.length === 0) items.push(<div>No Results Found for <b>{keyword}</b></div>)
5767

5868
const ClearQuery = (e: React.MouseEvent<HTMLButtonElement>) => {
5969
e.preventDefault()

src/components/sidebar.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const SideBar = ({ handleChange, properties }: any) => {
2828
const SolidIcon = components[`${tab}Solid`]
2929
const OutlineIcon = components[`${tab}Outline`]
3030
return (
31-
<Tooltip title={tab} enterDelay={500}>
32-
<Button className="w-100 rounded-corner p-10 tab" id={tab.toLowerCase()} key={index}>
31+
<Tooltip title={tab} enterDelay={500} enterNextDelay={500} key={index}>
32+
<Button className="w-100 rounded-corner p-10 tab" id={tab.toLowerCase()}>
3333
<div className="w-30">{properties.activeTab === tab.toLowerCase() ? <SolidIcon /> : <OutlineIcon />}</div>
3434
<div className="w-70 left-align">{tab.toLowerCase()}</div>
3535
</Button>

0 commit comments

Comments
 (0)