Skip to content

Commit

Permalink
add user directory
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 6, 2024
1 parent c4406a0 commit 4ba2aff
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Binary file added app/assets/images/default_banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# app/controllers/users_controller.rb
class UsersController < ApplicationController

def index
@users = User.all
end
end
42 changes: 42 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold text-white mb-6 text-center">User Directory</h1>

<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-8">
<% @users.each do |user| %>
<div class="bg-gray-800 rounded-lg p-6 text-center shadow-md">
<div class="mb-4">
<% avatar_path = "/avatars/#{user.username}_avatar#{File.extname(user.avatar || '')}" %>

<!-- Use local avatar if it exists, otherwise use the URL -->
<%= link_to user_links_path(user.username), target: "_blank" do %>
<% if File.exist?(Rails.root.join('public' + avatar_path)) %>
<%= image_tag avatar_path, alt: user.email, class: "rounded-full object-cover w-24 h-24 mx-auto" %>
<% elsif user.avatar.present? %>
<%= image_tag user.avatar, alt: user.email, class: "rounded-full object-cover w-24 h-24 mx-auto" %>
<% end %>
<% end %>
</div>

<!-- Link the username to the user's profile -->
<h2 class="text-xl font-bold text-lime-300">
<%= link_to user.full_name, user_links_path(user.username), target: "_blank", class: "hover:underline" %>
</h2>
<p class="text-gray-400">@<%= user.username %></p>

<% if user.parsed_tags.any? %>
<div class="flex flex-wrap justify-center mt-4 space-x-2 space-y-2">
<% user.parsed_tags.each do |tag| %>
<span class="bg-gray-700 text-white rounded px-2 py-1 text-xs"><%= tag %></span>
<% end %>
</div>
<% end %>

<% if user.description.present? %>
<div class="mt-4">
<p class="text-sm text-gray-300"><%= user.description %></p>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Rails.application.routes.draw do
# Static and more specific routes first

get 'analytics/index'

# Routes for users directory (static)
resources :users, only: [:index]

# Devise routes for user registration
devise_for :users, controllers: {
Expand All @@ -16,6 +18,7 @@
# Health check route
get 'up' => 'rails/health#show', as: :rails_health_check

# Routes for waiting lists
resources :waiting_lists, only: [:create]

# Root route
Expand All @@ -35,5 +38,5 @@
get '/:username/analytics', to: 'analytics#index', as: :user_analytics

# Dynamic user-specific routes must be last to avoid conflicts with static routes
get '/:username(/:theme)', to: 'links#user_links', as: :user_links, constraints: { theme: /retro|win95|win98/ }
get '/:username(/:theme)', to: 'links#user_links', as: :user_links, constraints: { username: /(?!users).*/, theme: /retro|win95|win98/ }
end

0 comments on commit 4ba2aff

Please sign in to comment.