diff --git a/app/controllers/shared/trips_controller.rb b/app/controllers/shared/trips_controller.rb index 9b583295..cc3f8c62 100644 --- a/app/controllers/shared/trips_controller.rb +++ b/app/controllers/shared/trips_controller.rb @@ -7,11 +7,8 @@ class Shared::TripsController < ApplicationController redirect_to root_path, alert: 'Shared trip not found or no longer available' and return unless @trip&.public_accessible? @user = @trip.user - @is_public_view = true - @coordinates = @trip.path.present? ? extract_coordinates : [] - @photo_previews = @trip.share_photos? ? fetch_photo_previews : [] - - render 'trips/public_show' + @coordinates = extract_coordinates + @photo_previews = fetch_photo_previews end private @@ -24,6 +21,8 @@ class Shared::TripsController < ApplicationController end def fetch_photo_previews + return [] unless @trip.share_photos? + Rails.cache.fetch("trip_photos_#{@trip.id}", expires_in: 1.day) do @trip.photo_previews end diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb index 2818b4af..d60b7ef9 100644 --- a/app/controllers/trips_controller.rb +++ b/app/controllers/trips_controller.rb @@ -39,8 +39,8 @@ class TripsController < ApplicationController end def update - # Handle sharing settings update (JSON response) - update_sharing and return if params[:sharing] + # Handle sharing settings update + handle_sharing_update if params[:sharing] # Handle regular trip update if @trip.update(trip_params) @@ -68,38 +68,18 @@ class TripsController < ApplicationController ).map { [_1.to_f, _2.to_f, _3.to_s, _4.to_s, _5.to_s, _6.to_s, _7.to_s, _8.to_s] } end - def update_sharing + def handle_sharing_update if params[:sharing][:enabled] == '1' sharing_options = { - expiration: params[:sharing][:expiration] || '24h' + expiration: params[:sharing][:expiration] || '24h', + share_notes: params[:sharing][:share_notes] == '1', + share_photos: params[:sharing][:share_photos] == '1' } - # Add optional sharing settings - sharing_options[:share_notes] = params[:sharing][:share_notes] == '1' - sharing_options[:share_photos] = params[:sharing][:share_photos] == '1' - @trip.enable_sharing!(**sharing_options) - sharing_url = shared_trip_url(@trip.sharing_uuid) - - render json: { - success: true, - sharing_url: sharing_url, - message: 'Sharing enabled successfully' - } else @trip.disable_sharing! - - render json: { - success: true, - message: 'Sharing disabled successfully' - } end - rescue StandardError => e - render json: { - success: false, - message: 'Failed to update sharing settings', - error: e.message - }, status: :unprocessable_content end def trip_params diff --git a/app/javascript/controllers/public_trip_map_controller.js b/app/javascript/controllers/shared/trip_map_controller.js similarity index 97% rename from app/javascript/controllers/public_trip_map_controller.js rename to app/javascript/controllers/shared/trip_map_controller.js index 49f0b27f..f1a3f61a 100644 --- a/app/javascript/controllers/public_trip_map_controller.js +++ b/app/javascript/controllers/shared/trip_map_controller.js @@ -1,5 +1,5 @@ import L from "leaflet"; -import BaseController from "./base_controller"; +import BaseController from "../base_controller"; export default class extends BaseController { static values = { diff --git a/app/views/trips/public_show.html.erb b/app/views/shared/trips/show.html.erb similarity index 95% rename from app/views/trips/public_show.html.erb rename to app/views/shared/trips/show.html.erb index 04d7620d..74acf17b 100644 --- a/app/views/trips/public_show.html.erb +++ b/app/views/shared/trips/show.html.erb @@ -54,9 +54,9 @@ <% if @coordinates.present? %>
+ data-controller="shared--trip-map" + data-shared--trip-map-coordinates-value="<%= @coordinates.to_json %>" + data-shared--trip-map-name-value="<%= @trip.name %>"> <% else %>