mirror of
https://github.com/jellyfin/jellyfin-vue.git
synced 2025-03-04 19:57:34 +00:00
feat: handle item deletion on apistore
Signed-off-by: Fernando Fernández <ferferga@hotmail.com>
This commit is contained in:
parent
86886a620d
commit
dc6476d4a3
@ -57,6 +57,7 @@
|
|||||||
import { useConfirmDialog } from '@/composables/use-confirm-dialog';
|
import { useConfirmDialog } from '@/composables/use-confirm-dialog';
|
||||||
import { useSnackbar } from '@/composables/use-snackbar';
|
import { useSnackbar } from '@/composables/use-snackbar';
|
||||||
import { remote } from '@/plugins/remote';
|
import { remote } from '@/plugins/remote';
|
||||||
|
import { apiStore } from '@/store/api';
|
||||||
import { playbackManager } from '@/store/playbackManager';
|
import { playbackManager } from '@/store/playbackManager';
|
||||||
import { taskManager } from '@/store/taskManager';
|
import { taskManager } from '@/store/taskManager';
|
||||||
import {
|
import {
|
||||||
@ -70,7 +71,6 @@ import {
|
|||||||
getItemSeriesDownloadMap
|
getItemSeriesDownloadMap
|
||||||
} from '@/utils/items';
|
} from '@/utils/items';
|
||||||
import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
|
import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
|
||||||
import { getLibraryApi } from '@jellyfin/sdk/lib/utils/api/library-api';
|
|
||||||
import { useClipboard, useEventListener } from '@vueuse/core';
|
import { useClipboard, useEventListener } from '@vueuse/core';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import IMdiArrowExpandDown from 'virtual:icons/mdi/arrow-expand-down';
|
import IMdiArrowExpandDown from 'virtual:icons/mdi/arrow-expand-down';
|
||||||
@ -289,9 +289,7 @@ const deleteItemAction = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await remote.sdk.newUserApi(getLibraryApi).deleteItem({
|
await apiStore.itemDelete(itemId.value);
|
||||||
itemId: itemId.value
|
|
||||||
});
|
|
||||||
|
|
||||||
if (itemId.value === menuProps.item.Id && route.fullPath.includes(itemId.value)) {
|
if (itemId.value === menuProps.item.Id && route.fullPath.includes(itemId.value)) {
|
||||||
await router.replace('/');
|
await router.replace('/');
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import { remote } from '@/plugins/remote';
|
import { remote } from '@/plugins/remote';
|
||||||
import { ImageType, ItemFields, type BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
|
import { ImageType, ItemFields, type BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
|
||||||
import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
|
import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
|
||||||
|
import { getLibraryApi } from '@jellyfin/sdk/lib/utils/api/library-api';
|
||||||
import { reactive, watch } from 'vue';
|
import { reactive, watch } from 'vue';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +38,7 @@ class ApiStore {
|
|||||||
*/
|
*/
|
||||||
private _defaultState: ApiState = {
|
private _defaultState: ApiState = {
|
||||||
items: new Map<BaseItemDto['Id'], BaseItemDto>(),
|
items: new Map<BaseItemDto['Id'], BaseItemDto>(),
|
||||||
requests: new Map<string, Map<string, string[] | RawBaseItemResponse>>()
|
requests: new Map<string, Map<string, unknown | RawBaseItemResponse>>()
|
||||||
};
|
};
|
||||||
private _state = reactive<ApiState>(structuredClone(this._defaultState));
|
private _state = reactive<ApiState>(structuredClone(this._defaultState));
|
||||||
|
|
||||||
@ -101,13 +102,31 @@ class ApiStore {
|
|||||||
return this.getRequest(funcName, params) as T;
|
return this.getRequest(funcName, params) as T;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public itemDelete = async (itemId: string): Promise<void> => {
|
||||||
|
try {
|
||||||
|
await remote.sdk.newUserApi(getLibraryApi).deleteItem({
|
||||||
|
itemId
|
||||||
|
});
|
||||||
|
|
||||||
|
this._state.items.delete(itemId);
|
||||||
|
|
||||||
|
for (const request of this._state.requests.values()) {
|
||||||
|
for (const [args, result] of request.entries()) {
|
||||||
|
if (result instanceof RawBaseItemResponse && result.ids.includes(itemId) || args.includes(itemId)) {
|
||||||
|
request.delete(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the items in the store. Just a request is enough, as the Axios
|
* Updates the items in the store. Just a request is enough, as the Axios
|
||||||
* interceptors already handle updating the item in the store
|
* interceptors already handle updating the item in the store
|
||||||
*
|
*
|
||||||
* @param itemIds - Ids of the items to update
|
* @param itemIds - Ids of the items to update
|
||||||
*/
|
*/
|
||||||
public updateStoreItems = async (itemIds: BaseItemDto['Id'][]): Promise<void> => {
|
private _update = async (itemIds: BaseItemDto['Id'][]): Promise<void> => {
|
||||||
if (itemIds.length > 0) {
|
if (itemIds.length > 0) {
|
||||||
const { data } = await remote.sdk.newUserApi(getItemsApi).getItems({
|
const { data } = await remote.sdk.newUserApi(getItemsApi).getItems({
|
||||||
userId: remote.auth.currentUserId,
|
userId: remote.auth.currentUserId,
|
||||||
@ -151,7 +170,7 @@ class ApiStore {
|
|||||||
(item: unknown): item is string => typeof item === 'string'
|
(item: unknown): item is string => typeof item === 'string'
|
||||||
).filter((itemId) => this._state.items.has(itemId));
|
).filter((itemId) => this._state.items.has(itemId));
|
||||||
|
|
||||||
await this.updateStoreItems(itemsToUpdate);
|
await this._update(itemsToUpdate);
|
||||||
} else if (
|
} else if (
|
||||||
MessageType === 'UserDataChanged' &&
|
MessageType === 'UserDataChanged' &&
|
||||||
'UserDataList' in Data &&
|
'UserDataList' in Data &&
|
||||||
@ -175,7 +194,7 @@ class ApiStore {
|
|||||||
return updatedData.ItemId;
|
return updatedData.ItemId;
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.updateStoreItems(itemsToUpdate);
|
await this._update(itemsToUpdate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user