Skip to content

Commit 93a4fcf

Browse files
committed
feature/Remove language tag and add folder tag
1 parent de7a5b3 commit 93a4fcf

File tree

7 files changed

+41
-8
lines changed

7 files changed

+41
-8
lines changed

app/assets/stylesheets/_sidebar.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
}
2020

2121
&--icon {
22-
22+
margin-left: 12px;
2323
}
2424

2525
&--name {
26-
margin-left: 18px;
26+
margin-left: 14px;
2727
}
2828

2929
&--item {

app/assets/stylesheets/folders.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@
100100
display: inline-block;
101101
}
102102

103+
.folder-tag {
104+
display: flex;
105+
align-items: center;
106+
font-size: 11px;
107+
background-color: $color-primary;
108+
padding: 2px 6px;
109+
border-radius: 4px;
110+
color: white;
111+
}
112+
103113
.date-tag {
104114
font-size: 11px;
105115
padding: 2px 0px;

app/assets/stylesheets/helpers.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
.no-margin-top { margin-top: 0px; }
3636
.margin-top { margin-top: 16px }
3737
.margin-top { margin-top: 16px }
38-
.margin-left { margin-left: 16px }
38+
.margin-left {
39+
margin-left: 16px;
40+
41+
&--tiny {
42+
margin-left: 4px;
43+
}
44+
}
3945
.margin-right { margin-right: 16px }
4046

4147
.text-center { text-align: center; }

app/controllers/snippets_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def index
99
@page_title = "Snippets"
1010
@user = User.find_by(id: params[:user_id]) || current_user
1111
@display_popover = true
12-
@snippets = @user.filed_snippets.includes(:user)
12+
@snippets = @user.filed_snippets.includes(:user, :folders)
1313

1414
# TODO: Extract this logic to model/service
1515
@snippets = @snippets.where('description ILIKE ?', "%#{params[:search]}%") if params[:search]

app/models/snippet.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class Snippet < ApplicationRecord
1010

1111
attr_accessor :folder_id
1212

13+
def folder_for_user(user)
14+
folders.find_by(user_id: user.id)
15+
end
16+
1317
# TODO: Don't call serializers from model - just instantiate in controller
1418
def serializable(current_user)
1519
SnippetSerializer.new(self, scope: current_user)

app/views/snippets/_snippet.html.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<% folder = snippet.folder_for_user(current_user) %>
2+
13
<div
24
id="<%= snippet.client_id %>"
35
data-controller="snippets"
@@ -10,7 +12,12 @@
1012
<div>
1113
<div style="display: flex; flex-direction: column;">
1214
<div style="display: flex; justify-content: flex-end; margin-bottom: 8px; align-items: center;">
13-
<span class="language-tag"><%= snippet.language %></span>
15+
<% if folder %>
16+
<div class="folder-tag">
17+
<img src="/icons/icons8-folder-white.svg" width="12">
18+
<span class="block margin-left--tiny"><%= folder.name %></span>
19+
</div>
20+
<% end%>
1421
<% if @display_popover %>
1522
<%= render partial: 'shared/popover_trigger', locals: { popover_path: popover_snippet_path(snippet) } %>
1623
<% end %>

app/views/snippets/_snippet_preview.html.erb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
<% folder = snippet.folder_for_user(current_user) %>
2+
13
<div
24
id="<%= snippet.client_id %>"
35
data-controller="snippets"
46
data-action="click->snippets#view_snippet"
57
data-snippet-url="<%= snippet_path(snippet) %>"
6-
class="card--container card--container-padding snippet--container-preview"
7-
>
8+
class="card--container card--container-padding snippet--container-preview">
89
<div class="snippet--author-wrapper">
910
<%= render partial: 'users/preview', locals: { user: snippet.user, resource: snippet } %>
1011
<div>
1112
<div style="display: flex; flex-direction: column;">
1213
<div style="display: flex; justify-content: flex-end; margin-bottom: 8px; align-items: center;">
13-
<span class="language-tag"><%= snippet.language %></span>
14+
<% if folder %>
15+
<div class="folder-tag">
16+
<img src="/icons/icons8-folder-white.svg" width="12">
17+
<span class="block margin-left--tiny"><%= folder.name %></span>
18+
</div>
19+
<% end%>
1420
<% if @display_popover %>
1521
<%= render partial: 'shared/popover_trigger', locals: { popover_path: popover_snippet_path(snippet) } %>
1622
<% end %>

0 commit comments

Comments
 (0)