Skip to content

Commit

Permalink
Remove fav bot on drop outside list
Browse files Browse the repository at this point in the history
  • Loading branch information
tanchekwei authored and sunner committed Jul 4, 2023
1 parent 969736a commit 169fb35
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/Footer/FooterBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,29 @@ onMounted(() => {
let sortable = undefined;
function initializeSortable() {
let isDropOnFavBotBar = false;
const onDragEnd = (event) => {
event.target.removeEventListener("dragend", onDragEnd);
if (isDropOnFavBotBar) {
return; // dropped on fav bot bar
}
// if not drop on fav bot bar, remove it from favorite bar
event.target.parentNode.removeChild(event.target);
store.commit("removeFavoriteBot", event.target.dataset.id);
rerenderFavBotLogos.value++; // trigger re-render to refresh order and shortkey
nextTick().then(() => {
sortable = undefined;
initializeSortable(); // re-initialize sortable instance after re-render
});
};
sortable = new Sortable(favBotLogosRef.value, {
animation: 200, // ms, animation speed moving items when sorting
// dragging started
onStart: function (favBot) {
isDropOnFavBotBar = false;
favBot.item.addEventListener("dragend", onDragEnd);
},
// dragging ended
onEnd: async function (favBot) {
if (favBot.oldIndex === favBot.newIndex) {
Expand All @@ -271,6 +292,9 @@ function initializeSortable() {
});
},
});
favBotLogosRef.value.addEventListener("drop", () => {
isDropOnFavBotBar = true;
});
}
defineExpose({
Expand Down

1 comment on commit 169fb35

@vercel
Copy link

@vercel vercel bot commented on 169fb35 Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

chatall – ./

chatall-git-main-sunner.vercel.app
chatall-sunner.vercel.app
chatall-llm.vercel.app

Please sign in to comment.