Skip to content

Commit 59ab6cc

Browse files
committed
feature/Reconfigure list select to work when initially filing a snippet
1 parent dde8a1f commit 59ab6cc

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

app/javascript/controllers/list_select_controller.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ export default class extends Controller {
1818
connect() {
1919
events(this)
2020
this.buttonTarget.disabled = true
21+
22+
if (!isNaN(this.selectedIdValue)) {
23+
const currentSelection = this.selectById(this.selectedIdValue)
24+
this.reassignCheckmark(currentSelection)
25+
}
2126
}
2227

2328
selectFolder(event) {
2429
const currentSelection = event.currentTarget
2530
const id = currentSelection.dataset.id
26-
const previousSelection = this.previouslySelected()
31+
const previousSelection = this.selectById(this.selectedIdValue)
2732

2833
if (currentSelection === previousSelection ) { return }
2934

@@ -33,21 +38,25 @@ export default class extends Controller {
3338
this.toggleButton()
3439
}
3540

36-
previouslySelected() {
41+
selectById(id) {
3742
return this.itemTargets.find(item => {
38-
return Number(item.dataset.id) === this.selectedIdValue
43+
return Number(item.dataset.id) === id
3944
})
4045
}
4146

4247
reassignClasses(previousSelection, currentSelection) {
43-
previousSelection.classList.remove('move-snippet--item-selected')
44-
previousSelection.classList.add('move-snippet--item')
48+
if (previousSelection) {
49+
previousSelection.classList.remove('move-snippet--item-selected')
50+
previousSelection.classList.add('move-snippet--item')
51+
}
52+
4553
currentSelection.classList.remove('move-snippet--item')
4654
currentSelection.classList.add('move-snippet--item-selected')
4755
}
4856

4957
reassignCheckmark(currentSelection) {
5058
const checkmark = this.checkmarkTarget
59+
checkmark.classList.remove('hidden')
5160
const checkmarkClone = checkmark.cloneNode(true)
5261

5362
checkmark.remove()

app/views/modals/snippets/move.html.erb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
class="<%= folder.id == @current_folder_id ? 'move-snippet--item-selected' : 'move-snippet--item' %>"
1717
>
1818
<span><%= folder.name %></span>
19-
<% if folder.id == @current_folder_id %>
20-
<div data-list-select-target="checkmark">
21-
<%= render partial: 'shared/icons/check', locals: { height: 5, width: 5, color: 'text-gray-500' } %>
22-
</div>
23-
<% end %>
2419
</div>
2520
<% end %>
2621
</div>
@@ -35,4 +30,8 @@
3530
<%= @header %>
3631
</button>
3732
</div>
33+
34+
<div data-list-select-target="checkmark" class="hidden">
35+
<%= render partial: 'shared/icons/check', locals: { height: 5, width: 5, color: 'text-gray-500' } %>
36+
</div>
3837
</div>

0 commit comments

Comments
 (0)