Skip to content

Commit d19eed0

Browse files
author
“Ahaanv19”
committed
Added Paying model
1 parent 62451da commit d19eed0

3 files changed

Lines changed: 116 additions & 4 deletions

File tree

navigation/favoriteLocations/favoriteLocations.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ async function populateScores() {
6464
square.addEventListener('click', () => showPopup(location)); // Add click event to show popup
6565
grid.appendChild(square);
6666
});
67+
68+
// Update usage display after populating
69+
if (typeof window.updateUsageDisplay === 'function') {
70+
window.updateUsageDisplay();
71+
}
6772
}
6873

6974
async function filterForUsername(scores) {

navigation/favoriteLocations/favoriteLocations.md

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,57 @@ permalink: /favoriteLocations/
110110

111111
<!-- Main Content (hidden until access verified) -->
112112
<div id="main-content" style="display: none;">
113+
<!-- Usage Display Header -->
114+
<div id="usage-header" class="usage-header" style="display: none;">
115+
<div class="usage-info">
116+
<span id="usage-display" class="usage-text"></span>
117+
<a href="{{site.baseurl}}/pricing" id="upgrade-link" class="upgrade-link" style="display: none;">Upgrade for more</a>
118+
</div>
119+
</div>
113120
<div id="locations-grid"></div>
114121
<button id="new-location-button" class="new-location-button">New</button>
115122
</div>
116123

124+
<style>
125+
.usage-header {
126+
padding: 12px 20px;
127+
margin-bottom: 20px;
128+
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
129+
border-radius: 12px;
130+
border: 1px solid #334155;
131+
}
132+
.usage-info {
133+
display: flex;
134+
justify-content: space-between;
135+
align-items: center;
136+
}
137+
.usage-text {
138+
font-size: 14px;
139+
font-weight: 600;
140+
}
141+
.usage-text.text-green-400 { color: #4ade80; }
142+
.usage-text.text-yellow-400 { color: #facc15; }
143+
.usage-text.text-red-400 { color: #f87171; }
144+
.upgrade-link {
145+
font-size: 13px;
146+
color: #22c55e;
147+
text-decoration: none;
148+
font-weight: 600;
149+
transition: all 0.2s;
150+
}
151+
.upgrade-link:hover {
152+
color: #4ade80;
153+
text-decoration: underline;
154+
}
155+
</style>
156+
117157
<!-- Subscription Access Check (runs first) -->
118158
<script type="module">
119159
import { pythonURI, fetchOptions } from '{{site.baseurl}}/assets/js/api/config.js';
120160

161+
let currentTier = 'free';
162+
let locationLimit = 0;
163+
121164
async function checkAccess() {
122165
try {
123166
// Check if user is logged in
@@ -131,6 +174,8 @@ permalink: /favoriteLocations/
131174

132175
// Admins have full access
133176
if (user.role === 'Admin') {
177+
currentTier = 'admin';
178+
locationLimit = Infinity;
134179
showContent();
135180
return;
136181
}
@@ -139,7 +184,14 @@ permalink: /favoriteLocations/
139184
const subResponse = await fetch(`${pythonURI}/api/subscription`, fetchOptions);
140185
if (subResponse.ok) {
141186
const subscription = await subResponse.json();
142-
if (subscription.tier === 'plus' || subscription.tier === 'pro') {
187+
currentTier = subscription.tier || 'free';
188+
189+
if (currentTier === 'plus') {
190+
locationLimit = 10;
191+
showContent();
192+
return;
193+
} else if (currentTier === 'pro') {
194+
locationLimit = Infinity;
143195
showContent();
144196
return;
145197
}
@@ -158,8 +210,19 @@ permalink: /favoriteLocations/
158210
document.getElementById('access-loading').style.display = 'none';
159211
document.getElementById('access-denied').style.display = 'none';
160212
document.getElementById('main-content').style.display = 'block';
161-
// Load the main functionality
162-
import('{{site.baseurl}}/navigation/favoriteLocations/favoriteLocations.js');
213+
214+
// Show usage header
215+
document.getElementById('usage-header').style.display = 'block';
216+
217+
// Load the main functionality and then update usage display
218+
import('{{site.baseurl}}/navigation/favoriteLocations/favoriteLocations.js').then(() => {
219+
// Wait a bit for locations to load, then update display
220+
setTimeout(updateUsageDisplay, 500);
221+
});
222+
223+
// Store tier info globally for the usage display
224+
window.favoriteLocationsTier = currentTier;
225+
window.favoriteLocationsLimit = locationLimit;
163226
}
164227

165228
function showAccessDenied() {
@@ -168,5 +231,35 @@ permalink: /favoriteLocations/
168231
document.getElementById('main-content').style.display = 'none';
169232
}
170233

234+
// Update the usage display based on current locations count
235+
window.updateUsageDisplay = function() {
236+
const grid = document.getElementById('locations-grid');
237+
const usageDisplay = document.getElementById('usage-display');
238+
const upgradeLink = document.getElementById('upgrade-link');
239+
const tier = window.favoriteLocationsTier;
240+
const limit = window.favoriteLocationsLimit;
241+
242+
// Count current locations
243+
const locationCount = grid ? grid.querySelectorAll('.location-square').length : 0;
244+
245+
if (tier === 'admin' || tier === 'pro' || limit === Infinity) {
246+
usageDisplay.textContent = `📍 ${locationCount} locations saved • Unlimited`;
247+
usageDisplay.className = 'usage-text text-green-400';
248+
upgradeLink.style.display = 'none';
249+
} else if (tier === 'plus') {
250+
const remaining = limit - locationCount;
251+
const colorClass = remaining <= 2 ? 'text-red-400' : remaining <= 5 ? 'text-yellow-400' : 'text-green-400';
252+
usageDisplay.textContent = `📍 ${locationCount}/${limit} locations saved`;
253+
usageDisplay.className = `usage-text ${colorClass}`;
254+
255+
if (remaining <= 3) {
256+
upgradeLink.style.display = 'inline';
257+
upgradeLink.textContent = remaining <= 0 ? 'Upgrade for unlimited' : 'Upgrade for unlimited';
258+
} else {
259+
upgradeLink.style.display = 'none';
260+
}
261+
}
262+
};
263+
171264
checkAccess();
172265
</script>

navigation/findBestRoute/map.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import polyline from 'https://cdn.skypack.dev/@mapbox/polyline';
44
const apiUrl = `${pythonURI}/api/get_routes`;
55
const routeUsageUrl = `${pythonURI}/api/subscription/route-usage`;
66

7+
// Get the base URL from the page (set by Jekyll)
8+
function getBaseUrl() {
9+
const trigger = document.querySelector('.trigger');
10+
if (trigger && trigger.getAttribute('data-baseurl')) {
11+
return trigger.getAttribute('data-baseurl');
12+
}
13+
// Fallback: try to extract from current URL or use known baseurl
14+
const pathMatch = window.location.pathname.match(/^(\/[^\/]+)/);
15+
if (pathMatch && pathMatch[1] !== '/route') {
16+
return pathMatch[1];
17+
}
18+
return '/SD_Auto_Frontend'; // Hardcoded fallback
19+
}
20+
721
const map = L.map('map').setView([32.7157, -117.1611], 12);
822
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
923
attribution: '&copy; OpenStreetMap contributors',
@@ -65,7 +79,7 @@ function showLimitReachedModal(data) {
6579
class="flex-1 py-3 px-4 rounded-xl bg-gray-700 text-white font-semibold hover:bg-gray-600 transition-colors">
6680
Close
6781
</button>
68-
<a href="${data.upgrade_url || '/pricing'}"
82+
<a href="${getBaseUrl()}/pricing"
6983
class="flex-1 py-3 px-4 rounded-xl bg-gradient-to-r from-yellow-500 to-yellow-600 text-white font-semibold text-center hover:from-yellow-600 hover:to-yellow-700 transition-all">
7084
Upgrade Now
7185
</a>

0 commit comments

Comments
 (0)