mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
player: renamed apiGetEmbedYoutube
This commit is contained in:
parent
4da55dcd21
commit
7031084b09
7 changed files with 130 additions and 140 deletions
|
@ -1,33 +1,18 @@
|
|||
import { INode, IResultWithStatus } from '~/redux/types';
|
||||
import { api, configWithToken, errorMiddleware, resultMiddleware } from '~/utils/api';
|
||||
import { api, cleanResult } from '~/utils/api';
|
||||
import { API } from '~/constants/api';
|
||||
import {
|
||||
ApiGetNodesOfTagRequest,
|
||||
ApiGetNodesOfTagResult,
|
||||
ApiGetTagSuggestionsRequest,
|
||||
ApiGetTagSuggestionsResult,
|
||||
} from '~/redux/tag/types';
|
||||
|
||||
export const getTagNodes = ({
|
||||
access,
|
||||
tag,
|
||||
offset,
|
||||
limit,
|
||||
}: {
|
||||
access: string;
|
||||
tag: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
}): Promise<IResultWithStatus<{ nodes: INode[]; count: number }>> =>
|
||||
export const apiGetNodesOfTag = ({ tag, offset, limit }: ApiGetNodesOfTagRequest) =>
|
||||
api
|
||||
.get(API.TAG.NODES, configWithToken(access, { params: { name: tag, offset, limit } }))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
.get<ApiGetNodesOfTagResult>(API.TAG.NODES, { params: { name: tag, offset, limit } })
|
||||
.then(cleanResult);
|
||||
|
||||
export const getTagAutocomplete = ({
|
||||
search,
|
||||
exclude,
|
||||
access,
|
||||
}: {
|
||||
access: string;
|
||||
search: string;
|
||||
exclude: string[];
|
||||
}): Promise<IResultWithStatus<{ tags: string[] }>> =>
|
||||
export const apiGetTagSuggestions = ({ search, exclude }: ApiGetTagSuggestionsRequest) =>
|
||||
api
|
||||
.get(API.TAG.AUTOCOMPLETE, configWithToken(access, { params: { search, exclude } }))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
.get<ApiGetTagSuggestionsResult>(API.TAG.AUTOCOMPLETE, { params: { search, exclude } })
|
||||
.then(cleanResult);
|
||||
|
|
|
@ -6,48 +6,43 @@ import {
|
|||
tagSetAutocomplete,
|
||||
tagSetNodes,
|
||||
} from '~/redux/tag/actions';
|
||||
import { wrap } from '~/redux/auth/sagas';
|
||||
import { selectTagNodes } from '~/redux/tag/selectors';
|
||||
import { getTagAutocomplete, getTagNodes } from '~/redux/tag/api';
|
||||
import { apiGetTagSuggestions, apiGetNodesOfTag } from '~/redux/tag/api';
|
||||
import { Unwrap } from '~/redux/types';
|
||||
|
||||
function* loadTagNodes({ tag }: ReturnType<typeof tagLoadNodes>) {
|
||||
yield put(tagSetNodes({ isLoading: true }));
|
||||
yield put(tagSetNodes({ isLoading: true, list: [] }));
|
||||
|
||||
try {
|
||||
const { list }: ReturnType<typeof selectTagNodes> = yield select(selectTagNodes);
|
||||
const { data, error }: Unwrap<typeof getTagNodes> = yield call(wrap, getTagNodes, {
|
||||
const data: Unwrap<typeof apiGetNodesOfTag> = yield call(apiGetNodesOfTag, {
|
||||
tag,
|
||||
limit: 18,
|
||||
offset: list.length,
|
||||
});
|
||||
|
||||
if (error) throw new Error(error);
|
||||
|
||||
yield put(tagSetNodes({ isLoading: false, list: [...list, ...data.nodes], count: data.count }));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
yield put(tagSetNodes({ list: [...list, ...data.nodes], count: data.count }));
|
||||
} catch {
|
||||
} finally {
|
||||
yield put(tagSetNodes({ isLoading: false }));
|
||||
}
|
||||
}
|
||||
|
||||
function* loadAutocomplete({ search, exclude }: ReturnType<typeof tagLoadAutocomplete>) {
|
||||
if (search.length < 3) return;
|
||||
if (search.length < 2) return;
|
||||
|
||||
try {
|
||||
yield put(tagSetAutocomplete({ isLoading: true }));
|
||||
yield delay(100);
|
||||
yield delay(200);
|
||||
|
||||
const { data, error }: Unwrap<typeof getTagAutocomplete> = yield call(
|
||||
wrap,
|
||||
getTagAutocomplete,
|
||||
{ search, exclude }
|
||||
);
|
||||
const data: Unwrap<typeof apiGetTagSuggestions> = yield call(apiGetTagSuggestions, {
|
||||
search,
|
||||
exclude,
|
||||
});
|
||||
|
||||
if (error) throw new Error(error);
|
||||
|
||||
yield put(tagSetAutocomplete({ options: data.tags, isLoading: false }));
|
||||
} catch (e) {
|
||||
yield put(tagSetAutocomplete({ options: data.tags }));
|
||||
} catch {
|
||||
} finally {
|
||||
yield put(tagSetAutocomplete({ isLoading: false }));
|
||||
}
|
||||
}
|
||||
|
|
16
src/redux/tag/types.ts
Normal file
16
src/redux/tag/types.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { INode } from '~/redux/types';
|
||||
|
||||
export type ApiGetNodesOfTagRequest = {
|
||||
tag: string;
|
||||
offset: number;
|
||||
limit: number;
|
||||
};
|
||||
export type ApiGetNodesOfTagResult = { nodes: INode[]; count: number };
|
||||
|
||||
export type ApiGetTagSuggestionsRequest = {
|
||||
search: string;
|
||||
exclude: string[];
|
||||
};
|
||||
export type ApiGetTagSuggestionsResult = {
|
||||
tags: string[];
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue