Started to work on media upload and organization
This commit is contained in:
@@ -10,7 +10,7 @@ export interface ApiResponse<T> {
|
||||
data?: T;
|
||||
}
|
||||
|
||||
async function request<T>(
|
||||
export async function request<T>(
|
||||
url: string,
|
||||
options: {
|
||||
method?: "GET" | "POST" | "PATCH" | "DELETE";
|
||||
@@ -81,14 +81,14 @@ async function mutationHandler<T, A>(
|
||||
}
|
||||
|
||||
export function useApi<T>(
|
||||
url: string,
|
||||
endpoint: string,
|
||||
config?: SWRConfiguration,
|
||||
requiresAuth: boolean = true,
|
||||
csrfToken?: boolean,
|
||||
) {
|
||||
const swr = useSWR<ApiResponse<T>>(
|
||||
url,
|
||||
() => fetcher(url, requiresAuth, csrfToken),
|
||||
endpoint,
|
||||
() => fetcher(endpoint, requiresAuth, csrfToken),
|
||||
config,
|
||||
);
|
||||
|
||||
|
||||
26
frontend/hooks/use-media.tsx
Normal file
26
frontend/hooks/use-media.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import useApiMutation, { useApi } from "./use-api";
|
||||
import IPaginatedResponse from "@/interfaces/IPaginatedResponse";
|
||||
import Media from "@/interfaces/Media";
|
||||
|
||||
interface MediaResponse {
|
||||
page: number;
|
||||
limit: number;
|
||||
totalPages: number;
|
||||
items: [];
|
||||
}
|
||||
|
||||
export default function useMedia(_limit: number = 20) {
|
||||
const [page, setPage] = useState(1);
|
||||
const [limit, setLimit] = useState(_limit);
|
||||
const res = useApi<IPaginatedResponse<Media>>(
|
||||
`/media?page=${page}&limit=${limit}`,
|
||||
);
|
||||
return {
|
||||
...res,
|
||||
setPage,
|
||||
setLimit,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user