fix: rolling id
This commit is contained in:
parent
ce94f9bcc4
commit
31ccf8d352
|
|
@ -60,7 +60,7 @@ export const GeneralPreviewComponent: FC<{
|
|||
index === renderContent.length - 1 ? 'pb-[12px]' : 'pb-[24px]'
|
||||
)}
|
||||
>
|
||||
<div className="w-[40px] flex flex-col items-center">
|
||||
<div className="min-w-[40px] h-[40px] min-h-[40px] w-[40px] flex flex-col items-center">
|
||||
<div className="relative">
|
||||
<img
|
||||
src={
|
||||
|
|
@ -75,7 +75,7 @@ export const GeneralPreviewComponent: FC<{
|
|||
{current !== 'global' && (
|
||||
<Image
|
||||
src={`/icons/platforms/${integration?.identifier}.png`}
|
||||
className="rounded-full absolute z-10 -bottom-[5px] -end-[5px] border border-fifth"
|
||||
className="min-w-[20px] min-h-[20px] rounded-full absolute z-10 -bottom-[5px] -end-[5px] border border-fifth"
|
||||
alt={integration.identifier}
|
||||
width={20}
|
||||
height={20}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { create } from 'zustand';
|
|||
import dayjs from 'dayjs';
|
||||
import { Integrations } from '@gitroom/frontend/components/launches/calendar.context';
|
||||
import { createRef, RefObject } from 'react';
|
||||
import { arrayMoveImmutable } from 'array-move';
|
||||
import { PostComment } from '@gitroom/frontend/components/new-launch/providers/high.order.provider';
|
||||
import { newDayjs } from '@gitroom/frontend/components/layout/set.timezone';
|
||||
|
||||
|
|
@ -257,22 +256,45 @@ export const useLaunchStore = create<StoreState>()((set) => ({
|
|||
};
|
||||
}),
|
||||
deleteGlobalValue: (index: number) =>
|
||||
set((state) => ({
|
||||
global: state.global.filter((_, i) => i !== index),
|
||||
})),
|
||||
set((state) => {
|
||||
// Preserve the IDs at their current positions
|
||||
const ids = state.global.map((item) => item.id);
|
||||
|
||||
// Get remaining data (content, delay, media) after filtering out deleted index
|
||||
const remainingData = state.global
|
||||
.filter((_, i) => i !== index)
|
||||
.map(({ id, ...rest }) => rest);
|
||||
|
||||
// Reconstruct with preserved IDs
|
||||
return {
|
||||
global: remainingData.map((data, i) => ({
|
||||
id: ids[i],
|
||||
...data,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
deleteInternalValue: (integrationId: string, index: number) =>
|
||||
set((state) => {
|
||||
return {
|
||||
internal: state.internal.map((i) => {
|
||||
if (i.integration.id === integrationId) {
|
||||
internal: state.internal.map((item) => {
|
||||
if (item.integration.id === integrationId) {
|
||||
// Preserve the IDs at their current positions
|
||||
const ids = item.integrationValue.map((v) => v.id);
|
||||
|
||||
// Get remaining data after filtering out deleted index
|
||||
const remainingData = item.integrationValue
|
||||
.filter((_, idx) => idx !== index)
|
||||
.map(({ id, ...rest }) => rest);
|
||||
|
||||
return {
|
||||
...i,
|
||||
integrationValue: i.integrationValue.filter(
|
||||
(_, idx) => idx !== index
|
||||
),
|
||||
...item,
|
||||
integrationValue: remainingData.map((data, i) => ({
|
||||
id: ids[i],
|
||||
...data,
|
||||
})),
|
||||
};
|
||||
}
|
||||
return i;
|
||||
return item;
|
||||
}),
|
||||
};
|
||||
}),
|
||||
|
|
@ -305,12 +327,35 @@ export const useLaunchStore = create<StoreState>()((set) => ({
|
|||
}),
|
||||
changeOrderGlobal: (index: number, direction: 'up' | 'down') =>
|
||||
set((state) => {
|
||||
const targetIndex = direction === 'up' ? index - 1 : index + 1;
|
||||
|
||||
if (targetIndex < 0 || targetIndex >= state.global.length) {
|
||||
return { global: state.global };
|
||||
}
|
||||
|
||||
const currentItem = state.global[index];
|
||||
const targetItem = state.global[targetIndex];
|
||||
|
||||
return {
|
||||
global: arrayMoveImmutable(
|
||||
state.global,
|
||||
index,
|
||||
direction === 'up' ? index - 1 : index + 1
|
||||
),
|
||||
global: state.global.map((item, i) => {
|
||||
if (i === index) {
|
||||
return {
|
||||
id: item.id,
|
||||
content: targetItem.content,
|
||||
delay: targetItem.delay,
|
||||
media: targetItem.media,
|
||||
};
|
||||
}
|
||||
if (i === targetIndex) {
|
||||
return {
|
||||
id: item.id,
|
||||
content: currentItem.content,
|
||||
delay: currentItem.delay,
|
||||
media: currentItem.media,
|
||||
};
|
||||
}
|
||||
return item;
|
||||
}),
|
||||
};
|
||||
}),
|
||||
changeOrderInternal: (
|
||||
|
|
@ -322,13 +367,36 @@ export const useLaunchStore = create<StoreState>()((set) => ({
|
|||
return {
|
||||
internal: state.internal.map((item) => {
|
||||
if (item.integration.id === integrationId) {
|
||||
const targetIndex = direction === 'up' ? index - 1 : index + 1;
|
||||
|
||||
if (targetIndex < 0 || targetIndex >= item.integrationValue.length) {
|
||||
return item;
|
||||
}
|
||||
|
||||
const currentValue = item.integrationValue[index];
|
||||
const targetValue = item.integrationValue[targetIndex];
|
||||
|
||||
return {
|
||||
...item,
|
||||
integrationValue: arrayMoveImmutable(
|
||||
item.integrationValue,
|
||||
index,
|
||||
direction === 'up' ? index - 1 : index + 1
|
||||
),
|
||||
integrationValue: item.integrationValue.map((v, i) => {
|
||||
if (i === index) {
|
||||
return {
|
||||
id: v.id,
|
||||
content: targetValue.content,
|
||||
delay: targetValue.delay,
|
||||
media: targetValue.media,
|
||||
};
|
||||
}
|
||||
if (i === targetIndex) {
|
||||
return {
|
||||
id: v.id,
|
||||
content: currentValue.content,
|
||||
delay: currentValue.delay,
|
||||
media: currentValue.media,
|
||||
};
|
||||
}
|
||||
return v;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue