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

Update playlist page titles #5271

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export default defineComponent({
channelName = subtitle.substring(0, index).trim()
}

this.setPlaylistTitle(result.info.title)
this.playlistTitle = result.info.title
this.playlistDescription = result.info.description ?? ''
this.firstVideoId = result.items[0].id
this.playlistThumbnail = result.info.thumbnails[0].url
Expand Down Expand Up @@ -334,6 +334,8 @@ export default defineComponent({
// auto load next page again when no. of parsed items < page size
if (shouldGetNextPage) { this.getNextPageLocal() }

this.updatePageTitle()

this.isLoading = false
}).catch((err) => {
console.error(err)
Expand All @@ -348,7 +350,7 @@ export default defineComponent({

getPlaylistInvidious: function () {
invidiousGetPlaylistInfo(this.playlistId).then((result) => {
this.setPlaylistTitle(result.title)
this.playlistTitle = result.title
this.playlistDescription = result.description
this.firstVideoId = result.videos[0].videoId
this.viewCount = result.viewCount
Expand All @@ -371,6 +373,8 @@ export default defineComponent({

this.playlistItems = result.videos

this.updatePageTitle()

this.isLoading = false
}).catch((err) => {
console.error(err)
Expand All @@ -385,7 +389,7 @@ export default defineComponent({
},

parseUserPlaylist: function (playlist) {
this.setPlaylistTitle(playlist.playlistName)
this.playlistTitle = playlist.playlistName
this.playlistDescription = playlist.description ?? ''

if (playlist.videos.length > 0) {
Expand All @@ -406,6 +410,8 @@ export default defineComponent({

this.playlistItems = playlist.videos

this.updatePageTitle()

this.isLoading = false
},
showUserPlaylistNotFound() {
Expand Down Expand Up @@ -544,9 +550,14 @@ export default defineComponent({
}
},

setPlaylistTitle: function (value) {
this.playlistTitle = value
document.title = `${value} - ${packageDetails.productName}`
updatePageTitle() {
const playlistTitle = this.playlistTitle
const channelName = this.channelName
const titleText = [
playlistTitle,
channelName,
].filter(v => v).join(' | ')
Comment on lines +556 to +559
Copy link
Collaborator

Choose a reason for hiding this comment

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

What a clever snippet!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

JS version of ruby code like (not exact coz Array#compact only removes nil values)

[
  value_a if condition_a,
  value_b if condition_b,
].compact.join(' | ')

document.title = `${titleText} - ${packageDetails.productName}`
},

handleResize: function () {
Expand Down