Избежать дублирование евентов в FullCalendar
У меня есть календарь (FullCalendar) и список с элементами, которые можно перетаскивать на календарь, а так же стоит подтягивание евентов. Когда я перетаскиваю со списка на календарь, а потом нажимаю "предыдущая" и обратно "следующая" (чтобы подтянуло евенты), у меня накладываются два евента, один который я перетащил, второй, который подтянулся из базы.
Как этого избежать?
const profileList = document.querySelector('.profile-list');
const profileListItems = [...profileList.querySelectorAll('.profile-list__item')];
const calendarEl = document.querySelector('.calendar');
new FullCalendar.Draggable(profileList,
{
itemSelector: '.profile-list__item',
eventData: function(eventEl)
{
const name = eventEl.querySelector('.profile__fullname').textContent;
const tel = eventEl.querySelector('.profile__description').textContent;
const id = eventEl.dataset.id;
return {
title: `${name} - ${tel}`,
url: '/profile/' +id,
color: '#DC4242',
backgroundColor: '#252525',
textColor: '#ACACAC'
};
}
}
);
const calendar = new FullCalendar.Calendar(calendarEl,
{
initialView: 'timeGridWeek',
headerToolbar:
{
left : 'prev,next today',
center: 'title',
right : 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
locale: 'ru',
editable: false,
droppable: true,
nowIndicator: true,
expandRows: true,
eventOverlap: false,
eventDurationEditable: false,
navLinks: true,
allDaySlot: false,
height: 'calc(100vh - 56px - 30px)',
slotDuration: '01:00:00',
slotMinTime: '08:00:00',
slotMaxTime: '23:00:00',
buttonText:
{
today : 'сегодня',
month : 'месяц',
week : 'неделя',
day : 'день',
list : 'список'
},
initialEvents:
{
url: '/events/get',
method: 'POST',
color: '#DC4242',
backgroundColor: '#252525',
textColor: '#ACACAC'
},
noEventsText: 'Нет событий для отображения',
drop: function(arg)
{
const date = new Date(arg.dateStr).getTime();
const profileId = arg.draggedEl.dataset.id;
const profileItem = profileListItems.find((profile) => profile.dataset.id == profileId);
console.log('profileItem:', profileItem)
profileItem.querySelector('.profile__description:last-child').textContent = new Date(date).toLocaleString();
fetch('/profile/date_add',
{
method: 'POST',
headers:
{
"Content-Type": 'application/json; charset=utf-8'
},
body: JSON.stringify(
{
profileId,
date
})
}
);
},
eventClick: function(info)
{
info.jsEvent.preventDefault();
if (info.event.url)
{
window.open(info.event.url, 'Profile');
}
}
}
);
calendar.render();
