diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index efc2526..ff7ab97 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -1,3 +1,23 @@ // Place all the styles related to the Users controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ + +.form-tag { + display: flex; + width: 100%; +} +.text-field { + flex: 5; + margin: 3px; +} +.submit-button { + flex: 1; + margin: 3px; +} +.stack { + display: flex; + flex-direction: column; +} +.stack > * + * { + margin-top: .5rem; +} diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6e18a4c..ccd077b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -44,8 +44,11 @@ def index end def search - @users = User.search(params[:search]).where.not(id: current_user.id) - @users_to_add = @users.reject do |user| + other_users = User.search(params[:search]).where.not(id: current_user.id) + @users_to_add = other_users.reject do |user| + current_user.sent_contact_request?(user) + end + @users = other_users.select do |user| current_user.sent_contact_request?(user) end end diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index 2acae9d..581301a 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -26,4 +26,4 @@ -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/users/search.html.erb b/app/views/users/search.html.erb index 8a618e0..aac107e 100644 --- a/app/views/users/search.html.erb +++ b/app/views/users/search.html.erb @@ -1,42 +1,18 @@ -
-

<%= I18n.t('user.lists') %>

+<%= stylesheet_link_tag 'users', media: 'all', 'data-turbolinks-track': 'reload' %> - <%# https://getbootstrap.com/docs/5.0/layout/grid/#auto-layout-columns %> +
+ <%= form_tag(search_users_path, method: "get", class: "form-tag justify-content-between") do %> + <%= text_field_tag :search, params[:search] , placeholder: I18n.t('user.search.placeholder'), class: "text-field form-control my-2 my-sm-0"%> + <%= submit_tag I18n.t('user.search.index') , class: "submit-button btn btn-outline-secondary my-2 my-sm-0"%> + <% end %> + <% @users.each do |user| %> + <%= render partial: 'users/card', locals: { user: user, mode: :overview } %> + <% end %> -
-
- <%= form_tag(search_users_path, method: "get") do %> - <%= label_tag(:search, I18n.t('user.search.for') ) %> - <%= text_field_tag :search, params[:search] %> - <%= submit_tag I18n.t('user.search.index') %> - <% end %> -
-
+ <% @users_to_add.each do |user| %> + <%= render partial: 'users/card', locals: { user: user, mode: :add } %> + <% end %> - - - - - - - - - - - - <% @users.each do |user| %> - - - - - - <% if @users_to_add.include? user %> - - <% end %> - - <% end %> - - -
<%= I18n.t('user.attributes.username') %><%= I18n.t('user.attributes.firstname')%><%= I18n.t('user.attributes.lastname')%><%= I18n.t('user.attributes.email')%>
<%= user.username%><%= user.firstname%><%= user.lastname%><%= user.email %><%= button_to '+', user_contact_requests_path(user), method: :post, id: user.id %>
+ diff --git a/config/locales/en.yml b/config/locales/en.yml index 8c71b47..ddbf908 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -71,6 +71,7 @@ en: search: index: 'Search' for: 'Search for:' + placeholder: 'Username, email, ...' contact_request: approved: 'Contact request approved' denied: 'Contact request denied'