Show user's activity right on their profile screen

This commit is contained in:
Jason Zimdars
2025-05-22 16:18:28 -05:00
parent f105f17656
commit 7ee65608c9
5 changed files with 85 additions and 72 deletions
@@ -0,0 +1,12 @@
module UserTimelineScoped
extend ActiveSupport::Concern
included do
include FilterScoped
end
def show
@filter = Current.user.filters.new(creator_ids: [ @user.id ])
@day_timeline = Current.user.timeline_for(Time.current, filter: @filter)
end
end
+2 -3
View File
@@ -1,4 +1,5 @@
class UsersController < ApplicationController
include UserTimelineScoped
require_unauthenticated_access only: %i[ new create ]
before_action :set_user, only: %i[ show edit update destroy ]
@@ -6,6 +7,7 @@ class UsersController < ApplicationController
before_action :ensure_permission_to_change_user, only: %i[ update destroy ]
def index
@filters = Current.user.filters.all
@users = User.active
end
@@ -19,9 +21,6 @@ class UsersController < ApplicationController
redirect_to root_path
end
def show
end
def edit
end
+1 -1
View File
@@ -14,6 +14,6 @@
<% end %>
<% else %>
<div class="events__none">
<p class="margin-none">No more activity.</p>
<p class="margin-none">No more activity</p>
</div>
<% end %>
+43 -45
View File
@@ -6,55 +6,53 @@
</nav>
<% end %>
<%= turbo_frame_tag dom_id(@user) do %>
<div class="panel shadow center">
<div class="flex flex-column gap txt-medium">
<%= form_with model: @user, method: :patch, class: "flex flex-column gap", data: { controller: "form upload-preview" } do |form| %>
<div class="align-center center avatar__form gap">
<span class="btn btn--placeholder txt-small"></span>
<div class="panel shadow center">
<div class="flex flex-column gap txt-medium">
<%= form_with model: @user, method: :patch, class: "flex flex-column gap", data: { controller: "form upload-preview" } do |form| %>
<div class="align-center center avatar__form gap">
<span class="btn btn--placeholder txt-small"></span>
<label class="btn avatar input--file txt-xx-large center fill-white">
<%= image_tag user_avatar_path(@user), aria: { hidden: "true" }, class: "avatar", size: 128, data: { upload_preview_target: "image" } %>
<%= form.file_field :avatar, id: "file", class: "input", accept: "image/*",
data: { upload_preview_target: "input", action: "upload-preview#previewImage" } %>
<span class="for-screen-reader">Profile avatar for <%= @user.name %></span>
</label>
<label class="btn avatar input--file txt-xx-large center fill-white">
<%= image_tag user_avatar_path(@user), aria: { hidden: "true" }, class: "avatar", size: 128, data: { upload_preview_target: "image" } %>
<%= form.file_field :avatar, id: "file", class: "input", accept: "image/*",
data: { upload_preview_target: "input", action: "upload-preview#previewImage" } %>
<span class="for-screen-reader">Profile avatar for <%= @user.name %></span>
</label>
<% if @user.avatar.attached? %>
<%= tag.button type: :submit, form: "avatar-delete-form", class: "btn btn--negative txt-small", data: { turbo_confirm: "Are you sure you want to remove your avatar? This can't be undone." } do %>
<%= icon_tag "minus" %>
<span class="for-screen-reader">Delete avatar</span>
<% end %>
<% if @user.avatar.attached? %>
<%= tag.button type: :submit, form: "avatar-delete-form", class: "btn btn--negative txt-small", data: { turbo_confirm: "Are you sure you want to remove your avatar? This can't be undone." } do %>
<%= icon_tag "minus" %>
<span class="for-screen-reader">Delete avatar</span>
<% end %>
</div>
<% end %>
</div>
<div class="flex align-center gap">
<label class="flex align-center gap input input--actor">
<%= form.text_field :name, class: "input full-width", autocomplete: "name", placeholder: "Name", autofocus: true, required: true, data: { "1p-ignore": true, action: "keydown.esc@document->form#cancel" } %>
<%= icon_tag "person", class: "txt-large" %>
</label>
</div>
<div class="flex align-center gap">
<label class="flex align-center gap input input--actor">
<%= form.email_field :email_address, class: "input full-width", autocomplete: "username", placeholder: "Email address", required: true %>
<%= icon_tag "email", class: "txt-large" %>
</label>
</div>
<div class="flex align-center gap">
<label class="flex align-center gap input input--actor">
<%= form.password_field :password, class: "input full-width", autocomplete: "new-password", placeholder: "Password", required: false, maxlength: 72 %>
<%= icon_tag "password", class: "txt-large" %>
</label>
</div>
<button type="submit" id="log_in" class="btn btn--reversed center">
<%= icon_tag "check" %>
<span>Save changes</span>
</button>
<div class="flex align-center gap">
<label class="flex align-center gap input input--actor">
<%= form.text_field :name, class: "input full-width", autocomplete: "name", placeholder: "Name", autofocus: true, required: true, data: { "1p-ignore": true, action: "keydown.esc@document->form#cancel" } %>
<%= icon_tag "person", class: "txt-large" %>
</label>
</div>
<div class="flex align-center gap">
<label class="flex align-center gap input input--actor">
<%= form.email_field :email_address, class: "input full-width", autocomplete: "username", placeholder: "Email address", required: true %>
<%= icon_tag "email", class: "txt-large" %>
</label>
</div>
<div class="flex align-center gap">
<label class="flex align-center gap input input--actor">
<%= form.password_field :password, class: "input full-width", autocomplete: "new-password", placeholder: "Password", required: false, maxlength: 72 %>
<%= icon_tag "password", class: "txt-large" %>
</label>
</div>
<button type="submit" id="log_in" class="btn btn--reversed center">
<%= icon_tag "check" %>
<span>Save changes</span>
</button>
<%= link_to "Cancel and go back", user_path(@user), data: { form_target: "cancel", turbo_frame: "_top" }, hidden: true %>
<% end %>
<%= link_to "Cancel and go back", user_path(@user), data: { form_target: "cancel", turbo_frame: "_top" }, hidden: true %>
<% end %>
<%= form_with url: user_avatar_url(@user), method: :delete, id: "avatar-delete-form" %>
</div>
<%= form_with url: user_avatar_url(@user), method: :delete, id: "avatar-delete-form" %>
</div>
<% end %>
</div>
+27 -23
View File
@@ -5,7 +5,7 @@
<%= link_to_back %>
<% if Current.user == @user %>
<%= link_to edit_user_path(@user), class: "btn flex-item-justify-end", data: { turbo_frame: dom_id(@user) } do %>
<%= link_to edit_user_path(@user), class: "btn flex-item-justify-end" do %>
<%= icon_tag "pencil" %>
<span class="for-screen-reader">Edit</span>
<% end %>
@@ -13,32 +13,29 @@
</nav>
<% end %>
<%= turbo_frame_tag dom_id(@user) do %>
<div class="panel shadow center txt-align-center">
<div class="flex flex-column gap">
<div class="avatar txt-xx-large center fill-white">
<%= image_tag user_avatar_path(@user), alt: "Profile avatar for #{@user.name}", class: "avatar", size: 128 %>
</div>
<div class="panel shadow center txt-align-center margin-block-end-double">
<div class="flex flex-column gap">
<div class="avatar txt-xx-large center fill-white">
<%= image_tag user_avatar_path(@user), alt: "Profile avatar for #{@user.name}", class: "avatar", size: 128 %>
</div>
<div class="flex flex-column gap-half margin-block-end">
<h1 class="txt-x-large margin-none"><%= @user.name %></h1>
<div class="txt-medium">
<% if @user.active? %>
<%= mail_to @user.email_address %>
<% else %>
<%= @user.name %> is no longer on this account
<% end %>
</div>
</div>
<div class="flex-inline center justify-center flex-wrap gap">
<%= link_to "What #{ Current.user == @user ? "have you" : "#{ @user.first_name } has" } been up to?", events_path(creator_ids: [@user.id]), class: "btn", data: { turbo_frame: "_top" } %>
<%= link_to "Which cards are assigned to #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(assignee_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
<%= link_to "Which cards were added by #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(creator_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
<div class="flex flex-column gap-half margin-block-end">
<h1 class="txt-x-large margin-none"><%= @user.name %></h1>
<div class="txt-medium">
<% if @user.active? %>
<%= mail_to @user.email_address %>
<% else %>
<%= @user.name %> is no longer on this account
<% end %>
</div>
</div>
<div class="flex-inline center justify-center flex-wrap gap">
<%= link_to "Which cards are assigned to #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(assignee_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
<%= link_to "Which cards were added by #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(creator_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
</div>
</div>
<% end %>
</div>
<% if Current.user == @user %>
<div class="panel shadow center margin-block-double">
@@ -52,3 +49,10 @@
<% end %>
</div>
<% end %>
<h1 class="font-black txt-large margin-block-double"><%= "What #{ Current.user == @user ? "have you" : "has #{ @user.first_name }" } been up to?" %></h1>
<div class="events margin-block-double" id="activity">
<%= render "events/day", day_timeline: @day_timeline %>
<%= event_next_page_link(@day_timeline.next_day) %>
</div>