Add ability to reorder apps on the home screen
Implements drag-and-drop functionality for reordering apps using @dnd-kit, adds a new `userAppOrdersTable` to the database schema to store user-specific app order preferences, and introduces a new API endpoint `/api/me/app-order` for updating these preferences. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 77cfe984-2c65-4152-bb7a-0df28274fe66 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: e782e35b-00f5-4b9b-8931-63051a25df80 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/c3c252e4-c83d-40ca-9fff-99a3ea60701e/77cfe984-2c65-4152-bb7a-0df28274fe66/PrQkd7G Replit-Helium-Checkpoint-Created: true
This commit is contained in:
@@ -40,6 +40,7 @@ import type {
|
||||
UpdateAppBody,
|
||||
UpdateAppSettingsBody,
|
||||
UpdateLanguageBody,
|
||||
UpdateMyAppOrderBody,
|
||||
UpdateServiceBody,
|
||||
UpdateUserBody,
|
||||
UserProfile,
|
||||
@@ -928,6 +929,92 @@ export const useDeleteApp = <
|
||||
return useMutation(getDeleteAppMutationOptions(options));
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary Set the current user's preferred home apps order
|
||||
*/
|
||||
export const getUpdateMyAppOrderUrl = () => {
|
||||
return `/api/me/app-order`;
|
||||
};
|
||||
|
||||
export const updateMyAppOrder = async (
|
||||
updateMyAppOrderBody: UpdateMyAppOrderBody,
|
||||
options?: RequestInit,
|
||||
): Promise<App[]> => {
|
||||
return customFetch<App[]>(getUpdateMyAppOrderUrl(), {
|
||||
...options,
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json", ...options?.headers },
|
||||
body: JSON.stringify(updateMyAppOrderBody),
|
||||
});
|
||||
};
|
||||
|
||||
export const getUpdateMyAppOrderMutationOptions = <
|
||||
TError = ErrorType<ErrorResponse>,
|
||||
TContext = unknown,
|
||||
>(options?: {
|
||||
mutation?: UseMutationOptions<
|
||||
Awaited<ReturnType<typeof updateMyAppOrder>>,
|
||||
TError,
|
||||
{ data: BodyType<UpdateMyAppOrderBody> },
|
||||
TContext
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
}): UseMutationOptions<
|
||||
Awaited<ReturnType<typeof updateMyAppOrder>>,
|
||||
TError,
|
||||
{ data: BodyType<UpdateMyAppOrderBody> },
|
||||
TContext
|
||||
> => {
|
||||
const mutationKey = ["updateMyAppOrder"];
|
||||
const { mutation: mutationOptions, request: requestOptions } = options
|
||||
? options.mutation &&
|
||||
"mutationKey" in options.mutation &&
|
||||
options.mutation.mutationKey
|
||||
? options
|
||||
: { ...options, mutation: { ...options.mutation, mutationKey } }
|
||||
: { mutation: { mutationKey }, request: undefined };
|
||||
|
||||
const mutationFn: MutationFunction<
|
||||
Awaited<ReturnType<typeof updateMyAppOrder>>,
|
||||
{ data: BodyType<UpdateMyAppOrderBody> }
|
||||
> = (props) => {
|
||||
const { data } = props ?? {};
|
||||
|
||||
return updateMyAppOrder(data, requestOptions);
|
||||
};
|
||||
|
||||
return { mutationFn, ...mutationOptions };
|
||||
};
|
||||
|
||||
export type UpdateMyAppOrderMutationResult = NonNullable<
|
||||
Awaited<ReturnType<typeof updateMyAppOrder>>
|
||||
>;
|
||||
export type UpdateMyAppOrderMutationBody = BodyType<UpdateMyAppOrderBody>;
|
||||
export type UpdateMyAppOrderMutationError = ErrorType<ErrorResponse>;
|
||||
|
||||
/**
|
||||
* @summary Set the current user's preferred home apps order
|
||||
*/
|
||||
export const useUpdateMyAppOrder = <
|
||||
TError = ErrorType<ErrorResponse>,
|
||||
TContext = unknown,
|
||||
>(options?: {
|
||||
mutation?: UseMutationOptions<
|
||||
Awaited<ReturnType<typeof updateMyAppOrder>>,
|
||||
TError,
|
||||
{ data: BodyType<UpdateMyAppOrderBody> },
|
||||
TContext
|
||||
>;
|
||||
request?: SecondParameter<typeof customFetch>;
|
||||
}): UseMutationResult<
|
||||
Awaited<ReturnType<typeof updateMyAppOrder>>,
|
||||
TError,
|
||||
{ data: BodyType<UpdateMyAppOrderBody> },
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getUpdateMyAppOrderMutationOptions(options));
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary Get application settings (public)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user