Skip to content

Commit c2bd6f8

Browse files
authored
Merge pull request #3 from yashc73080:development
Updated auth requirements
2 parents ce42ff4 + 06e8f61 commit c2bd6f8

8 files changed

Lines changed: 86 additions & 56 deletions

File tree

frontend/app/components/ChatInterface.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ export default function ChatInterface({ selectedLocations, onNewChat, onShowHist
215215
}
216216
}, [newChatTrigger]);
217217

218+
// Watch for valuable content to trigger sign-in prompt
219+
220+
218221
const loadMostRecentSession = async () => {
222+
if (!currentUser) return;
219223
try {
220224
const token = await currentUser.getIdToken();
221225
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/chat/sessions`, {
@@ -244,6 +248,7 @@ export default function ChatInterface({ selectedLocations, onNewChat, onShowHist
244248
}, [showHistory, currentUser]);
245249

246250
const fetchSessions = async () => {
251+
if (!currentUser) return;
247252
try {
248253
const token = await currentUser.getIdToken();
249254
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/chat/sessions`, {

frontend/app/components/ChatWidget.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ export default function ChatWidget() {
1616
const [newChatTrigger, setNewChatTrigger] = useState(0);
1717

1818
const toggleChat = () => {
19-
if (!userLoggedIn) {
20-
openLoginModal();
21-
return;
22-
}
2319
setIsChatOpen(!isChatOpen);
2420
// Sync mobile panel state
2521
setActivePanel(isChatOpen ? 'none' : 'chat');
@@ -55,23 +51,6 @@ export default function ChatWidget() {
5551
}
5652
};
5753

58-
if (!userLoggedIn) {
59-
return (
60-
<div className="hidden md:flex absolute bottom-4 right-4 flex-col items-end z-10">
61-
<button
62-
onClick={openLoginModal}
63-
className="px-4 py-2 bg-gray-600 text-white rounded-lg shadow-lg hover:bg-gray-700 flex items-center gap-2 transition-all duration-200 hover:scale-105"
64-
aria-label="Login to access AI chat"
65-
>
66-
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
67-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
68-
</svg>
69-
<span className="font-medium">Login to Chat</span>
70-
</button>
71-
</div>
72-
);
73-
}
74-
7554
return (
7655
<>
7756
{/* Mobile: Partial-height chat panel with drag handle */}

frontend/app/components/LoginModal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export default function LoginModal() {
4747
};
4848

4949
return (
50-
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50 backdrop-blur-sm">
51-
<div className="bg-white rounded-2xl shadow-xl w-full max-w-md overflow-hidden transform transition-all">
50+
<div onClick={closeLoginModal} className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50 backdrop-blur-sm cursor-pointer">
51+
<div onClick={(e) => e.stopPropagation()} className="bg-white rounded-2xl shadow-xl w-full max-w-md overflow-hidden transform transition-all cursor-default">
5252
<div className="p-8">
5353
<div className="flex justify-between items-center mb-6">
5454
<h2 className="text-2xl font-bold text-gray-900">

frontend/app/components/MobileNav.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ export default function MobileNav() {
88
const { userLoggedIn, openLoginModal, currentUser, openSavedTripsModal } = useAuth();
99

1010
const handleTabClick = (panel) => {
11-
if (panel === 'chat' && !userLoggedIn) {
12-
openLoginModal();
13-
return;
14-
}
11+
1512

1613
// Toggle panel off if already active, otherwise switch to it
1714
if (activePanel === panel) {

frontend/app/components/RoutePanel.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { useDraggablePanel } from '../hooks/useDraggablePanel';
1111
export default function RoutePanel() {
1212
const { optimizedRoute, selectedLocations, optimizedCoords, exportToGoogleMaps, startIndex, endIndex, activePanel, setActivePanel, routeHeight, setRouteHeight, currentChatSessionId } = useTrip();
1313
const { userLoggedIn, currentUser, openLoginModal } = useAuth();
14+
1415
const [isSaving, setIsSaving] = useState(false);
16+
const [showSignInPrompt, setShowSignInPrompt] = useState(false);
1517

1618
// Draggable panel hook for mobile resizing
1719
const { panelRef, handleDragStart } = useDraggablePanel({
@@ -32,7 +34,13 @@ export default function RoutePanel() {
3234
console.log('Optimized Route in RoutePanel:', optimizedRoute);
3335
console.log('Optimized Coordinates in RoutePanel:', optimizedCoords);
3436
}
35-
}, [optimizedRoute]);
37+
if (optimizedRoute) {
38+
console.log('Selected Locations:', selectedLocations);
39+
console.log('Optimized Route in RoutePanel:', optimizedRoute);
40+
console.log('Optimized Coordinates in RoutePanel:', optimizedCoords);
41+
if (!currentUser) setShowSignInPrompt(true);
42+
}
43+
}, [optimizedRoute, currentUser]);
3644

3745
const handleSaveTrip = async () => {
3846
if (!userLoggedIn) {
@@ -138,7 +146,15 @@ export default function RoutePanel() {
138146

139147
<div className="p-4 border-b flex justify-between items-center">
140148
<h3 className="font-semibold text-gray-900">Optimized Route</h3>
141-
<div className="flex gap-2">
149+
<div className="flex gap-2 items-center">
150+
{showSignInPrompt && !currentUser && (
151+
<button
152+
onClick={openLoginModal}
153+
className="mr-2 px-3 py-1.5 bg-blue-100 text-blue-700 text-xs font-semibold rounded-full animate-pulse hover:bg-blue-200"
154+
>
155+
Sign In to Save
156+
</button>
157+
)}
142158
{optimizedRoute && (
143159
<>
144160
<button

frontend/app/components/SavedTripsModal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export default function SavedTripsModal() {
8181
if (!isSavedTripsModalOpen) return null;
8282

8383
return (
84-
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 pb-24 md:pb-4 bg-black bg-opacity-50 backdrop-blur-sm">
85-
<div className="bg-white rounded-2xl shadow-xl w-full max-w-2xl h-[70vh] md:h-[80vh] flex flex-col overflow-hidden">
84+
<div onClick={closeSavedTripsModal} className="fixed inset-0 z-50 flex items-center justify-center p-4 pb-24 md:pb-4 bg-black bg-opacity-50 backdrop-blur-sm cursor-pointer">
85+
<div onClick={(e) => e.stopPropagation()} className="bg-white rounded-2xl shadow-xl w-full max-w-2xl h-[70vh] md:h-[80vh] flex flex-col overflow-hidden cursor-default">
8686
<div className="p-6 border-b flex justify-between items-center">
8787
<h2 className="text-2xl font-bold text-gray-900">Saved Trips</h2>
8888
<div className="flex items-center gap-2">

frontend/app/components/Search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default function Search() {
180180
id="pac-input"
181181
className="flex-1 p-2.5 bg-transparent border-none focus:ring-0 focus:outline-none text-gray-900 placeholder-gray-400"
182182
type="text"
183-
placeholder="Search for a location"
183+
placeholder="Search for a location or click on the map"
184184
aria-label="Search for a location"
185185
/>
186186
</div>

frontend/app/components/Sidebar.js

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function Sidebar() {
3838
// Desktop tab: 'itinerary' | 'route'
3939
const [desktopTab, setDesktopTab] = useState('itinerary');
4040
const [isSaving, setIsSaving] = useState(false);
41+
const [showSignInPrompt, setShowSignInPrompt] = useState(false);
4142

4243
// Draggable panel hook
4344
const { panelRef, handleDragStart } = useDraggablePanel({
@@ -55,8 +56,11 @@ export default function Sidebar() {
5556
useEffect(() => {
5657
if (optimizedRoute) {
5758
setDesktopTab('route');
59+
if (!currentUser) {
60+
setShowSignInPrompt(true);
61+
}
5862
}
59-
}, [optimizedRoute]);
63+
}, [optimizedRoute, currentUser]);
6064

6165
const handleDragEnd = (result) => {
6266
if (!result.destination) return;
@@ -299,31 +303,60 @@ export default function Sidebar() {
299303
) : (
300304
/* Route tab actions */
301305
optimizedRoute && (
302-
<div className="p-4 border-t bg-gray-50 rounded-b-lg flex gap-2">
303-
<button
304-
onClick={handleSaveTrip}
305-
disabled={isSaving}
306-
className={`flex-1 py-2.5 px-4 bg-green-600 text-white rounded-lg font-medium flex items-center justify-center gap-2 hover:bg-green-700 transition-colors ${isSaving ? 'opacity-75 cursor-not-allowed' : ''
307-
}`}
308-
>
309-
{isSaving ? (
310-
<div className="w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
311-
) : (
306+
<div className="p-4 border-t bg-gray-50 rounded-b-lg flex flex-col gap-2">
307+
{showSignInPrompt && !currentUser && (
308+
<div className="mb-2 p-3 bg-blue-50 border border-blue-100 rounded-lg flex justify-between items-center shadow-sm animate-slide-up">
309+
<div className="flex-1">
310+
<p className="text-sm text-blue-800 font-medium">✨ Trip optimized!</p>
311+
<p className="text-xs text-blue-600 mt-0.5">Sign in to save this trip.</p>
312+
</div>
313+
<div className="flex gap-2 ml-3">
314+
<button
315+
onClick={() => setShowSignInPrompt(false)}
316+
className="text-blue-400 hover:text-blue-600 p-1"
317+
>
318+
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
319+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
320+
</svg>
321+
</button>
322+
<button
323+
onClick={() => {
324+
openLoginModal();
325+
setShowSignInPrompt(false);
326+
}}
327+
className="px-3 py-1.5 bg-blue-600 text-white text-xs font-semibold rounded-md hover:bg-blue-700 transition-colors whitespace-nowrap"
328+
>
329+
Sign In
330+
</button>
331+
</div>
332+
</div>
333+
)}
334+
<div className="flex gap-2">
335+
<button
336+
onClick={handleSaveTrip}
337+
disabled={isSaving}
338+
className={`flex-1 py-2.5 px-4 bg-green-600 text-white rounded-lg font-medium flex items-center justify-center gap-2 hover:bg-green-700 transition-colors ${isSaving ? 'opacity-75 cursor-not-allowed' : ''
339+
}`}
340+
>
341+
{isSaving ? (
342+
<div className="w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
343+
) : (
344+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
345+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4" />
346+
</svg>
347+
)}
348+
Save
349+
</button>
350+
<button
351+
onClick={exportToGoogleMaps}
352+
className="flex-1 py-2.5 px-4 bg-blue-600 text-white rounded-lg font-medium flex items-center justify-center gap-2 hover:bg-blue-700 transition-colors"
353+
>
312354
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
313-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4" />
355+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
314356
</svg>
315-
)}
316-
Save
317-
</button>
318-
<button
319-
onClick={exportToGoogleMaps}
320-
className="flex-1 py-2.5 px-4 bg-blue-600 text-white rounded-lg font-medium flex items-center justify-center gap-2 hover:bg-blue-700 transition-colors"
321-
>
322-
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
323-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
324-
</svg>
325-
Export
326-
</button>
357+
Export
358+
</button>
359+
</div>
327360
</div>
328361
)
329362
)}

0 commit comments

Comments
 (0)