diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 27453c76..ae3d4fbc 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true class HomeController < ApplicationController + include ApplicationHelper + def index # redirect_to 'https://dawarich.app', allow_other_host: true and return unless SELF_HOSTED - redirect_to map_url if current_user + redirect_to preferred_map_path if current_user @points = current_user.points.without_raw_data if current_user end diff --git a/app/controllers/settings/maps_controller.rb b/app/controllers/settings/maps_controller.rb index 3cee8e0e..f4275f70 100644 --- a/app/controllers/settings/maps_controller.rb +++ b/app/controllers/settings/maps_controller.rb @@ -24,6 +24,6 @@ class Settings::MapsController < ApplicationController private def settings_params - params.require(:maps).permit(:name, :url, :distance_unit) + params.require(:maps).permit(:name, :url, :distance_unit, :preferred_version) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 970a549b..530dc2a7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -142,4 +142,11 @@ module ApplicationHelper ALLOW_EMAIL_PASSWORD_REGISTRATION end + + def preferred_map_path + return map_path unless user_signed_in? + + preferred_version = current_user.safe_settings.maps&.dig('preferred_version') + preferred_version == 'v2' ? maps_maplibre_path : map_path + end end diff --git a/app/views/settings/maps/index.html.erb b/app/views/settings/maps/index.html.erb index fa8ee555..00c1f63f 100644 --- a/app/views/settings/maps/index.html.erb +++ b/app/views/settings/maps/index.html.erb @@ -80,6 +80,23 @@ +
+ + Choose which map version to use by default. V1 uses Leaflet, V2 uses MapLibre with enhanced features. +

Map Preview

diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index e29ad920..fcf869a7 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -5,7 +5,7 @@
- <%= link_to 'Dawarichα'.html_safe, root_path, class: 'btn btn-ghost normal-case text-xl'%> + <%= link_to 'Dawarichα'.html_safe, (user_signed_in? ? preferred_map_path : root_path), class: 'btn btn-ghost normal-case text-xl'%>
<% if new_version_available? %> @@ -71,7 +71,7 @@