itube-specs 0.0.330 → 0.0.335
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import { EAsyncData } from '../runtime';
|
|
2
|
-
|
|
3
1
|
export function useApiAction<T extends any[], R>(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
key?: string,
|
|
2
|
+
apiMethod: (...args: T) => Promise<R>,
|
|
3
|
+
isGet = false,
|
|
7
4
|
) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const loading = ref(false)
|
|
6
|
+
const error = ref<Error | null>(null)
|
|
7
|
+
const data = ref<R | null>(null)
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const execute = async (
|
|
10
|
+
args: T,
|
|
11
|
+
key?: string
|
|
12
|
+
) => {
|
|
13
|
+
loading.value = true
|
|
14
|
+
error.value = null
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
try {
|
|
17
|
+
const result = await apiMethod(...args)
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (key) {
|
|
22
|
-
const state = useState<R | null>(`data-${key}`);
|
|
23
|
-
state.value = result;
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
19
|
+
if (isGet) {
|
|
20
|
+
data.value = result
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
error.value = createError({
|
|
31
|
-
statusCode: 500,
|
|
32
|
-
statusMessage: 'Error in API action',
|
|
33
|
-
message: err instanceof Error ? err.message : 'Unknown error'
|
|
34
|
-
});
|
|
35
|
-
} finally {
|
|
36
|
-
loading.value = false;
|
|
22
|
+
if (key) {
|
|
23
|
+
useState<R | null>(`data-${key}`).value = result
|
|
37
24
|
}
|
|
38
|
-
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result
|
|
28
|
+
} catch (err: any) {
|
|
29
|
+
error.value = createError({
|
|
30
|
+
statusCode: 500,
|
|
31
|
+
statusMessage: 'Error in API action',
|
|
32
|
+
message: err instanceof Error ? err.message : 'Unknown error'
|
|
33
|
+
})
|
|
34
|
+
} finally {
|
|
35
|
+
loading.value = false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
return { loading, error, data, execute }
|
|
41
40
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
1
2
|
import { ref } from 'vue';
|
|
2
3
|
import type { IVideoData, IVideoCard } from '../types';
|
|
3
4
|
import { EAuthSteps } from '../runtime';
|
|
4
|
-
import { AuthorizationApiService } from '~/services/api/authorization.service';
|
|
5
5
|
|
|
6
6
|
const videoCard = ref<IVideoCard | IVideoData | null>(null);
|
|
7
7
|
const isPlaylistAdd = ref(false);
|
|
8
|
-
|
|
9
|
-
const { isAuthorized } = useUser(AuthorizationApiService);
|
|
10
8
|
const { openAuthPopup } = useAuthPopup();
|
|
11
9
|
|
|
12
|
-
const openPlaylistAdd = (card: IVideoCard | IVideoData) => {
|
|
10
|
+
const openPlaylistAdd = (isAuthorized: Ref<boolean>, card: IVideoCard | IVideoData) => {
|
|
13
11
|
if (isAuthorized.value) {
|
|
14
12
|
videoCard.value = card;
|
|
15
13
|
isPlaylistAdd.value = true;
|