Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hidden links #73

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion app/javascript/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.');
}
}
}
});
1 change: 1 addition & 0 deletions app/models/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class Link < ApplicationRecord

scope :visible, -> { where(visible: true) }
scope :pinned, -> { where(pinned: true) }
scope :hidden, -> { where(hidden: true) }
end
63 changes: 36 additions & 27 deletions app/views/links/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
<%= 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? %>
<div id="error_explanation" class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4">
<h2 class="font-bold"><%= pluralize(link.errors.count, 'error') %> prohibited this link from being saved:</h2>
<ul>
<div id="error_explanation" class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4 rounded">
<h2 class="font-bold mb-2"><%= pluralize(link.errors.count, 'error') %> prohibited this link from being saved:</h2>
<ul class="list-disc pl-5">
<% link.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="mb-4">
<%= form.label :title, class: 'block text-lime-200 mb-2' %>
<%= form.text_field :title, class: 'block w-full px-3 py-2 text-black' %>
<div class="mb-6">
<%= form.label :title, class: 'block text-lime-200 font-semibold mb-2' %>
<%= form.text_field :title, class: 'block w-full px-4 py-2 border border-gray-700 rounded bg-gray-900 text-white focus:outline-none focus:border-lime-500' %>
</div>

<div class="mb-4">
<%= form.label :url, class: 'block text-lime-200 mb-2' %>
<%= form.text_field :url, class: 'block w-full px-3 py-2 text-black' %>
<div class="mb-6">
<%= form.label :url, class: 'block text-lime-200 font-semibold mb-2' %>
<%= form.text_field :url, class: 'block w-full px-4 py-2 border border-gray-700 rounded bg-gray-900 text-white focus:outline-none focus:border-lime-500' %>
</div>

<div class="mb-4">
<%= form.label :description, class: 'block text-lime-200 mb-2' %>
<%= form.text_area :description, class: 'block w-full px-3 py-2 text-black' %>
<div class="mb-6">
<%= form.label :description, class: 'block text-lime-200 font-semibold mb-2' %>
<%= form.text_area :description, rows: 3, class: 'block w-full px-4 py-2 border border-gray-700 rounded bg-gray-900 text-white focus:outline-none focus:border-lime-500' %>
</div>

<div class="mb-4">
<%= form.label :icon, class: 'block text-lime-200 mb-2' %>
<%= form.text_field :icon, class: 'block w-full px-3 py-2 text-black' %>
<div class="mb-6">
<%= form.label :icon, class: 'block text-lime-200 font-semibold mb-2' %>
<%= form.text_field :icon, class: 'block w-full px-4 py-2 border border-gray-700 rounded bg-gray-900 text-white focus:outline-none focus:border-lime-500' %>
<p class="text-gray-400 mt-2 text-sm">
Find icons at <a href="https://fontawesome.com/v6/icons" target="_blank" class="text-lime-300 underline">Font Awesome</a>.
Use the class name (e.g., <code>fas fa-home</code>) in the icon field.
</p>
</div>

<div class="mb-4">
<%= form.label :position, class: 'block text-lime-200 mb-2' %>
<%= form.number_field :position, class: 'block w-full px-3 py-2 text-black' %>
<div class="mb-6">
<%= form.label :position, class: 'block text-lime-200 font-semibold mb-2' %>
<%= form.number_field :position, class: 'block w-full px-4 py-2 border border-gray-700 rounded bg-gray-900 text-white focus:outline-none focus:border-lime-500' %>
</div>

<div class="mb-4">
<%= form.label :visible, class: 'block text-lime-200 mb-2' %>
<%= form.check_box :visible, class: 'text-black' %>
<div class="mb-6 flex items-center">
<%= form.check_box :visible, class: 'mr-2' %>
<%= form.label :visible, class: 'text-lime-200 font-semibold' %>
</div>

<div class="mb-4">
<%= form.label :pinned, class: 'block text-lime-200 mb-2' %>
<%= form.check_box :pinned, class: 'text-black' %>
<div class="mb-6 flex items-center">
<%= form.check_box :pinned, class: 'mr-2' %>
<%= form.label :pinned, class: 'text-lime-200 font-semibold' %>
</div>

<div class="actions">
<%= form.submit 'Save', class: 'bg-lime-500 hover:bg-lime-700 text-white font-bold py-2 px-4 rounded' %>
<div class="mb-6 flex items-center">
<%= form.check_box :hidden, class: 'mr-2' %>
<%= form.label :hidden, class: 'text-lime-200 font-semibold' %>
</div>

<div class="actions text-center">
<%= form.submit 'Save', class: 'bg-lime-500 hover:bg-lime-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out' %>
</div>
<% end %>
3 changes: 3 additions & 0 deletions app/views/links/user_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
</ul>
</div>

<!-- Hidden data for JavaScript to access -->
<div id="hidden-links-data" style="display: none;" data-hidden-links="<%= @hidden_links.to_json %>"></div>

<% if @achievements.present? %>
<div class="achievements-section max-w-4xl mx-auto mt-12 text-center">
<h2 class="text-2xl font-bold pt-2 pb-2 text-white">Achievements</h2>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240901041708_add_hidden_to_links.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHiddenToLinks < ActiveRecord::Migration[7.1]
def change
add_column :links, :hidden, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading