Skip to content

added a profile update log#563

Open
WallerTrevor wants to merge 1 commit intoMitcheljager:masterfrom
WallerTrevor:Profile-Update-Log
Open

added a profile update log#563
WallerTrevor wants to merge 1 commit intoMitcheljager:masterfrom
WallerTrevor:Profile-Update-Log

Conversation

@WallerTrevor
Copy link
Contributor

added a update log to the profile page of the user.

Copy link
Owner

@Mitcheljager Mitcheljager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good effort, but unfortunately the AI made a real mess of this. When using AI to write your code, you should be careful to only push code that is actually useful and that you understand. As is this introduces an awful lot of ugliness that will need to be cleaned up before this can be merged.

@posts = @user.posts.select_overview_columns.public?.order("#{ allowed_sort_params.include?(params[:sort_posts]) ? params[:sort_posts] : "created_at" } DESC").page(params[:page])
@blocks = Block.where(user_id: @user.id, content_type: :profile).order(position: :asc, created_at: :asc)
@collections = @user.collections.includes(:posts).where("posts_count > ?", 0)
@updates = Revision.where(post_id: @user.posts.pluck(:id)).order(created_at: :desc).limit(50)
Copy link
Owner

@Mitcheljager Mitcheljager Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a few issues:

  • This will include posts that are private or in draft
  • This will load posts with n+1 because each revision will need to query it's post. It's not an n+1 query, but it is still quite inefficient
  • A limit of 50 is really quite high, that's a lot of revisions to load at once. Better might be to limit it to like 20 at a time with pagination

@@ -0,0 +1,88 @@
<%# app/views/blocks/profile/_update_log.html.erb %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know what file we're in, we really don't need that at the top

@@ -0,0 +1,88 @@
<%# app/views/blocks/profile/_update_log.html.erb %>
<div class="mt-1/1">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other profile tabs have a title at the top, it would be nice if this had that too

@@ -0,0 +1,88 @@
<%# app/views/blocks/profile/_update_log.html.erb %>
<div class="mt-1/1">
<% if @updates&.any? %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@updates can't be nil since .where will fall back to an empty collection if nothing is found, so the optional chaining here is irrelevant

<%# app/views/blocks/profile/_update_log.html.erb %>
<div class="mt-1/1">
<% if @updates&.any? %>
<%# Removed the 'standout' and 'p-0' classes to remove the box/border %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is odd, why do you want me to remove these classes?

<% end %>
</div>

<%# Keep your Styles and Scripts at the bottom as before %>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, don't keep it here. Javascript and css go into their own respective locations and files.

<%= render "blocks/profile/user_collections" %>
</div>
</div>
</div> No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a trailing space but no newline at the end of the file

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't include changes in package-lock, these seem to be accidental

Comment on lines +7 to +57
<%# Use 'feed__item' to ensure the site's global CSS handles the horizontal layout %>
<div class="feed__item <%= "border-top" unless index == 0 %> py-1/2">

<%# Left Column: Thumbnail and Code %>
<div class="feed__info">
<%= render "posts/thumbnail", post: revision.post %>
<%= render "posts/code", post: revision.post, item_class: "code feed__code" %>

<p class="feed__author">
by <%= link_to revision.post.user.clean_username, user_profile_path(revision.post.user) %>
</p>

<p class="feed__date">
<%= time_ago_in_words(revision.created_at) %> ago
</p>
</div>

<%# Right Column: Text Content (Left-Aligned by default in 'feed__item') %>
<div class="feed__content">
<h3 class="feed__title">
<%= link_to revision.post.title, post_path(revision.post.code) %>
</h3>

<% if revision.version.present? %>
<p class="feed__version">v<%= revision.version %></p>
<% end %>

<% if revision.description.blank? %>
<p class="mb-0 text-muted italic">
No update notes provided.
</p>
<% else %>
<h5 class="feed__update-notes mt-1/2 mb-1/8">Update notes</h5>
<div class="revision-description" data-role="expandable-content">
<%# 'item__description' ensures the markdown text aligns left %>
<div class="item__description mt-1/8 line-clamp-3" data-target="expandable-text">
<%= sanitized_markdown(revision.description) %>
</div>

<% if revision.description.length > 200 %>
<button class="text-primary text-xs font-bold mt-1/4 p-0 bg-transparent border-0 cursor-pointer hover-underline"
data-action="toggle-expand">
Read more
</button>
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is largely a copy of _feed_item.html.erb. Rather than copy pasting the same code, you can reuse that partial with <%= render "feed/feed_item", revision: revision %>. That way you prevent having to make changes in multiple places. Everything re-using the same file.


<script>
document.querySelectorAll('[data-action="toggle-expand"]').forEach(button => {
button.addEventListener('click', (e) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event won't get cleaned up when navigating which is problematic with Turbolinks. If you navigate away from this page the event listeners will stay in memory. If you navigate back to this page these event listeners will be attached again over top the other ones. Go back and forth a few times and each button will fire many times over, making it impossible to toggle the content here.

@posts = @user.posts.select_overview_columns.public?.order("#{ allowed_sort_params.include?(params[:sort_posts]) ? params[:sort_posts] : "created_at" } DESC").page(params[:page])
@blocks = Block.where(user_id: @user.id, content_type: :profile).order(position: :asc, created_at: :asc)
@collections = @user.collections.includes(:posts).where("posts_count > ?", 0)
@updates = Revision.where(post_id: @user.posts.pluck(:id)).order(created_at: :desc).limit(50)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I forgot to mention earlier, this will slow down all profiles even if the feed is never shown. This would be better to load async via a partial just like how tabs are loaded on post pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants