Skip to content

Commit

Permalink
chore: Renaming variables in assets/js/app.js. #416
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Sep 9, 2023
1 parent b8aee0e commit 26b804c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ Hooks.Items = {
})

this.el.addEventListener("remove-highlight", e => {
hook.pushEventTo("#items", "removeHighlight", {id: e.detail.id})
hook.pushEventTo("#items", "remove_highlight", {id: e.detail.id})
// console.log('remove-highlight', e.detail.id)
})

this.el.addEventListener("dragoverItem", e => {
// console.log("dragoverItem", e.detail)
this.el.addEventListener("dragover_item", e => {
// console.log("dragover_item", e.detail)
const currentItemId = e.detail.currentItem.id
const selectedItemId = e.detail.selectedItemId
if( currentItemId != selectedItemId) {
hook.pushEventTo("#items", "dragoverItem", {currentItemId: currentItemId, selectedItemId: selectedItemId})
hook.pushEventTo("#items", "dragover_item", {currentItemId: currentItemId, selectedItemId: selectedItemId})
itemId_to = e.detail.currentItem.dataset.id
}
})

this.el.addEventListener("update-indexes", e => {
this.el.addEventListener("update_indexes", e => {
const item_id = e.detail.fromItemId
const list_ids = get_list_item_cids()
console.log("update-indexes", e.detail, "list: ", list_ids)
console.log("update_indexes", e.detail, "list: ", list_ids)
// Check if both "from" and "to" are defined
if(item_id && itemId_to && item_id != itemId_to) {
hook.pushEventTo("#items", "update_list_seq",
Expand Down
4 changes: 2 additions & 2 deletions lib/app_web/live/app_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ defmodule AppWeb.AppLive do
end

@impl true
def handle_event("removeHighlight", %{"id" => id}, socket) do
def handle_event("remove_highlight", %{"id" => id}, socket) do
AppWeb.Endpoint.broadcast(@topic, "move_items", {:drop_item, id})
{:noreply, socket}
end

@impl true
def handle_event(
"dragoverItem",
"dragover_item",
%{
"currentItemId" => current_item_id,
"selectedItemId" => selected_item_id
Expand Down
4 changes: 2 additions & 2 deletions lib/app_web/live/app_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
draggable={"#{if item.id == @editing do 'false' else 'true' end}"}
x-data="{selected: false}"
x-on:dragstart="selected = true; $dispatch('highlight', {id: $el.id}); selectedItem = $el"
x-on:dragend="selected = false; $dispatch('remove-highlight', {id: $el.id}); selectedItem = null; $dispatch('update-indexes', {fromItemId: $el.dataset.id})"
x-on:dragend="selected = false; $dispatch('remove-highlight', {id: $el.id}); selectedItem = null; $dispatch('update_indexes', {fromItemId: $el.dataset.id})"
x-bind:class="selected ?? 'cursor-grabbing'"
x-on:dragover.throttle="$dispatch('dragoverItem', {selectedItemId: selectedItem.id, currentItem: $el})"
x-on:dragover.throttle="$dispatch('dragover_item', {selectedItemId: selectedItem.id, currentItem: $el})"
data-highlight={JS.add_class("bg-teal-300")}
data-remove-highlight={JS.remove_class("bg-teal-300")}
>
Expand Down
4 changes: 2 additions & 2 deletions test/app_web/live/app_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,12 @@ defmodule AppWeb.AppLiveTest do
|> length() > 0

# Dragover and remove highlight
render_hook(view, "dragoverItem", %{
render_hook(view, "dragover_item", %{
"currentItemId" => item2.id,
"selectedItemId" => item.id
})

assert render_hook(view, "removeHighlight", %{"id" => item.id})
assert render_hook(view, "remove_highlight", %{"id" => item.id})

# reorder items:
render_hook(view, "update_list_seq", %{
Expand Down

0 comments on commit 26b804c

Please sign in to comment.