diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index 4e1ec9a..3cb26ae 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -45,15 +45,17 @@ def destroy def user_links @user = User.find_by(username: params[:username]) return redirect_to root_path, alert: "User not found" if @user.nil? - - @links = @user.links + + @links = @user.links.where(hidden: false, visible: true) + @hidden_links = @user.links.where(hidden: true) @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}" - + Rails.logger.debug "Hidden Links: #{@hidden_links.inspect}" + # Render the appropriate template based on the theme case @theme when 'retro' @@ -84,7 +86,7 @@ def track_click private def link_params - params.require(:link).permit(:url, :title, :description, :position, :icon, :visible, :pinned) + params.require(:link).permit(:url, :title, :description, :position, :icon, :visible, :pinned, :hidden) end def set_theme diff --git a/app/javascript/entrypoints/application.js b/app/javascript/entrypoints/application.js index 364fb35..df76145 100644 --- a/app/javascript/entrypoints/application.js +++ b/app/javascript/entrypoints/application.js @@ -5,7 +5,6 @@ import "flowbite"; Rails.start(); console.log('Vite ⚡️ Rails'); -console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails'); // Linkarooie console messages console.log('Linkarooie 🌐 Your ultimate link management tool'); @@ -79,3 +78,26 @@ console.log('© 2024 Linkarooie. All rights reserved.'); }); } })(); + +document.addEventListener('DOMContentLoaded', () => { + const pathname = window.location.pathname; + const userPagePattern = /^\/[^/]+$/; // Matches any path with a single segment after the root + + if (userPagePattern.test(pathname)) { + const hiddenLinksData = document.getElementById('hidden-links-data'); + + if (hiddenLinksData) { + const hiddenLinks = JSON.parse(hiddenLinksData.dataset.hiddenLinks); + + if (hiddenLinks.length > 0) { + console.group('Hidden Links'); + hiddenLinks.forEach((link) => { + console.log(`Title: ${link.title}, URL: ${link.url}`); + }); + console.groupEnd(); + } else { + console.log('No hidden links to display.'); + } + } + } + }); \ No newline at end of file diff --git a/app/models/link.rb b/app/models/link.rb index 5191d76..edfd0e0 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -5,4 +5,5 @@ class Link < ApplicationRecord scope :visible, -> { where(visible: true) } scope :pinned, -> { where(pinned: true) } + scope :hidden, -> { where(hidden: true) } end \ No newline at end of file diff --git a/app/views/links/_form.html.erb b/app/views/links/_form.html.erb index b072e97..6944b83 100644 --- a/app/views/links/_form.html.erb +++ b/app/views/links/_form.html.erb @@ -1,8 +1,8 @@ -<%= form_with(model: link, local: true) do |form| %> +<%= form_with(model: link, local: true, class: "max-w-md mx-auto p-4 bg-gray-800 rounded-lg shadow-md") do |form| %> <% if link.errors.any? %> -
-

<%= pluralize(link.errors.count, 'error') %> prohibited this link from being saved:

-
+ + + <% if @achievements.present? %>

Achievements

diff --git a/db/migrate/20240901041708_add_hidden_to_links.rb b/db/migrate/20240901041708_add_hidden_to_links.rb new file mode 100644 index 0000000..051bffb --- /dev/null +++ b/db/migrate/20240901041708_add_hidden_to_links.rb @@ -0,0 +1,5 @@ +class AddHiddenToLinks < ActiveRecord::Migration[7.1] + def change + add_column :links, :hidden, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index a753cb8..ee81a33 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_08_24_060759) do +ActiveRecord::Schema[7.1].define(version: 2024_09_01_041708) do create_table "achievement_views", force: :cascade do |t| t.integer "achievement_id", null: false t.integer "user_id", null: false @@ -102,6 +102,7 @@ t.string "icon" t.boolean "visible", default: true t.boolean "pinned", default: false + t.boolean "hidden", default: false t.index ["user_id"], name: "index_links_on_user_id" end