Skip to content

Commit

Permalink
use a computed to track changed history for drag drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Aug 21, 2024
1 parent f65df80 commit 32c57a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const historyStore = useHistoryStore();
const historyItemsStore = useHistoryItemsStore();
const { currentUser } = storeToRefs(useUserStore());
const { showDropZone, onDragEnter, onDragLeave, onDragOver, onDrop } = useHistoryDragDrop(props.history.id);
const historyIdComputed = computed(() => props.history.id);
const { showDropZone, onDragEnter, onDragLeave, onDragOver, onDrop } = useHistoryDragDrop(historyIdComputed);
const currentUserOwnsHistory = computed(() => {
return userOwnsHistory(currentUser.value, props.history);
Expand Down
17 changes: 12 additions & 5 deletions client/src/composables/historyDragDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import { useHistoryStore } from "@/stores/historyStore";
type DraggableHistoryItem = HistoryItemSummary | DCEDataset; // TODO: DCESummary instead of DCEDataset

export function useHistoryDragDrop(targetHistoryId?: Ref<string> | string, createNew = false, pinHistories = false) {
const destinationHistoryId = unref(targetHistoryId);
// convert destinationHistoryId to a ref if it's not already
const destinationHistoryId = computed(() => {
if (typeof targetHistoryId === "string") {
return targetHistoryId;
}
return unref(targetHistoryId);
});

const eventStore = useEventStore();
const historyStore = useHistoryStore();

Expand All @@ -29,8 +36,8 @@ export function useHistoryDragDrop(targetHistoryId?: Ref<string> | string, creat
const operationDisabled = computed(
() =>
!fromHistoryId.value ||
(destinationHistoryId && fromHistoryId.value === destinationHistoryId) ||
(!createNew && !destinationHistoryId) ||
(destinationHistoryId.value && fromHistoryId.value === destinationHistoryId.value) ||
(!createNew && !destinationHistoryId.value) ||
!getDragItems().length ||
processingDrop.value
);
Expand Down Expand Up @@ -83,8 +90,8 @@ export function useHistoryDragDrop(targetHistoryId?: Ref<string> | string, creat
const originalHistoryId = fromHistoryId.value as string;

let historyId;
if (destinationHistoryId) {
historyId = destinationHistoryId;
if (destinationHistoryId.value) {
historyId = destinationHistoryId.value;
} else if (createNew) {
await historyStore.createNewHistory();
historyId = historyStore.currentHistoryId;
Expand Down

0 comments on commit 32c57a8

Please sign in to comment.