Skip to content

Commit e689658

Browse files
committed
Append dropped cards instantly instead of relying on server-side rendering to refresh the columns
This also replaces sorting by "created at" with sorting by "updated at" for the Not now column. Cards will drop at the top by default, respecting golden cards.
1 parent 069e0ca commit e689658

File tree

11 files changed

+51
-41
lines changed

11 files changed

+51
-41
lines changed

app/assets/stylesheets/card-columns.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@
426426
}
427427
}
428428

429+
.cards__list:has(> :not(.blank-slate--card)) .card--hide-unless-empty {
430+
display: none;
431+
}
432+
429433
/* TODO: I think this is legacy now? */
430434
.cards__heading {
431435
display: flex;

app/controllers/boards/columns/not_nows_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Boards::Columns::NotNowsController < ApplicationController
22
include BoardScoped
33

44
def show
5-
set_page_and_extract_portion_from @board.cards.postponed.reverse_chronologically.with_golden_first.preloaded
5+
set_page_and_extract_portion_from @board.cards.postponed.latest.preloaded
66
fresh_when etag: @page.records
77
end
88
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Public::Boards::Columns::NotNowsController < Public::BaseController
22
def show
3-
set_page_and_extract_portion_from @board.cards.postponed.reverse_chronologically.with_golden_first
3+
set_page_and_extract_portion_from @board.cards.postponed.latest
44
end
55
end

app/helpers/cards_helper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
module CardsHelper
2-
def card_article_tag(card, id: dom_id(card, :article), **options, &block)
2+
def card_article_tag(card, id: dom_id(card, :article), data: {}, **options, &block)
33
classes = [
44
options.delete(:class),
55
("golden-effect" if card.golden?),
66
("card--postponed" if card.postponed?),
77
("card--active" if card.active?)
88
].compact.join(" ")
99

10+
data[:drag_and_drop_top] = true if card.golden? && !card.closed? && !card.postponed?
11+
1012
tag.article \
1113
id: id,
1214
style: "--card-color: #{card.color}; view-transition-name: #{id}",
1315
class: classes,
16+
data: data,
1417
**options,
1518
&block
1619
end

app/javascript/controllers/drag_and_drop_controller.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default class extends Controller {
3939
this.wasDropped = true
4040
this.#decreaseCounter(this.sourceContainer)
4141
const sourceContainer = this.sourceContainer
42+
this.#insertDraggedItem(container, this.dragItem)
4243
await this.#submitDropRequest(this.dragItem, container)
4344
this.#reloadSourceFrame(sourceContainer);
4445
}
@@ -47,10 +48,6 @@ export default class extends Controller {
4748
this.dragItem.classList.remove(this.draggedItemClass)
4849
this.#clearContainerHoverClasses()
4950

50-
if (this.wasDropped) {
51-
this.dragItem.remove()
52-
}
53-
5451
this.sourceContainer = null
5552
this.dragItem = null
5653
this.wasDropped = false
@@ -68,19 +65,6 @@ export default class extends Controller {
6865
this.containerTargets.forEach(container => container.classList.remove(this.hoverContainerClass))
6966
}
7067

71-
async #submitDropRequest(item, container) {
72-
const body = new FormData()
73-
const id = item.dataset.id
74-
const url = container.dataset.dragAndDropUrl.replaceAll("__id__", id)
75-
76-
return post(url, { body, headers: { Accept: "text/vnd.turbo-stream.html" } })
77-
}
78-
79-
#reloadSourceFrame(sourceContainer) {
80-
const frame = sourceContainer.querySelector("[data-drag-and-drop-refresh]")
81-
if (frame) frame.reload()
82-
}
83-
8468
#decreaseCounter(sourceContainer) {
8569
const counterElement = sourceContainer.querySelector("[data-drag-and-drop-counter]")
8670
if (counterElement) {
@@ -94,4 +78,30 @@ export default class extends Controller {
9478
}
9579
}
9680
}
81+
82+
#insertDraggedItem(container, item) {
83+
const itemContainer = container.querySelector("[data-drag-drop-item-container]")
84+
const topItems = itemContainer.querySelectorAll("[data-drag-and-drop-top]")
85+
const lastTopItem = topItems[topItems.length - 1]
86+
87+
if (lastTopItem) {
88+
console.debug("INSERTING AFTER", lastTopItem);
89+
lastTopItem.after(item)
90+
} else {
91+
itemContainer.prepend(item)
92+
}
93+
}
94+
95+
async #submitDropRequest(item, container) {
96+
const body = new FormData()
97+
const id = item.dataset.id
98+
const url = container.dataset.dragAndDropUrl.replaceAll("__id__", id)
99+
100+
return post(url, { body, headers: { Accept: "text/vnd.turbo-stream.html" } })
101+
}
102+
103+
#reloadSourceFrame(sourceContainer) {
104+
const frame = sourceContainer.querySelector("[data-drag-and-drop-refresh]")
105+
if (frame) frame.reload()
106+
}
97107
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="cards__list" data-drag-drop-item-container>
2+
<div class="card blank-slate blank-slate--card card--hide-unless-empty">
3+
<p class="txt-align-center card--hide-unless-empty">Drag cards here</p>
4+
<p class="txt-align-center blank-slate-for-grid card--hide-unless-empty">Nothing here</p>
5+
</div>
6+
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div class="cards__list">
1+
<div class="cards__list" data-drag-drop-item-container >
22
<%= render "cards/display/previews", cards: cards, draggable: draggable %>
33
</div>

app/views/boards/columns/closeds/show.html.erb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
<%= render "boards/columns/list", cards: @page.records, draggable: true %>
1818
<% end %>
1919
<% else %>
20-
<div class="cards__list">
21-
<div class="card blank-slate blank-slate--card">
22-
<p class="txt-align-center">Drag cards here</p>
23-
<p class="txt-align-center blank-slate-for-grid">Nothing here</p>
24-
</div>
25-
</div>
20+
<%= render "boards/columns/empty_placeholder" %>
2621
<% end %>
2722
<% end %>
2823
</section>

app/views/boards/columns/not_nows/show.html.erb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
<%= render "boards/columns/list", cards: @page.records, draggable: true %>
1818
<% end %>
1919
<% else %>
20-
<div class="cards__list">
21-
<div class="card blank-slate blank-slate--card">
22-
<p class="txt-align-center">Drag cards here</p>
23-
<p class="txt-align-center blank-slate-for-grid">Nothing here</p>
24-
</div>
25-
</div>
20+
<%= render "boards/columns/empty_placeholder" %>
2621
<% end %>
2722
<% end %>
2823
</section>

app/views/boards/columns/show.html.erb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
<%= render "boards/columns/list", cards: @page.records, draggable: true %>
1818
<% end %>
1919
<% else %>
20-
<div class="cards__list">
21-
<div class="card blank-slate blank-slate--card">
22-
<p class="txt-align-center">Drag cards here</p>
23-
<p class="txt-align-center blank-slate-for-grid">Nothing here</p>
24-
</div>
25-
</div>
20+
<%= render "boards/columns/empty_placeholder" %>
2621
<% end %>
2722
<% end %>
2823
</section>

0 commit comments

Comments
 (0)