2024-07-08 11:44:39 -04:00
|
|
|
import inspirationalQuotes from './json/quotes.json';
|
2024-10-17 21:35:55 -04:00
|
|
|
import randomBackgrounds from './json/backgrounds.json';
|
2025-06-18 21:10:10 -04:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
import { DateTime } from 'luxon';
|
2024-10-20 21:56:16 -04:00
|
|
|
import type {
|
|
|
|
Adventure,
|
|
|
|
Background,
|
|
|
|
Checklist,
|
|
|
|
Collection,
|
2025-02-15 19:44:11 -05:00
|
|
|
Lodging,
|
2024-10-20 21:56:16 -04:00
|
|
|
Note,
|
|
|
|
Transportation,
|
|
|
|
User
|
|
|
|
} from './types';
|
2024-07-08 11:44:39 -04:00
|
|
|
|
|
|
|
export function getRandomQuote() {
|
|
|
|
const quotes = inspirationalQuotes.quotes;
|
|
|
|
const randomIndex = Math.floor(Math.random() * quotes.length);
|
|
|
|
let quoteString = quotes[randomIndex].quote;
|
|
|
|
let authorString = quotes[randomIndex].author;
|
2024-10-17 21:35:55 -04:00
|
|
|
return { quote: quoteString, author: authorString };
|
2024-07-08 11:44:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getFlag(size: number, country: string) {
|
|
|
|
return `https://flagcdn.com/h${size}/${country}.png`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function checkLink(link: string) {
|
|
|
|
if (link.startsWith('http://') || (link.startsWith('https://') && link.indexOf('.') !== -1)) {
|
|
|
|
return link;
|
|
|
|
} else {
|
|
|
|
return 'http://' + link + '.com';
|
|
|
|
}
|
|
|
|
}
|
2024-07-17 10:35:42 -04:00
|
|
|
|
|
|
|
export async function exportData() {
|
|
|
|
let res = await fetch('/api/adventures/all');
|
|
|
|
let adventures = (await res.json()) as Adventure[];
|
|
|
|
|
|
|
|
res = await fetch('/api/collections/all');
|
|
|
|
let collections = (await res.json()) as Collection[];
|
|
|
|
|
|
|
|
res = await fetch('/api/visitedregion');
|
|
|
|
let visitedRegions = await res.json();
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
adventures,
|
|
|
|
collections,
|
|
|
|
visitedRegions
|
|
|
|
};
|
|
|
|
|
|
|
|
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
|
|
|
|
return URL.createObjectURL(blob);
|
|
|
|
}
|
2024-08-04 13:27:05 -04:00
|
|
|
|
|
|
|
export function isValidUrl(url: string) {
|
|
|
|
try {
|
|
|
|
new URL(url);
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-08-05 18:48:11 -04:00
|
|
|
|
|
|
|
export function groupAdventuresByDate(
|
|
|
|
adventures: Adventure[],
|
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Adventure[]> {
|
|
|
|
const groupedAdventures: Record<string, Adventure[]> = {};
|
|
|
|
|
2025-06-18 22:21:34 -04:00
|
|
|
// Initialize all days in the range using DateTime
|
2024-08-05 18:48:11 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
2025-06-18 22:21:34 -04:00
|
|
|
const currentDate = DateTime.fromJSDate(startDate).plus({ days: i });
|
|
|
|
const dateString = currentDate.toISODate(); // 'YYYY-MM-DD'
|
2024-08-05 18:48:11 -04:00
|
|
|
groupedAdventures[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
adventures.forEach((adventure) => {
|
2024-10-01 09:32:02 -04:00
|
|
|
adventure.visits.forEach((visit) => {
|
|
|
|
if (visit.start_date) {
|
2025-06-18 22:21:34 -04:00
|
|
|
// Check if it's all-day: start has 00:00:00 AND (no end OR end also has 00:00:00)
|
2025-06-19 11:33:04 -04:00
|
|
|
const startHasZeros = isAllDay(visit.start_date);
|
|
|
|
const endHasZeros = visit.end_date ? isAllDay(visit.end_date) : true;
|
2025-06-18 22:21:34 -04:00
|
|
|
const isAllDayEvent = startHasZeros && endHasZeros;
|
|
|
|
|
|
|
|
let startDT: DateTime;
|
|
|
|
let endDT: DateTime;
|
|
|
|
|
|
|
|
if (isAllDayEvent) {
|
|
|
|
// For all-day events, extract just the date part and ignore timezone
|
|
|
|
const dateOnly = visit.start_date.split('T')[0]; // Get 'YYYY-MM-DD'
|
|
|
|
startDT = DateTime.fromISO(dateOnly); // This creates a date without time/timezone
|
|
|
|
|
2025-06-19 11:33:04 -04:00
|
|
|
endDT = visit.end_date ? DateTime.fromISO(visit.end_date.split('T')[0]) : startDT;
|
2025-03-20 10:26:41 -04:00
|
|
|
} else {
|
2025-06-18 22:21:34 -04:00
|
|
|
// For timed events, use timezone conversion
|
|
|
|
startDT = DateTime.fromISO(visit.start_date, {
|
|
|
|
zone: visit.timezone ?? 'UTC'
|
|
|
|
});
|
|
|
|
|
|
|
|
endDT = visit.end_date
|
|
|
|
? DateTime.fromISO(visit.end_date, {
|
|
|
|
zone: visit.timezone ?? 'UTC'
|
|
|
|
})
|
|
|
|
: startDT;
|
|
|
|
}
|
|
|
|
|
|
|
|
const startDateStr = startDT.toISODate();
|
|
|
|
const endDateStr = endDT.toISODate();
|
|
|
|
|
|
|
|
// Loop through all days in range
|
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = DateTime.fromJSDate(startDate).plus({ days: i });
|
|
|
|
const currentDateStr = currentDate.toISODate();
|
|
|
|
|
|
|
|
// Include the current day if it falls within the adventure date range
|
|
|
|
if (currentDateStr >= startDateStr && currentDateStr <= endDateStr) {
|
|
|
|
if (groupedAdventures[currentDateStr]) {
|
|
|
|
groupedAdventures[currentDateStr].push(adventure);
|
2025-03-20 10:26:41 -04:00
|
|
|
}
|
|
|
|
}
|
2024-08-19 16:32:08 -04:00
|
|
|
}
|
2024-08-05 18:48:11 -04:00
|
|
|
}
|
2024-10-01 09:32:02 -04:00
|
|
|
});
|
2024-08-05 18:48:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return groupedAdventures;
|
|
|
|
}
|
|
|
|
|
2025-03-20 10:26:41 -04:00
|
|
|
function getLocalDateString(date: Date): string {
|
|
|
|
const year = date.getFullYear();
|
|
|
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
|
|
|
|
const day = String(date.getDate()).padStart(2, '0');
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
}
|
|
|
|
|
2024-08-05 18:48:11 -04:00
|
|
|
export function groupTransportationsByDate(
|
|
|
|
transportations: Transportation[],
|
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Transportation[]> {
|
|
|
|
const groupedTransportations: Record<string, Transportation[]> = {};
|
|
|
|
|
2025-06-18 21:10:10 -04:00
|
|
|
// Initialize days
|
2024-08-05 18:48:11 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
2025-06-18 21:10:10 -04:00
|
|
|
const currentDate = DateTime.fromJSDate(startDate).plus({ days: i });
|
|
|
|
const dateString = currentDate.toISODate(); // 'YYYY-MM-DD'
|
2024-08-05 18:48:11 -04:00
|
|
|
groupedTransportations[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
transportations.forEach((transportation) => {
|
|
|
|
if (transportation.date) {
|
2025-06-18 21:10:10 -04:00
|
|
|
// Check if it's all-day: start has 00:00:00 AND (no end OR end also has 00:00:00)
|
|
|
|
const startHasZeros = transportation.date.includes('T00:00:00');
|
|
|
|
const endHasZeros = transportation.end_date
|
|
|
|
? transportation.end_date.includes('T00:00:00')
|
|
|
|
: true;
|
|
|
|
const isTranspoAllDay = startHasZeros && endHasZeros;
|
|
|
|
|
|
|
|
let startDT: DateTime;
|
|
|
|
let endDT: DateTime;
|
|
|
|
|
|
|
|
if (isTranspoAllDay) {
|
|
|
|
// For all-day events, extract just the date part and ignore timezone
|
|
|
|
const dateOnly = transportation.date.split('T')[0]; // Get 'YYYY-MM-DD'
|
|
|
|
startDT = DateTime.fromISO(dateOnly); // This creates a date without time/timezone
|
|
|
|
|
|
|
|
endDT = transportation.end_date
|
|
|
|
? DateTime.fromISO(transportation.end_date.split('T')[0])
|
|
|
|
: startDT;
|
|
|
|
} else {
|
|
|
|
// For timed events, use timezone conversion
|
|
|
|
startDT = DateTime.fromISO(transportation.date, {
|
|
|
|
zone: transportation.start_timezone ?? 'UTC'
|
|
|
|
});
|
|
|
|
|
|
|
|
endDT = transportation.end_date
|
|
|
|
? DateTime.fromISO(transportation.end_date, {
|
|
|
|
zone: transportation.end_timezone ?? transportation.start_timezone ?? 'UTC'
|
|
|
|
})
|
|
|
|
: startDT;
|
|
|
|
}
|
|
|
|
|
|
|
|
const startDateStr = startDT.toISODate();
|
|
|
|
const endDateStr = endDT.toISODate();
|
|
|
|
|
|
|
|
// Loop through all days in range
|
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = DateTime.fromJSDate(startDate).plus({ days: i });
|
|
|
|
const currentDateStr = currentDate.toISODate();
|
|
|
|
|
|
|
|
if (currentDateStr >= startDateStr && currentDateStr <= endDateStr) {
|
|
|
|
groupedTransportations[currentDateStr]?.push(transportation);
|
2024-08-19 16:32:08 -04:00
|
|
|
}
|
2024-08-05 18:48:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return groupedTransportations;
|
|
|
|
}
|
2025-02-15 19:44:11 -05:00
|
|
|
export function groupLodgingByDate(
|
2025-06-18 21:10:10 -04:00
|
|
|
lodging: Lodging[],
|
2025-02-15 19:44:11 -05:00
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Lodging[]> {
|
2025-06-18 21:10:10 -04:00
|
|
|
const groupedLodging: Record<string, Lodging[]> = {};
|
2025-02-15 19:44:11 -05:00
|
|
|
|
2025-06-18 21:10:10 -04:00
|
|
|
// Initialize days (excluding last day for lodging)
|
|
|
|
// If trip is 7/1 to 7/4 (4 days), show lodging only on 7/1, 7/2, 7/3
|
|
|
|
const lodgingDays = numberOfDays - 1;
|
|
|
|
|
|
|
|
for (let i = 0; i < lodgingDays; i++) {
|
|
|
|
const currentDate = DateTime.fromJSDate(startDate).plus({ days: i });
|
|
|
|
const dateString = currentDate.toISODate(); // 'YYYY-MM-DD'
|
|
|
|
groupedLodging[dateString] = [];
|
2025-02-15 19:44:11 -05:00
|
|
|
}
|
|
|
|
|
2025-06-18 21:10:10 -04:00
|
|
|
lodging.forEach((hotel) => {
|
|
|
|
if (hotel.check_in) {
|
|
|
|
// Check if it's all-day: start has 00:00:00 AND (no end OR end also has 00:00:00)
|
|
|
|
const startHasZeros = hotel.check_in.includes('T00:00:00');
|
|
|
|
const endHasZeros = hotel.check_out ? hotel.check_out.includes('T00:00:00') : true;
|
|
|
|
const isAllDay = startHasZeros && endHasZeros;
|
|
|
|
|
|
|
|
let startDT: DateTime;
|
|
|
|
let endDT: DateTime;
|
|
|
|
|
|
|
|
if (isAllDay) {
|
|
|
|
// For all-day events, extract just the date part and ignore timezone
|
|
|
|
const dateOnly = hotel.check_in.split('T')[0]; // Get 'YYYY-MM-DD'
|
|
|
|
startDT = DateTime.fromISO(dateOnly); // This creates a date without time/timezone
|
|
|
|
|
|
|
|
endDT = hotel.check_out ? DateTime.fromISO(hotel.check_out.split('T')[0]) : startDT;
|
|
|
|
} else {
|
|
|
|
// For timed events, use timezone conversion
|
|
|
|
startDT = DateTime.fromISO(hotel.check_in, {
|
|
|
|
zone: hotel.timezone ?? 'UTC'
|
|
|
|
});
|
|
|
|
|
|
|
|
endDT = hotel.check_out
|
|
|
|
? DateTime.fromISO(hotel.check_out, {
|
|
|
|
zone: hotel.timezone ?? 'UTC'
|
|
|
|
})
|
|
|
|
: startDT;
|
|
|
|
}
|
|
|
|
|
|
|
|
const startDateStr = startDT.toISODate();
|
|
|
|
const endDateStr = endDT.toISODate();
|
|
|
|
|
|
|
|
// Loop through lodging days only (excluding last day)
|
|
|
|
for (let i = 0; i < lodgingDays; i++) {
|
|
|
|
const currentDate = DateTime.fromJSDate(startDate).plus({ days: i });
|
|
|
|
const currentDateStr = currentDate.toISODate();
|
|
|
|
|
|
|
|
// Show lodging on days where check-in occurs through the day before check-out
|
|
|
|
// For lodging, we typically want to show it on the nights you're staying
|
|
|
|
if (currentDateStr >= startDateStr && currentDateStr < endDateStr) {
|
|
|
|
groupedLodging[currentDateStr]?.push(hotel);
|
2025-02-15 19:44:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-06-18 21:10:10 -04:00
|
|
|
return groupedLodging;
|
2025-02-15 19:44:11 -05:00
|
|
|
}
|
|
|
|
|
2024-08-05 18:48:11 -04:00
|
|
|
export function groupNotesByDate(
|
|
|
|
notes: Note[],
|
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Note[]> {
|
|
|
|
const groupedNotes: Record<string, Note[]> = {};
|
|
|
|
|
2025-03-18 21:07:34 -04:00
|
|
|
// Initialize all days in the range using local dates
|
2024-08-05 18:48:11 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
2025-03-18 21:07:34 -04:00
|
|
|
currentDate.setDate(startDate.getDate() + i);
|
|
|
|
const dateString = getLocalDateString(currentDate);
|
2024-08-05 18:48:11 -04:00
|
|
|
groupedNotes[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
notes.forEach((note) => {
|
|
|
|
if (note.date) {
|
2025-03-18 21:07:34 -04:00
|
|
|
// Use the date string as is since it's already in "YYYY-MM-DD" format.
|
|
|
|
const noteDate = note.date;
|
2024-08-05 18:48:11 -04:00
|
|
|
if (groupedNotes[noteDate]) {
|
|
|
|
groupedNotes[noteDate].push(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return groupedNotes;
|
|
|
|
}
|
2024-08-05 21:36:38 -04:00
|
|
|
|
|
|
|
export function groupChecklistsByDate(
|
|
|
|
checklists: Checklist[],
|
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Checklist[]> {
|
|
|
|
const groupedChecklists: Record<string, Checklist[]> = {};
|
|
|
|
|
2025-03-18 21:07:34 -04:00
|
|
|
// Initialize all days in the range using local dates
|
2024-08-05 21:36:38 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
2025-03-18 21:07:34 -04:00
|
|
|
currentDate.setDate(startDate.getDate() + i);
|
|
|
|
const dateString = getLocalDateString(currentDate);
|
2024-08-05 21:36:38 -04:00
|
|
|
groupedChecklists[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
checklists.forEach((checklist) => {
|
|
|
|
if (checklist.date) {
|
2025-03-18 21:07:34 -04:00
|
|
|
// Use the date string as is since it's already in "YYYY-MM-DD" format.
|
|
|
|
const checklistDate = checklist.date;
|
2024-09-16 20:02:17 -04:00
|
|
|
if (groupedChecklists[checklistDate]) {
|
|
|
|
groupedChecklists[checklistDate].push(checklist);
|
2024-08-05 21:36:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return groupedChecklists;
|
|
|
|
}
|
2024-09-06 23:58:06 -04:00
|
|
|
|
2025-06-18 21:10:10 -04:00
|
|
|
// Helper to check if a given date string represents midnight (all-day)
|
|
|
|
// Improved isAllDay function to handle different ISO date formats
|
|
|
|
export function isAllDay(dateStr: string): boolean {
|
|
|
|
// Check for various midnight formats in UTC
|
|
|
|
return dateStr.endsWith('T00:00:00Z') || dateStr.endsWith('T00:00:00.000Z');
|
|
|
|
}
|
|
|
|
|
2024-09-06 23:58:06 -04:00
|
|
|
export function continentCodeToString(code: string) {
|
|
|
|
switch (code) {
|
|
|
|
case 'AF':
|
|
|
|
return 'Africa';
|
|
|
|
case 'AN':
|
|
|
|
return 'Antarctica';
|
|
|
|
case 'AS':
|
|
|
|
return 'Asia';
|
|
|
|
case 'EU':
|
|
|
|
return 'Europe';
|
|
|
|
case 'NA':
|
|
|
|
return 'North America';
|
|
|
|
case 'OC':
|
|
|
|
return 'Oceania';
|
|
|
|
case 'SA':
|
|
|
|
return 'South America';
|
|
|
|
default:
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
|
|
|
}
|
2024-09-23 18:46:04 -04:00
|
|
|
|
|
|
|
export let ADVENTURE_TYPES = [
|
|
|
|
{ type: 'general', label: 'General 🌍' },
|
2024-09-24 17:05:16 -04:00
|
|
|
{ type: 'outdoor', label: 'Outdoor 🏞️' },
|
2024-09-23 18:46:04 -04:00
|
|
|
{ type: 'lodging', label: 'Lodging 🛌' },
|
|
|
|
{ type: 'dining', label: 'Dining 🍽️' },
|
|
|
|
{ type: 'activity', label: 'Activity 🏄' },
|
|
|
|
{ type: 'attraction', label: 'Attraction 🎢' },
|
|
|
|
{ type: 'shopping', label: 'Shopping 🛍️' },
|
|
|
|
{ type: 'nightlife', label: 'Nightlife 🌃' },
|
|
|
|
{ type: 'event', label: 'Event 🎉' },
|
|
|
|
{ type: 'transportation', label: 'Transportation 🚗' },
|
|
|
|
{ type: 'culture', label: 'Culture 🎭' },
|
|
|
|
{ type: 'water_sports', label: 'Water Sports 🚤' },
|
|
|
|
{ type: 'hiking', label: 'Hiking 🥾' },
|
|
|
|
{ type: 'wildlife', label: 'Wildlife 🦒' },
|
|
|
|
{ type: 'historical_sites', label: 'Historical Sites 🏛️' },
|
|
|
|
{ type: 'music_concerts', label: 'Music & Concerts 🎶' },
|
|
|
|
{ type: 'fitness', label: 'Fitness 🏋️' },
|
|
|
|
{ type: 'art_museums', label: 'Art & Museums 🎨' },
|
|
|
|
{ type: 'festivals', label: 'Festivals 🎪' },
|
|
|
|
{ type: 'spiritual_journeys', label: 'Spiritual Journeys 🧘♀️' },
|
|
|
|
{ type: 'volunteer_work', label: 'Volunteer Work 🤝' },
|
|
|
|
{ type: 'other', label: 'Other' }
|
|
|
|
];
|
|
|
|
|
2024-11-02 21:18:52 -04:00
|
|
|
// adventure type to icon mapping
|
|
|
|
export let ADVENTURE_TYPE_ICONS = {
|
|
|
|
general: '🌍',
|
|
|
|
outdoor: '🏞️',
|
|
|
|
lodging: '🛌',
|
|
|
|
dining: '🍽️',
|
|
|
|
activity: '🏄',
|
|
|
|
attraction: '🎢',
|
|
|
|
shopping: '🛍️',
|
|
|
|
nightlife: '🌃',
|
|
|
|
event: '🎉',
|
|
|
|
transportation: '🚗',
|
|
|
|
culture: '🎭',
|
|
|
|
water_sports: '🚤',
|
|
|
|
hiking: '🥾',
|
|
|
|
wildlife: '🦒',
|
|
|
|
historical_sites: '🏛️',
|
|
|
|
music_concerts: '🎶',
|
|
|
|
fitness: '🏋️',
|
|
|
|
art_museums: '🎨',
|
|
|
|
festivals: '🎪',
|
|
|
|
spiritual_journeys: '🧘♀️',
|
|
|
|
volunteer_work: '🤝',
|
|
|
|
other: '❓'
|
|
|
|
};
|
|
|
|
|
2025-03-15 23:55:53 -04:00
|
|
|
export let LODGING_TYPES_ICONS = {
|
|
|
|
hotel: '🏨',
|
|
|
|
hostel: '🛏️',
|
|
|
|
resort: '🏝️',
|
|
|
|
bnb: '🍳',
|
|
|
|
campground: '🏕️',
|
|
|
|
cabin: '🏚️',
|
|
|
|
apartment: '🏢',
|
|
|
|
house: '🏠',
|
|
|
|
villa: '🏡',
|
|
|
|
motel: '🚗🏨',
|
|
|
|
other: '❓'
|
|
|
|
};
|
|
|
|
|
2025-03-18 17:40:32 -04:00
|
|
|
export let TRANSPORTATION_TYPES_ICONS = {
|
|
|
|
car: '🚗',
|
|
|
|
plane: '✈️',
|
|
|
|
train: '🚆',
|
|
|
|
bus: '🚌',
|
|
|
|
boat: '⛵',
|
|
|
|
bike: '🚲',
|
|
|
|
walking: '🚶',
|
|
|
|
other: '❓'
|
|
|
|
};
|
|
|
|
|
2024-11-02 21:29:42 -04:00
|
|
|
export function getAdventureTypeLabel(type: string) {
|
|
|
|
// return the emoji ADVENTURE_TYPE_ICONS label for the given type if not found return ? emoji
|
|
|
|
if (type in ADVENTURE_TYPE_ICONS) {
|
|
|
|
return ADVENTURE_TYPE_ICONS[type as keyof typeof ADVENTURE_TYPE_ICONS];
|
|
|
|
} else {
|
|
|
|
return '❓';
|
|
|
|
}
|
2024-11-02 21:18:52 -04:00
|
|
|
}
|
|
|
|
|
2024-10-17 21:35:55 -04:00
|
|
|
export function getRandomBackground() {
|
2024-12-26 11:07:59 -05:00
|
|
|
const today = new Date();
|
|
|
|
|
|
|
|
// Special dates for specific backgrounds
|
|
|
|
// New Years week
|
|
|
|
|
|
|
|
const newYearsStart = new Date(today.getFullYear() - 1, 11, 31);
|
|
|
|
newYearsStart.setHours(0, 0, 0, 0);
|
2025-01-03 18:46:45 -05:00
|
|
|
const newYearsEnd = new Date(today.getFullYear(), 0, 2);
|
2024-12-26 11:07:59 -05:00
|
|
|
newYearsEnd.setHours(23, 59, 59, 999);
|
|
|
|
if (today >= newYearsStart && today <= newYearsEnd) {
|
|
|
|
return {
|
|
|
|
url: 'backgrounds/adventurelog_new_year.webp',
|
|
|
|
author: 'Roven Images',
|
|
|
|
location: "Happy New Year's from the AdventureLog team!"
|
|
|
|
} as Background;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Christmas 12/24 - 12/25
|
|
|
|
const christmasStart = new Date(today.getFullYear(), 11, 24);
|
|
|
|
christmasStart.setHours(0, 0, 0, 0);
|
|
|
|
const christmasEnd = new Date(today.getFullYear(), 11, 25);
|
|
|
|
christmasEnd.setHours(23, 59, 59, 999);
|
|
|
|
|
|
|
|
if (today >= christmasStart && today <= christmasEnd) {
|
|
|
|
return {
|
|
|
|
url: 'backgrounds/adventurelog_christmas.webp',
|
|
|
|
author: 'Annie Spratt',
|
|
|
|
location: 'Merry Christmas from the AdventureLog team!'
|
|
|
|
} as Background;
|
|
|
|
}
|
|
|
|
|
2024-10-17 21:35:55 -04:00
|
|
|
const randomIndex = Math.floor(Math.random() * randomBackgrounds.backgrounds.length);
|
2024-10-20 21:56:16 -04:00
|
|
|
return randomBackgrounds.backgrounds[randomIndex] as Background;
|
2024-10-17 21:35:55 -04:00
|
|
|
}
|
2024-11-23 13:42:41 -05:00
|
|
|
|
|
|
|
export function findFirstValue(obj: any): any {
|
|
|
|
for (const key in obj) {
|
|
|
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
|
|
const value = findFirstValue(obj[key]);
|
|
|
|
if (value !== undefined) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return obj[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-26 17:39:10 -05:00
|
|
|
|
|
|
|
export let themes = [
|
|
|
|
{ name: 'light', label: 'Light' },
|
|
|
|
{ name: 'dark', label: 'Dark' },
|
2025-06-14 18:55:59 -04:00
|
|
|
{ name: 'dim', label: 'Dim' },
|
2024-11-26 17:39:10 -05:00
|
|
|
{ name: 'night', label: 'Night' },
|
|
|
|
{ name: 'forest', label: 'Forest' },
|
|
|
|
{ name: 'aqua', label: 'Aqua' },
|
|
|
|
{ name: 'aestheticLight', label: 'Aesthetic Light' },
|
2024-12-02 15:47:09 -05:00
|
|
|
{ name: 'aestheticDark', label: 'Aesthetic Dark' },
|
|
|
|
{ name: 'northernLights', label: 'Northern Lights' }
|
2024-11-26 17:39:10 -05:00
|
|
|
];
|
2025-01-15 15:39:21 -05:00
|
|
|
|
|
|
|
export function osmTagToEmoji(tag: string) {
|
|
|
|
switch (tag) {
|
|
|
|
case 'camp_site':
|
|
|
|
return '🏕️';
|
|
|
|
case 'slipway':
|
|
|
|
return '🛳️';
|
|
|
|
case 'playground':
|
|
|
|
return '🛝';
|
|
|
|
case 'viewpoint':
|
|
|
|
return '👀';
|
|
|
|
case 'cape':
|
|
|
|
return '🏞️';
|
|
|
|
case 'beach':
|
|
|
|
return '🏖️';
|
|
|
|
case 'park':
|
|
|
|
return '🌳';
|
|
|
|
case 'museum':
|
|
|
|
return '🏛️';
|
|
|
|
case 'theme_park':
|
|
|
|
return '🎢';
|
|
|
|
case 'nature_reserve':
|
|
|
|
return '🌲';
|
|
|
|
case 'memorial':
|
|
|
|
return '🕊️';
|
|
|
|
case 'monument':
|
|
|
|
return '🗿';
|
|
|
|
case 'wood':
|
|
|
|
return '🌲';
|
|
|
|
case 'zoo':
|
|
|
|
return '🦁';
|
|
|
|
case 'attraction':
|
|
|
|
return '🎡';
|
|
|
|
case 'ruins':
|
|
|
|
return '🏚️';
|
|
|
|
case 'bay':
|
|
|
|
return '🌊';
|
|
|
|
case 'hotel':
|
|
|
|
return '🏨';
|
|
|
|
case 'motel':
|
|
|
|
return '🏩';
|
|
|
|
case 'pub':
|
|
|
|
return '🍺';
|
|
|
|
case 'restaurant':
|
|
|
|
return '🍽️';
|
|
|
|
case 'cafe':
|
|
|
|
return '☕';
|
|
|
|
case 'bakery':
|
|
|
|
return '🥐';
|
|
|
|
case 'archaeological_site':
|
|
|
|
return '🏺';
|
|
|
|
case 'lighthouse':
|
|
|
|
return '🗼';
|
|
|
|
case 'tree':
|
|
|
|
return '🌳';
|
|
|
|
case 'cliff':
|
|
|
|
return '⛰️';
|
|
|
|
case 'water':
|
|
|
|
return '💧';
|
|
|
|
case 'fishing':
|
|
|
|
return '🎣';
|
|
|
|
case 'golf_course':
|
|
|
|
return '⛳';
|
|
|
|
case 'swimming_pool':
|
|
|
|
return '🏊';
|
|
|
|
case 'stadium':
|
|
|
|
return '🏟️';
|
|
|
|
case 'cave_entrance':
|
|
|
|
return '🕳️';
|
|
|
|
case 'anchor':
|
|
|
|
return '⚓';
|
|
|
|
case 'garden':
|
|
|
|
return '🌼';
|
|
|
|
case 'disc_golf_course':
|
|
|
|
return '🥏';
|
|
|
|
case 'natural':
|
|
|
|
return '🌿';
|
|
|
|
case 'ice_rink':
|
|
|
|
return '⛸️';
|
|
|
|
case 'horse_riding':
|
|
|
|
return '🐎';
|
|
|
|
case 'wreck':
|
|
|
|
return '🚢';
|
|
|
|
case 'water_park':
|
|
|
|
return '💦';
|
|
|
|
case 'picnic_site':
|
|
|
|
return '🧺';
|
|
|
|
case 'axe_throwing':
|
|
|
|
return '🪓';
|
|
|
|
case 'fort':
|
|
|
|
return '🏰';
|
|
|
|
case 'amusement_arcade':
|
|
|
|
return '🕹️';
|
|
|
|
case 'tepee':
|
|
|
|
return '🏕️';
|
|
|
|
case 'track':
|
|
|
|
return '🏃';
|
|
|
|
case 'trampoline_park':
|
|
|
|
return '🤸';
|
|
|
|
case 'dojo':
|
|
|
|
return '🥋';
|
|
|
|
case 'tree_stump':
|
|
|
|
return '🪵';
|
|
|
|
case 'peak':
|
|
|
|
return '🏔️';
|
|
|
|
case 'fitness_centre':
|
|
|
|
return '🏋️';
|
|
|
|
case 'artwork':
|
|
|
|
return '🎨';
|
|
|
|
case 'fast_food':
|
|
|
|
return '🍔';
|
|
|
|
case 'ice_cream':
|
|
|
|
return '🍦';
|
|
|
|
default:
|
|
|
|
return '📍'; // Default placeholder emoji for unknown tags
|
|
|
|
}
|
|
|
|
}
|
2025-01-30 12:18:35 +01:00
|
|
|
|
|
|
|
export function debounce(func: Function, timeout: number) {
|
2025-01-30 13:02:49 +01:00
|
|
|
let timer: number | NodeJS.Timeout;
|
|
|
|
return (...args: any) => {
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
func(...args);
|
|
|
|
}, timeout);
|
|
|
|
};
|
2025-02-15 19:44:11 -05:00
|
|
|
}
|
2025-06-13 23:49:14 -04:00
|
|
|
|
|
|
|
export function getIsDarkMode() {
|
|
|
|
const theme = document.documentElement.getAttribute('data-theme');
|
|
|
|
|
|
|
|
if (theme) {
|
|
|
|
const isDark =
|
|
|
|
theme === 'dark' ||
|
|
|
|
theme === 'night' ||
|
|
|
|
theme === 'aestheticDark' ||
|
|
|
|
theme === 'northernLights' ||
|
2025-06-14 18:55:59 -04:00
|
|
|
theme === 'forest' ||
|
|
|
|
theme === 'dim';
|
2025-06-13 23:49:14 -04:00
|
|
|
return isDark;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to browser preference if no theme cookie is set
|
|
|
|
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
|
|
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
|
|
return prefersDark;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getBasemapUrl() {
|
|
|
|
if (getIsDarkMode()) {
|
|
|
|
return 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json';
|
|
|
|
}
|
|
|
|
return 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json';
|
|
|
|
}
|