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