Skip to content

Commit 525f1bf

Browse files
committed
refactor/Use alerts namespace for alerts
1 parent fadb350 commit 525f1bf

25 files changed

+126
-133
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Alerts::CommentsController < AlertsController
2+
DELETE_CONFIRM_TEXT = "Are you sure you want to delete this comment? You won't be able to undo this.".freeze
3+
4+
def delete
5+
@comment = current_user.comments.find(params[:id])
6+
@header = 'Delete Comment'
7+
@message = DELETE_CONFIRM_TEXT
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Alerts::FoldersController < AlertsController
2+
DELETE_CONFIRM_TEXT = "Are you sure you want to delete this folder? You won't be able to undo this.".freeze
3+
4+
def delete
5+
@folder = current_user.folders.find(params[:id])
6+
@header = 'Delete Folder'
7+
@message = DELETE_CONFIRM_TEXT
8+
end
9+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Alerts::SnippetsController < AlertsController
2+
UNFILE_CONFIRM_TEXT = "Are you sure you want to unfile this snippet? It will be removed from your collection.".freeze
3+
DELETE_CONFIRM_TEXT = "Are you sure you want to delete this snippet? You won't be able to undo this.".freeze
4+
5+
def unfile
6+
@snippet = current_user.filed_snippets.find(params[:id])
7+
@header = 'Unfile Snippet'
8+
@message = UNFILE_CONFIRM_TEXT
9+
end
10+
11+
def delete
12+
@snippet = current_user.snippets.find(params[:id])
13+
@header = 'Delete Snippet'
14+
@message = DELETE_CONFIRM_TEXT
15+
end
16+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AlertsController < ApplicationController
2+
skip_before_action :assign_users_for_connect
3+
4+
layout 'alert'
5+
end

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def assign_users_for_connect
2525
if user_signed_in?
2626
@users_for_connect = User.where.not(id: current_user.following.pluck(:id) << current_user.id).limit(5)
2727
else
28-
@users_for_connect = User.limit(5)
28+
@users_for_connect = User.order(updated_at: :desc).limit(5)
2929
end
3030
end
3131

app/controllers/comments_controller.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ class CommentsController < ApplicationController
22
before_action :authenticate_user!
33
before_action :set_comment, only: :destroy
44

5-
DELETE_CONFIRM_TEXT = "Are you sure you want to delete this comment? You won't be able to undo this.".freeze
6-
75
def create
86
@snippet = Snippet.find(params[:snippet_id])
97
@comment = @snippet.comments.new(comment_params)
@@ -34,18 +32,6 @@ def popover
3432
render partial: 'shared/popover', layout: false
3533
end
3634

37-
def delete_alert
38-
@comment = current_user.comments.find(params[:id])
39-
@title = 'Delete Comment'
40-
@message = DELETE_CONFIRM_TEXT
41-
@confirm_word = 'DELETE'
42-
@toast_message = 'Comment deleted!'
43-
@confirm_path = comment_path(@comment)
44-
@resource_id = @comment.client_id
45-
46-
render 'shared/delete_alert', layout: false
47-
end
48-
4935
private
5036

5137
def set_comment

app/controllers/folders_controller.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class FoldersController < ApplicationController
22
MINIMUM_FOLDERS = 1.freeze
3-
DELETE_CONFIRM_TEXT = "Are you sure you want to delete this folder? You won't be able to undo this.".freeze
43

54
before_action :authenticate_user!
65
before_action :set_folder, only: %i(show edit update destroy)
@@ -14,18 +13,6 @@ def popover
1413
render partial: 'shared/popover', layout: false
1514
end
1615

17-
def delete_alert
18-
@folder = current_user.folders.find(params[:id])
19-
@title = 'Delete Folder'
20-
@message = DELETE_CONFIRM_TEXT
21-
@confirm_word = 'DELETE'
22-
@confirm_path = folder_path(@folder, redirect_url: folders_path)
23-
@resource_id = @folder.client_id
24-
@method = :delete
25-
26-
render 'shared/delete_alert', layout: false
27-
end
28-
2916
def index
3017
@page_title = 'Folders'
3118

app/controllers/snippets_controller.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
class SnippetsController < ApplicationController
22
before_action :authenticate_user!, except: :show
33

4-
DELETE_CONFIRM_TEXT = "Are you sure you want to delete this snippet? You won't be able to undo this.".freeze
5-
UNFILE_CONFIRM_TEXT = "Are you sure you want to unfile this snippet? It will be removed from your collection.".freeze
6-
74
def index
85
@page_title = "Snippets"
96
@user = User.find_by(id: params[:user_id]) || current_user
@@ -73,18 +70,6 @@ def file
7370
end
7471
end
7572

76-
def delete_alert
77-
@snippet = current_user.snippets.find(params[:id])
78-
@title = 'Delete Snippet'
79-
@message = DELETE_CONFIRM_TEXT
80-
@confirm_word = 'DELETE'
81-
@toast_message = 'Snippet deleted!'
82-
@confirm_path = snippet_path(@snippet)
83-
@resource_id = @snippet.client_id
84-
85-
render 'shared/delete_alert', layout: false
86-
end
87-
8873
def unfile_alert
8974
@snippet = current_user.filed_snippets.find(params[:id])
9075
@title = 'Unfile Snippet'

app/javascript/controllers/alert_controller.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import axios from 'axios';
33

44
export default class extends Controller {
55
static targets = ["alert", "confirm", "body", "header"];
6-
7-
connect() {
8-
this.element[this.identifier] = this
9-
}
6+
static values = { url: String };
107

11-
present(url) {
12-
axios.get(url)
8+
present(event) {
9+
event.preventDefault();
10+
event.stopPropagation();
11+
console.log(this.urlValue)
12+
axios.get(this.urlValue)
1313
.then(res => {
14-
this.bodyTarget.insertAdjacentHTML('afterbegin', res.data);
15-
this.alertTarget.classList.remove('hidden')
14+
console.log(res)
15+
document.body.insertAdjacentHTML('afterbegin', res.data);
1616
})
1717
.catch(console.error)
1818
}

app/javascript/controllers/modal_controller.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,21 @@ import axios from 'axios';
44
export default class extends Controller {
55
static targets = ["modal", "header", "body"];
66
static values = { url: String }
7-
8-
connect() {
9-
this.element[this.identifier] = this
10-
}
117

128
initialize() {
139
const csrfToken = document.querySelector("meta[name=csrf-token]").content
1410
axios.defaults.headers.common['X-CSRF-Token'] = csrfToken
1511
}
1612

1713
present(event) {
18-
console.log('click', this.urlValue)
1914
event.preventDefault();
2015
event.stopPropagation();
2116

2217
axios.get(this.urlValue)
2318
.then(res => {
24-
console.log(res)
2519
this.close();
20+
2621
document.body.insertAdjacentHTML('afterbegin', res.data);
27-
// this.bodyTarget.insertAdjacentHTML('afterbegin', res.data);
28-
// this.modalTarget.classList.remove('hidden')
2922
})
3023
.catch(console.error)
3124
}

0 commit comments

Comments
 (0)