Skip to content

Commit bb2ce54

Browse files
committed
feat(home/document): Add delete method for documents, trashcan icon and notice with disappearing notifications on success
1 parent efdbf8b commit bb2ce54

5 files changed

Lines changed: 49 additions & 16 deletions

File tree

app/controllers/documents_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ def update
4545

4646
redirect_to document_path(@document)
4747
end
48+
49+
def destroy
50+
@document = Document.find(params[:id])
51+
@document.destroy
52+
53+
redirect_to root_path, notice: "Document was successfully deleted!"
54+
end
4855
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
// Connects to data-controller="flash"
4+
export default class extends Controller {
5+
connect() {
6+
setTimeout(() => {
7+
this.element.style.opacity = "0";
8+
9+
setTimeout(() => {
10+
this.element.remove();
11+
}, 500);
12+
}, 3000);
13+
}
14+
}

app/views/home/index.html.erb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,34 @@
1717

1818
<% @documents.each do |document| %>
1919

20-
<a href="<%= document_path(document) %>" style="text-decoration: none; color: inherit; display: block; border: 1px solid #ddd; border-radius: 8px; overflow: hidden; transition: box-shadow 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.05);" onmouseover="this.style.boxShadow='0 4px 12px rgba(0,0,0,0.15)'" onmouseout="this.style.boxShadow='0 2px 5px rgba(0,0,0,0.05)'">
20+
<div style="position: relative; border: 1px solid #ddd; border-radius: 8px; overflow: hidden; background: white; transition: box-shadow 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.05);" onmouseover="this.style.boxShadow='0 4px 12px rgba(0,0,0,0.15)'" onmouseout="this.style.boxShadow='0 2px 5px rgba(0,0,0,0.05)'">
2121

22-
<div style="height: 160px; background-color: #f8f9fa; border-bottom: 1px solid #ddd; display: flex; align-items: center; justify-content: center; overflow: hidden;">
23-
<% if document.image_url.present? %>
24-
<img src="<%= document.image_url %>" style="width: 100%; height: 100%; object-fit: cover; object-position: top;" alt="Thumbnail">
25-
<% else %>
26-
<span style="font-size: 40px; color: #ccc;">📄</span>
27-
<% end %>
22+
<div style="position: absolute; top: 10px; right: 10px; z-index: 10;">
23+
<%= button_to "🗑️", document_path(document), method: :delete, data: { turbo_confirm: "Are you sure you want to permanently delete this document and all its pins?" }, style: "background: white; border: 1px solid #ff4d4f; color: #ff4d4f; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 5px rgba(0,0,0,0.2); font-size: 16px; transition: transform 0.1s;", onmouseover: "this.style.transform='scale(1.1)'", onmouseout: "this.style.transform='scale(1)'" %>
2824
</div>
2925

30-
<div style="padding: 15px; display: flex; align-items: center; gap: 10px;">
31-
<div style="background-color: #4285f4; color: white; width: 20px; height: 20px; display: flex; justify-content: center; align-items: center; border-radius: 3px; font-size: 12px;">
32-
26+
<a href="<%= document_path(document) %>" style="text-decoration: none; color: inherit; display: block;">
27+
28+
<div style="height: 160px; background-color: #f8f9fa; border-bottom: 1px solid #ddd; display: flex; align-items: center; justify-content: center; overflow: hidden;">
29+
<% if document.image_url.present? %>
30+
<img src="<%= document.image_url %>" style="width: 100%; height: 100%; object-fit: cover; object-position: top;" alt="Thumbnail">
31+
<% else %>
32+
<span style="font-size: 40px; color: #ccc;">📄</span>
33+
<% end %>
3334
</div>
34-
<div style="overflow: hidden;">
35-
<h3 style="margin: 0 0 4px 0; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"><%= document.title %></h3>
36-
<p style="margin: 0; font-size: 12px; color: #5f6368;">Opened <%= time_ago_in_words(document.updated_at) %> ago</p>
35+
36+
<div style="padding: 15px; display: flex; align-items: center; gap: 10px;">
37+
<div style="background-color: #4285f4; color: white; width: 20px; height: 20px; display: flex; justify-content: center; align-items: center; border-radius: 3px; font-size: 12px;">
38+
39+
</div>
40+
<div style="overflow: hidden;">
41+
<h3 style="margin: 0 0 4px 0; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"><%= document.title %></h3>
42+
<p style="margin: 0; font-size: 12px; color: #5f6368;">Opened <%= time_ago_in_words(document.updated_at) %> ago</p>
43+
</div>
3744
</div>
38-
</div>
3945

40-
</a>
46+
</a>
47+
</div>
4148

4249
<% end %>
4350

app/views/layouts/application.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
</head>
2424

2525
<body>
26+
<% if notice.present? %>
27+
<div data-controller="flash" style="position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background-color: #4caf50; color: white; padding: 12px 24px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 9999; font-family: sans-serif; font-weight: bold; transition: opacity 0.5s ease;"><%= notice %>
28+
</div>
29+
<% end %>
30+
2631
<%= yield %>
2732
</body>
2833
</html>

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
44
post "capture", to: "home#capture"
55

6-
resources :documents, only: [:create, :show, :update] do
6+
resources :documents, only: [:create, :show, :update, :destroy] do
77
resources :pins, only: [:create]
88
end
99

0 commit comments

Comments
 (0)