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

Add Play All and Shuffle Button #6153

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
32 changes: 32 additions & 0 deletions src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ export default defineComponent({
}
},
computed: {
watchRandomVideo() {
if (!this.firstVideoIdExists) {
return ''
}

const randomVideo = this.videos[Math.floor(Math.random() * this.videos.length)]
return {
path: `/watch/${randomVideo.videoId}`,
query: this.watchPageLinkQuery(randomVideo.playlistItemId, true),
}
},
watchFirstVideo() {
if (!this.firstVideoIdExists) {
return ''
}

const firstVideo = this.videos[0]
return {
path: `/watch/${firstVideo.videoId}`,
query: this.watchPageLinkQuery(firstVideo.playlistItemId),
}
},

hideSharingActions: function () {
return this.$store.getters.getHideSharingActions
},
Expand Down Expand Up @@ -352,6 +375,15 @@ export default defineComponent({
document.removeEventListener('keydown', this.keyboardShortcutHandler)
},
methods: {
watchPageLinkQuery(playlistItemId, shuffle = false) {
return {
playlistId: this.id,
playlistType: this.videoPlaylistType,
playlistItemId: playlistItemId,
playlistEnableShuffle: shuffle,
}
},

handlePlaylistNameInput(input) {
if (input.trim() === '') {
// Need to show message for blank input
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/playlist-info/playlist-info.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
grid-auto-flow: column;
column-gap: 8px;
justify-content: flex-end;
margin-block: 5px;
}

.searchInputsRow {
Expand Down Expand Up @@ -111,7 +112,7 @@
margin-block-start: 8px;
}

.playlistOptionsAndSearch {
.playlistOptionsWrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
Expand Down
60 changes: 43 additions & 17 deletions src/renderer/components/playlist-info/playlist-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</h3>
</div>

<div class="playlistOptionsAndSearch">
<div class="playlistOptionsWrapper">
<div class="playlistOptions">
<ft-icon-button
v-if="editMode"
Expand Down Expand Up @@ -207,22 +207,6 @@
share-target-type="Playlist"
/>
</div>
<div
v-if="searchVideoModeAllowed"
class="searchInputsRow"
>
<ft-input
ref="searchInput"
class="inputElement"
:placeholder="$t('User Playlists.SinglePlaylistView.Search for Videos')"
:show-clear-text-button="true"
:show-action-button="false"
:value="query"
:maxlength="255"
@input="(input) => updateQueryDebounce(input)"
@clear="updateQueryDebounce('')"
/>
</div>
</div>
<ft-prompt
v-if="showDeletePlaylistPrompt"
Expand All @@ -249,6 +233,48 @@
@click="handleRemoveDuplicateVideosPromptAnswer"
/>
</div>

<div class="playlistOptionsWrapper">
<div
v-if="firstVideoIdExists"
class="playlistOptions"
>
<router-link
:to="watchFirstVideo"
>
<ft-button
class="playlistPlayButton"
:label="$t('Playlist.Play all')"
:icon="['fas', 'play']"
/>
</router-link>
<router-link
:to="watchRandomVideo"
>
<ft-button
class="playlistPlayButton"
:label="$t('Playlist.Shuffle')"
:icon="['fas', 'random']"
/>
</router-link>
</div>
<div
v-if="searchVideoModeAllowed"
class="searchInputsRow"
>
<ft-input
ref="searchInput"
class="inputElement"
:placeholder="$t('User Playlists.SinglePlaylistView.Search for Videos')"
:show-clear-text-button="true"
:show-action-button="false"
:value="query"
:maxlength="255"
@input="(input) => updateQueryDebounce(input)"
@clear="updateQueryDebounce('')"
/>
</div>
</div>
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ export default defineComponent({
type: Boolean,
required: true,
},
playlistEnableShuffle: {
type: Boolean,
default: false,
}
},
emits: ['pause-player'],
data: function () {
return {
isLoading: true,
shuffleEnabled: false,
shuffleEnabled: this.playlistEnableShuffle,
loopEnabled: false,
reversePlaylist: false,
pauseOnCurrentVideo: false,
Expand Down Expand Up @@ -213,6 +217,10 @@ export default defineComponent({
this.getPlaylistInfoWithDelay()
}

if (this.shuffleEnabled) {
this.shufflePlaylistItems()
}

if ('mediaSession' in navigator) {
navigator.mediaSession.setActionHandler('previoustrack', this.playPreviousVideo)
navigator.mediaSession.setActionHandler('nexttrack', this.playNextVideo)
Expand Down Expand Up @@ -529,7 +537,6 @@ export default defineComponent({
items.push(remainingItems[randomInt])
remainingItems.splice(randomInt, 1)
}

this.randomizedPlaylistItems = items
},

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Playlist/Playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:last-updated="lastUpdated"
:description="playlistDescription"
:video-count="videoCount"
:videos="playlistItems"
:videos="sortedPlaylistItems"
:view-count="viewCount"
:info-source="infoSource"
:more-video-data-available="moreVideoDataAvailable"
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default defineComponent({
playlistId: '',
playlistType: '',
playlistItemId: null,
playlistEnableShuffle: false,
/** @type {number|null} */
timestamp: null,
playNextTimeout: null,
Expand Down Expand Up @@ -1107,6 +1108,7 @@ export default defineComponent({

this.playlistId = this.$route.query.playlistId
this.playlistItemId = this.$route.query.playlistItemId
this.playlistEnableShuffle = this.$route.query.playlistEnableShuffle === 'true'

if (this.playlistId == null || this.playlistId.length === 0) {
this.playlistType = ''
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/Watch/Watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
:playlist-type="playlistType"
:video-id="videoId"
:playlist-item-id="playlistItemId"
:playlist-enable-shuffle="playlistEnableShuffle"
class="watchVideoSideBar watchVideoPlaylist"
:class="{ theatrePlaylist: useTheatreMode }"
@pause-player="pausePlayer"
Expand Down
2 changes: 2 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ Playlist:
Playlist: Playlist
View Full Playlist: View Full Playlist
Last Updated On: Last Updated On
Play all: Play all
Shuffle: Shuffle
Sort By:
Sort By: Sort By
DateAddedNewest: Latest added first
Expand Down