Skip to content

Commit 617cb32

Browse files
committed
feat(playlist) Fixed some linting issues.
1 parent 71b98ce commit 617cb32

File tree

3 files changed

+69
-43
lines changed

3 files changed

+69
-43
lines changed

frontend/components/Item/PlaylistItems.vue

+37-35
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<v-list v-if="!!children" color="transparent" two-line>
99
<v-list-item-group class="list-group">
1010
<draggable
11-
class="list-draggable"
12-
v-bind="dragOptions"
1311
v-if="children.length > 0"
12+
v-bind="dragOptions"
1413
v-model="children"
1514
:move="checkMove"
15+
class="list-draggable"
1616
>
1717
<v-hover
1818
v-for="(item, index) in children"
@@ -80,44 +80,16 @@
8080
import { BaseItemDto } from '@jellyfin/client-axios';
8181
import Vue from 'vue';
8282
import { mapStores } from 'pinia';
83+
import { MoveEvent } from 'vuedraggable';
8384
import { itemsStore, playbackManagerStore } from '~/store';
8485
8586
export default Vue.extend({
8687
props: {
87-
item: {
88+
playlist: {
8889
type: Object as () => BaseItemDto,
8990
required: true
9091
}
9192
},
92-
methods: {
93-
checkMove(evt: any) {
94-
console.log(evt.draggedContext);
95-
this.newIndex = evt.draggedContext.futureIndex;
96-
this.oldIndex = evt.draggedContext.index;
97-
},
98-
getArtists(item: BaseItemDto): string | null {
99-
if (item.Artists) {
100-
return item.Artists.join(', ');
101-
} else {
102-
return null;
103-
}
104-
},
105-
isPlaying(item: BaseItemDto): boolean {
106-
if (this.playbackManager.getCurrentItem == undefined) {
107-
return false;
108-
}
109-
return item.Id == (this.playbackManager.getCurrentItem as BaseItemDto).Id;
110-
},
111-
playQueueFrom(playFromIndex: number): void {
112-
this.playbackManager
113-
.play({
114-
item: this.item,
115-
startFromIndex: playFromIndex,
116-
initiator: this.item
117-
})
118-
.then(() => this.items.fetchAndAddPlaylist(this.item.Id as string));
119-
}
120-
},
12193
data() {
12294
return {
12395
currentTab: 0,
@@ -138,13 +110,13 @@ export default Vue.extend({
138110
children: {
139111
get(): BaseItemDto[] {
140112
return this.items.getChildrenOfParentPlaylist(
141-
this.item.Id
113+
this.playlist.Id
142114
) as BaseItemDto[];
143115
},
144-
set(newValue: BaseItemDto[]): void {
116+
set(_: BaseItemDto[]): void {
145117
if (this.oldIndex != null && this.newIndex != null) {
146118
this.items.movePlaylistItem(
147-
this.item,
119+
this.playlist,
148120
this.children[this.oldIndex],
149121
this.newIndex
150122
);
@@ -163,6 +135,36 @@ export default Vue.extend({
163135
}
164136
}
165137
}
138+
},
139+
methods: {
140+
checkMove(evt: MoveEvent<BaseItemDto>) {
141+
this.newIndex = evt.draggedContext.futureIndex;
142+
this.oldIndex = evt.draggedContext.index;
143+
},
144+
getArtists(item: BaseItemDto): string | null {
145+
if (item.Artists) {
146+
return item.Artists.join(', ');
147+
} else {
148+
return null;
149+
}
150+
},
151+
isPlaying(item: BaseItemDto): boolean {
152+
if (this.playbackManager.getCurrentItem === undefined) {
153+
return false;
154+
}
155+
156+
return (
157+
item.Id === (this.playbackManager.getCurrentItem as BaseItemDto).Id
158+
);
159+
},
160+
async playQueueFrom(playFromIndex: number): Promise<void> {
161+
await this.playbackManager.play({
162+
item: this.playlist,
163+
startFromIndex: playFromIndex,
164+
initiator: this.playlist
165+
});
166+
await this.items.fetchAndAddPlaylist(this.playlist.Id as string);
167+
}
166168
}
167169
});
168170
</script>

frontend/pages/item/_itemId/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
<collection-tabs :item="item" />
246246
</v-col>
247247
<v-col v-if="item.Type === 'Playlist'" cols="12">
248-
<playlist-items :item="item" />
248+
<playlist-items :playlist="item" />
249249
</v-col>
250250
<v-col cols="12">
251251
<related-items :id="$route.params.itemId" :item="item" />

frontend/store/items.ts

+31-7
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ export const itemsStore = defineStore('items', {
6565
}
6666
},
6767
/**
68-
* Associate an item that has children with its children
68+
* Moves a playlist item to another index.
6969
*
70-
* @param parent
71-
* @param children
72-
* @returns - The children of the item
70+
* @param parent The playlist containing the item to be moved.
71+
* @param localChild The item in the playlist to be moved.
72+
* @param index The new index of the item after being moved
73+
* @returns A promise representing the resulting playlist after the item is moved.
7374
*/
7475
async movePlaylistItem(
7576
parent: BaseItemDto,
@@ -101,16 +102,26 @@ export const itemsStore = defineStore('items', {
101102
ImageType.Thumb
102103
]
103104
});
105+
104106
const child = children.data.Items?.find(
105-
(i) => i.Id == localChild.Id
107+
(i) => i.Id === localChild.Id
106108
) as BaseItemDto;
109+
107110
await this.$nuxt.$api.playlists.moveItem({
108111
playlistId: parent.Id as string,
109112
itemId: child.PlaylistItemId as string,
110113
newIndex: index
111114
});
115+
112116
return await this.fetchAndAddPlaylist(parent.Id as string);
113117
},
118+
/**
119+
* Adds a playlist and it's items to the local store.
120+
*
121+
* @param parent The playlist containing the children items.
122+
* @param children The items in the playlist
123+
* @returns The items in the playlist
124+
*/
114125
addPlaylist(parent: BaseItemDto, children: BaseItemDto[]): BaseItemDto[] {
115126
if (!parent.Id) {
116127
throw new Error("Parent item doesn't have an Id");
@@ -132,6 +143,12 @@ export const itemsStore = defineStore('items', {
132143

133144
return this.getChildrenOfParentPlaylist(parent.Id) as BaseItemDto[];
134145
},
146+
/**
147+
* Fetches the items in a playlist and stores them locally.
148+
*
149+
* @param parentId The Item ID of the playlist
150+
* @returns The items in the playlist.
151+
*/
135152
async fetchAndAddPlaylist(
136153
parentId: string | undefined
137154
): Promise<BaseItemDto[]> {
@@ -167,15 +184,22 @@ export const itemsStore = defineStore('items', {
167184
})
168185
).data;
169186

170-
if (childItems.Items) {
171-
const parent = this.getItemById(parentId);
187+
const parent = this.getItemById(parentId);
172188

189+
if (childItems.Items) {
173190
return this.addPlaylist(parent as BaseItemDto, childItems.Items);
174191
} else {
175192
// I think this just means it's an empty playlist...?
176193
return this.addPlaylist(parent as BaseItemDto, []);
177194
}
178195
},
196+
/**
197+
* Associate an item that has children with its children
198+
*
199+
* @param parent
200+
* @param children
201+
* @returns - The children of the item
202+
*/
179203
addCollection(parent: BaseItemDto, children: BaseItemDto[]): BaseItemDto[] {
180204
if (!parent.Id) {
181205
throw new Error("Parent item doesn't have an Id");

0 commit comments

Comments
 (0)