feat: add projects page and rework home page

This commit is contained in:
2026-07-09 16:24:51 +02:00
parent 8aa5aca650
commit 834d7ed00f
32 changed files with 720 additions and 77 deletions
+21 -16
View File
@@ -13,12 +13,17 @@ export interface UseApi {
patch: <T, B = unknown>(path: string, opts?: FetchOptions, immediate?: boolean, body?: B) => UseApiResponse<T, B>;
}
export interface CreateRequestOptions<PayloadT> {
host?: string;
path: string;
immediate?: boolean;
method: HttpMethod;
body?: PayloadT;
opts?: FetchOptions;
}
const createRequest = <ResponseT = unknown, PayloadT = unknown>(
method: HttpMethod,
url: string,
opts?: FetchOptions,
immediate: boolean = true,
body?: PayloadT,
options: CreateRequestOptions<PayloadT>,
): QueryResult<ResponseT, PayloadT> => {
const response = new QueryResult<ResponseT, PayloadT>();
const { apiBase } = useRuntimeConfig().public;
@@ -28,10 +33,10 @@ const createRequest = <ResponseT = unknown, PayloadT = unknown>(
response.error.value = null;
try {
const res = await $fetch<ResponseT>(url, {
baseURL: apiBase,
...opts,
method,
const res = await $fetch<ResponseT>(options.path, {
...options.opts,
baseURL: options.host ?? apiBase,
method: options.method,
body: requestBody ?? undefined,
});
response.data.value = res;
@@ -48,22 +53,22 @@ const createRequest = <ResponseT = unknown, PayloadT = unknown>(
};
response.run = run;
if (immediate) run(body);
if (options.immediate) run(options.body);
return response;
};
export const useApi = (): UseApi => {
export const useApi = (host?: string): UseApi => {
const get = <T>(path: string, opts?: FetchOptions, immediate: boolean = true) =>
createRequest<T>('GET', path, opts, immediate);
createRequest<T>({ method: 'GET', path, opts, immediate, host });
const del = <T>(path: string, opts?: FetchOptions, immediate: boolean = true) =>
createRequest<T>('DELETE', path, opts, immediate);
createRequest<T>({ method: 'DELETE', path, opts, immediate, host });
const post = <T, B = unknown>(path: string, opts?: FetchOptions, immediate: boolean = true, body?: B) =>
createRequest<T, B>('POST', path, opts, immediate, body);
createRequest<T, B>({ method: 'POST', path, opts, immediate, body, host });
const put = <T, B = unknown>(path: string, opts?: FetchOptions, immediate: boolean = true, body?: B) =>
createRequest<T, B>('PUT', path, opts, immediate, body);
createRequest<T, B>({ method: 'PUT', path, opts, immediate, body, host });
const patch = <T, B = unknown>(path: string, opts?: FetchOptions, immediate: boolean = true, body?: B) =>
createRequest<T, B>('PATCH', path, opts, immediate, body);
createRequest<T, B>({ method: 'PATCH', path, opts, immediate, body, host });
return { get, post, put, patch, del };
};