diff --git a/app/assets/images/favicon.png b/app/assets/images/favicon.png index c85c37f..fb324e9 100644 Binary files a/app/assets/images/favicon.png and b/app/assets/images/favicon.png differ diff --git a/app/assets/stylesheets/currently_hacking.css b/app/assets/stylesheets/currently_hacking.css index 21ab55a..3cb0e4e 100644 --- a/app/assets/stylesheets/currently_hacking.css +++ b/app/assets/stylesheets/currently_hacking.css @@ -34,7 +34,7 @@ width: 8px; height: 8px; border-radius: 50%; - background-color: var(--primary-color); + background-color: #4caf50; display: inline-block; margin-right: 0.2em; animation: pulse 2s infinite; @@ -100,4 +100,4 @@ .currently-hacking-header { color: white; } -} \ No newline at end of file +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de27999..6653306 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,6 +21,14 @@ module ApplicationHelper country_code.tr("A-Z", "\u{1F1E6}-\u{1F1FF}") end + # infer country from timezone + def timezone_to_country(timezone) + return null unless timezone.present? + tz = ActiveSupport::TimeZone[timezone] + return null unless tz && tz.tzinfo.respond_to?(:country_code) + tz.tzinfo.country_code || null + end + def timezone_difference_in_seconds(timezone1, timezone2) return 0 if timezone1 == timezone2 diff --git a/app/javascript/controllers/trust_level_controller.js b/app/javascript/controllers/trust_level_controller.js index 6ae7ae9..91615c2 100644 --- a/app/javascript/controllers/trust_level_controller.js +++ b/app/javascript/controllers/trust_level_controller.js @@ -1,57 +1,62 @@ -import { Controller } from "@hotwired/stimulus" +import { Controller } from "@hotwired/stimulus"; export default class extends Controller { - static targets = ["select"] + static targets = ["select"]; connect() { - this.selectTarget.addEventListener('change', this.handleChange.bind(this)) + this.selectTarget.addEventListener("change", this.handleChange.bind(this)); } async handleChange(event) { - const userId = event.target.dataset.userId - const trustLevel = event.target.value + const userId = event.target.dataset.userId; + const trustLevel = event.target.value; if (!userId) { - console.error('No user ID found in dataset') - event.target.value = event.target.dataset.currentTrustLevel - alert('Error: No user ID found. Please try again.') - return + console.error("No user ID found in dataset"); + event.target.value = event.target.dataset.currentTrustLevel; + alert("Error: No user ID found. Please try again."); + return; } try { - console.log('Updating trust level for user:', userId, 'to:', trustLevel) - const url = new URL(`/users/${userId}/update_trust_level`, window.location.origin) + console.log("Updating trust level for user:", userId, "to:", trustLevel); + const url = new URL( + `/users/${userId}/update_trust_level`, + window.location.origin + ); const response = await fetch(url, { - method: 'PATCH', + method: "PATCH", headers: { - 'Content-Type': 'application/json', - 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content + "Content-Type": "application/json", + "X-CSRF-Token": document.querySelector('meta[name="csrf-token"]') + .content, }, - body: JSON.stringify({ trust_level: trustLevel }) - }) + body: JSON.stringify({ trust_level: trustLevel }), + }); if (!response.ok) { - throw new Error(`Failed to update trust level: ${response.status} ${response.statusText}`) + throw new Error( + `Failed to update trust level: ${response.status} ${response.statusText}` + ); } // Update the current trust level in the dataset - event.target.dataset.currentTrustLevel = trustLevel + event.target.dataset.currentTrustLevel = trustLevel; // Update the leaderboard entry's omitted class - const leaderboardEntry = event.target.closest('.leaderboard-entry') + const leaderboardEntry = event.target.closest(".leaderboard-entry"); if (leaderboardEntry) { - if (trustLevel === 'untrusted') { - leaderboardEntry.classList.add('omitted') + if (trustLevel === "red") { + leaderboardEntry.classList.add("omitted"); } else { - leaderboardEntry.classList.remove('omitted') + leaderboardEntry.classList.remove("omitted"); } } - } catch (error) { - console.error('Error updating trust level:', error) + console.error("Error updating trust level:", error); // Revert the select to its previous value - event.target.value = event.target.dataset.currentTrustLevel - alert('Failed to update trust level. Please try again.') + event.target.value = event.target.dataset.currentTrustLevel; + alert("Failed to update trust level. Please try again."); } } -} \ No newline at end of file +} diff --git a/app/models/user.rb b/app/models/user.rb index eccfc8b..3446e5e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,10 +16,17 @@ class User < ApplicationRecord end enum :trust_level, { - default: 0, - untrusted: 1, - trusted: 2 + yellow: 0, + red: 1, + green: 2 } + # yellow is unscored, red being convicted while green being trusted + # labels make it easier for display :okay-1: + + def set_trust(level) + update!(trust_level: level) + end + # ex: .set_trust(:green) or set_trust(1) setting it to red has_many :heartbeats has_many :email_addresses, dependent: :destroy diff --git a/app/views/docs/index.html.erb b/app/views/docs/index.html.erb index 4d0ffab..e38969d 100644 --- a/app/views/docs/index.html.erb +++ b/app/views/docs/index.html.erb @@ -22,9 +22,6 @@ Hackatime is totally free. Anyone can see the code. It's like WakaTime but free and open source.
- - -+
💡 Tip: The setup page does everything for you. No hard stuff to figure out!
+Hackatime works with any editor that has WakaTime. Just add the WakaTime plugin to your editor: @@ -55,7 +53,7 @@