Skip to content

Commit

Permalink
add theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Aug 24, 2024
1 parent cf1c5fd commit 9acfc1f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
29 changes: 26 additions & 3 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class LinksController < ApplicationController
before_action :authenticate_user!, except: [:index, :show, :user_links, :track_click]
before_action :set_theme, only: [:user_links] # Add this line

def index
@links = Link.order(:position)
Expand Down Expand Up @@ -43,10 +44,27 @@ def destroy

def user_links
@user = User.find_by(username: params[:username])
@links = @user.links.where(visible: true).order(:position)
@pinned_links = @user.links.where(visible: true, pinned: true).order(:position)
@achievements = @user.achievements.order(date: :desc)
return redirect_to root_path, alert: "User not found" if @user.nil?

@links = @user.links
@pinned_links = @user.links.where(pinned: true)
@achievements = @user.achievements
@user.tags = JSON.parse(@user.tags) if @user.tags.is_a?(String)

# Add debugging
Rails.logger.debug "Theme: #{@theme.inspect}"

# Render the appropriate template based on the theme
case @theme
when 'retro'
render 'user_links_retro'
when 'win95'
render 'user_links_win95'
when 'win98'
render 'user_links_win98'
else
render 'user_links'
end
end

def track_click
Expand All @@ -68,4 +86,9 @@ def track_click
def link_params
params.require(:link).permit(:url, :title, :description, :position, :icon, :visible, :pinned)
end

def set_theme
# Determine the theme either from a query parameter or route segment
@theme = params[:theme] || 'default'
end
end
19 changes: 13 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
Rails.application.routes.draw do
get 'analytics/index'
# Use the custom registrations controller in all environments

# Devise routes for user registration
devise_for :users, controllers: {
registrations: 'users/registrations'
}

# Routes for links with standard RESTful actions
resources :links do
member do
get :track_click
end
end

# Sidekiq monitoring
require 'sidekiq/web'
require 'sidekiq-scheduler/web'
mount Sidekiq::Web => '/sidekiq'

# Other routes
# Custom routes for user-specific views and analytics
get '/:username/analytics', to: 'analytics#index', as: :user_analytics
get "up" => "rails/health#show", as: :rails_health_check
get '/:username(/:theme)', to: 'links#user_links', as: :user_links, constraints: { theme: /retro|win95|win98/ }

# Health check route
get 'up' => 'rails/health#show', as: :rails_health_check

# Root route
root to: 'pages#home'
resources :links, only: [:index, :show, :new, :create, :edit, :update, :destroy]

# Additional resources
resources :achievements, only: [:index, :show, :new, :create, :edit, :update, :destroy]
get '/:username', to: 'links#user_links', as: 'user_links'
end

0 comments on commit 9acfc1f

Please sign in to comment.