Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
spotify
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web
spotify
Commits
ba66f83f
Commit
ba66f83f
authored
2 years ago
by
Benoît Harrault
Browse files
Options
Downloads
Plain Diff
Merge branch '46-improve-now-playing-page' into 'master'
Resolve "Improve "now playing" page" Closes
#46
See merge request
!41
parents
d32de92f
60d318aa
No related branches found
No related tags found
1 merge request
!41
Resolve "Improve "now playing" page"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
public/css/styles.css
+19
-3
19 additions, 3 deletions
public/css/styles.css
public/js/now-playing.js
+36
-9
36 additions, 9 deletions
public/js/now-playing.js
template.php
+5
-1
5 additions, 1 deletion
template.php
with
60 additions
and
13 deletions
public/css/styles.css
+
19
−
3
View file @
ba66f83f
...
...
@@ -20,17 +20,33 @@
}
.now-playing
{
padding
:
0
;
margin
:
0
;
background-color
:
black
;
color
:
white
;
}
.now-playing-cover
{
padding
:
2em
;
padding
:
1em
;
}
.now-playing-loading
,
.now-playing-nothing
{
padding-top
:
2em
;
padding-bottom
:
2em
;
text-align
:
center
;
font-size
:
300%
;
}
.now-playing-data
{
padding
:
1em
0.5em
;
}
.now-playing-title
{
padding-top
:
4
em
;
font-size
:
4
00%
;
padding-top
:
1
em
;
font-size
:
3
00%
;
font-weight
:
bolder
;
line-height
:
1.2em
;
}
.now-playing-artists
{
padding-top
:
0.5em
;
padding-bottom
:
1em
;
font-size
:
200%
;
line-height
:
1.2em
;
}
This diff is collapsed.
Click to expand it.
public/js/now-playing.js
+
36
−
9
View file @
ba66f83f
var
lastFetchedNowPlayingData
=
""
;
function
updateNowPlaying
()
{
var
apiUrl
=
"
now-playing?api
"
;
...
...
@@ -6,9 +8,11 @@ function updateNowPlaying() {
return
response
.
json
();
})
.
then
(
function
(
data
)
{
var
nowPlayingBlock
=
document
.
getElementById
(
"
now-playing
"
);
newContent
=
buildNowPlayingBlock
(
data
);
nowPlayingBlock
.
innerHTML
=
newContent
;
if
(
hasChanged
(
data
))
{
var
nowPlayingBlock
=
document
.
getElementById
(
"
now-playing
"
);
newContent
=
buildNowPlayingBlock
(
data
);
nowPlayingBlock
.
innerHTML
=
newContent
;
}
})
.
catch
(
function
(
err
)
{
console
.
warn
(
"
Something went wrong.
"
,
err
);
...
...
@@ -19,16 +23,30 @@ function updateNowPlaying() {
});
}
function
hasChanged
(
data
)
{
if
(
data
&&
data
[
"
playing
"
]
&&
data
[
"
playing
"
][
"
item
"
])
{
var
dataAsString
=
JSON
.
stringify
(
data
[
"
playing
"
][
"
item
"
]);
if
(
dataAsString
!==
lastFetchedNowPlayingData
)
{
lastFetchedNowPlayingData
=
dataAsString
;
return
true
;
}
}
return
false
;
}
function
buildNowPlayingBlock
(
apiResponse
)
{
var
html
=
`
<div class="container-fluid now-playing">
<div class="row">
<div class="col">
<div class="col
-12 col-md-6
">
<div class="now-playing-cover"><img src="COVER_URL" class="img-fluid"></div>
</div>
<div class="col">
<div class="now-playing-title">TITLE</div>
<div class="now-playing-artists">ARTISTS</div>
<div class="col-12 col-md-6">
<div class="now-playing-data">
<div class="now-playing-title">TITLE</div>
<div class="now-playing-artists">ARTISTS</div>
</div>
</div>
</div>
</div>`
;
...
...
@@ -36,7 +54,15 @@ function buildNowPlayingBlock(apiResponse) {
var
nowPlayingData
=
apiResponse
[
"
playing
"
];
if
(
!
nowPlayingData
)
{
return
'
<div class="alert alert-info">No currently playing track...</div>
'
;
return
`
<div class="container-fluid now-playing">
<div class="row">
<div class="col">
<div class="now-playing-nothing">🔇</div>
</div>
</div>
</div>
`
;
}
var
item
=
nowPlayingData
[
"
item
"
];
...
...
@@ -49,9 +75,10 @@ function buildNowPlayingBlock(apiResponse) {
html
=
html
.
replace
(
"
TITLE
"
,
trackName
);
html
=
html
.
replace
(
"
ARTISTS
"
,
artistNames
);
html
=
html
.
replace
(
"
COVER_URL
"
,
coverUrl
);
html
=
html
.
replace
(
"
COVER_URL
"
,
coverUrl
);
return
html
;
}
updateNowPlaying
();
setInterval
(
updateNowPlaying
,
2000
);
This diff is collapsed.
Click to expand it.
template.php
+
5
−
1
View file @
ba66f83f
...
...
@@ -232,7 +232,11 @@
<?php
if
(
$templateData
[
'page'
]
===
'now-playing'
)
{
?>
<div
id=
"now-playing"
>
⏳
<div
class=
"container-fluid now-playing"
>
<div
class=
"col"
>
<div
class=
"now-playing-loading"
>
⏳
</div>
</div>
</div>
</div>
<script
src=
"js/now-playing.js"
></script>
<?php
}
?>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment