♻️ refactor(api): Sort and Announcement
This commit is contained in:
parent
93a0a88f88
commit
38d561604d
@ -205,7 +205,7 @@ export default function NodeTable() {
|
||||
await createNode({
|
||||
...params,
|
||||
enable: false,
|
||||
});
|
||||
} as API.CreateNodeRequest);
|
||||
toast.success(t('copySuccess'));
|
||||
ref.current?.refresh();
|
||||
setLoading(false);
|
||||
@ -258,26 +258,27 @@ export default function NodeTable() {
|
||||
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
||||
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
||||
|
||||
const originalSorts = items.map((item) => ({ id: item.id, sort: item.sort || item.id }));
|
||||
const originalSortMap = new Map(items.map((item) => [item.id, item.sort || item.id]));
|
||||
|
||||
const [movedItem] = items.splice(sourceIndex, 1);
|
||||
items.splice(targetIndex, 0, movedItem!);
|
||||
|
||||
const updatedItems = items.map((item) => {
|
||||
const originalSort = originalSorts.find((sortItem) => sortItem.id === item.id)?.sort;
|
||||
return {
|
||||
...item,
|
||||
sort: originalSort !== undefined ? originalSort : item.sort,
|
||||
};
|
||||
});
|
||||
nodeSort({
|
||||
sort: updatedItems.map((item) => {
|
||||
return {
|
||||
id: item.id,
|
||||
sort: item.sort,
|
||||
};
|
||||
}),
|
||||
const updatedItems = items.map((item, index) => {
|
||||
const originalSort = originalSortMap.get(item.id);
|
||||
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
||||
return { ...item, sort: newSort };
|
||||
});
|
||||
|
||||
const changedItems = updatedItems.filter(
|
||||
(item) => originalSortMap.get(item.id) !== item.sort,
|
||||
);
|
||||
|
||||
if (changedItems.length > 0) {
|
||||
nodeSort({
|
||||
sort: changedItems.map((item) => ({ id: item.id, sort: item.sort })),
|
||||
});
|
||||
}
|
||||
|
||||
return updatedItems;
|
||||
}}
|
||||
/>
|
||||
|
||||
@ -266,26 +266,27 @@ export default function SubscribeTable() {
|
||||
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
||||
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
||||
|
||||
const originalSorts = items.map((item) => ({ id: item.id, sort: item.sort || item.id }));
|
||||
const originalSortMap = new Map(items.map((item) => [item.id, item.sort || item.id]));
|
||||
|
||||
const [movedItem] = items.splice(sourceIndex, 1);
|
||||
items.splice(targetIndex, 0, movedItem!);
|
||||
|
||||
const updatedItems = items.map((item) => {
|
||||
const originalSort = originalSorts.find((sortItem) => sortItem.id === item.id)?.sort;
|
||||
return {
|
||||
...item,
|
||||
sort: originalSort !== undefined ? originalSort : item.sort,
|
||||
};
|
||||
});
|
||||
subscribeSort({
|
||||
sort: updatedItems.map((item) => {
|
||||
return {
|
||||
id: item.id,
|
||||
sort: item.sort,
|
||||
};
|
||||
}),
|
||||
const updatedItems = items.map((item, index) => {
|
||||
const originalSort = originalSortMap.get(item.id);
|
||||
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
||||
return { ...item, sort: newSort };
|
||||
});
|
||||
|
||||
const changedItems = updatedItems.filter(
|
||||
(item) => originalSortMap.get(item.id) !== item.sort,
|
||||
);
|
||||
|
||||
if (changedItems.length > 0) {
|
||||
subscribeSort({
|
||||
sort: changedItems.map((item) => ({ id: item.id, sort: item.sort })),
|
||||
});
|
||||
}
|
||||
|
||||
return updatedItems;
|
||||
}}
|
||||
/>
|
||||
|
||||
10
apps/admin/services/admin/typings.d.ts
vendored
10
apps/admin/services/admin/typings.d.ts
vendored
@ -131,6 +131,7 @@ declare namespace API {
|
||||
protocol: string;
|
||||
config: Record<string, any>;
|
||||
enable: boolean;
|
||||
sort: number;
|
||||
};
|
||||
|
||||
type CreateOrderRequest = {
|
||||
@ -276,14 +277,18 @@ declare namespace API {
|
||||
type GetAnnouncementListParams = {
|
||||
page: number;
|
||||
size: number;
|
||||
enable?: boolean;
|
||||
show?: boolean;
|
||||
pinned?: boolean;
|
||||
popup?: boolean;
|
||||
search?: string;
|
||||
};
|
||||
|
||||
type GetAnnouncementListRequest = {
|
||||
page: number;
|
||||
size: number;
|
||||
enable?: boolean;
|
||||
show?: boolean;
|
||||
pinned?: boolean;
|
||||
popup?: boolean;
|
||||
search?: string;
|
||||
};
|
||||
|
||||
@ -891,6 +896,7 @@ declare namespace API {
|
||||
protocol: string;
|
||||
config: Record<string, any>;
|
||||
enable: boolean;
|
||||
sort: number;
|
||||
};
|
||||
|
||||
type UpdateOrderStatusRequest = {
|
||||
|
||||
@ -12,7 +12,9 @@ export default function Page() {
|
||||
queryFn: async () => {
|
||||
const { data } = await queryAnnouncement({
|
||||
page: 1,
|
||||
size: 20,
|
||||
size: 99,
|
||||
pinned: false,
|
||||
popup: false,
|
||||
});
|
||||
return data.data?.announcements || [];
|
||||
},
|
||||
|
||||
@ -18,7 +18,9 @@ export default async function Announcement({
|
||||
data = await queryAnnouncement(
|
||||
{
|
||||
page: 1,
|
||||
size: 50,
|
||||
size: 10,
|
||||
pinned: type === 'pinned',
|
||||
popup: type === 'popup',
|
||||
},
|
||||
{
|
||||
skipErrorHandler: true,
|
||||
|
||||
4
apps/user/services/user/typings.d.ts
vendored
4
apps/user/services/user/typings.d.ts
vendored
@ -249,11 +249,15 @@ declare namespace API {
|
||||
type QueryAnnouncementParams = {
|
||||
page: number;
|
||||
size: number;
|
||||
pinned: boolean;
|
||||
popup: boolean;
|
||||
};
|
||||
|
||||
type QueryAnnouncementRequest = {
|
||||
page: number;
|
||||
size: number;
|
||||
pinned: boolean;
|
||||
popup: boolean;
|
||||
};
|
||||
|
||||
type QueryAnnouncementResponse = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user