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';
|
2024-10-20 21:56:16 -04:00
|
|
|
import type {
|
|
|
|
Adventure,
|
|
|
|
Background,
|
|
|
|
Checklist,
|
|
|
|
Collection,
|
|
|
|
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[]> = {};
|
|
|
|
|
2024-09-16 20:02:17 -04:00
|
|
|
// Initialize all days in the range
|
2024-08-05 18:48:11 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
2024-09-16 20:02:17 -04:00
|
|
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
2024-08-05 18:48:11 -04:00
|
|
|
const dateString = currentDate.toISOString().split('T')[0];
|
|
|
|
groupedAdventures[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
adventures.forEach((adventure) => {
|
2024-10-01 09:32:02 -04:00
|
|
|
adventure.visits.forEach((visit) => {
|
|
|
|
if (visit.start_date) {
|
|
|
|
const adventureDate = new Date(visit.start_date).toISOString().split('T')[0];
|
|
|
|
if (visit.end_date) {
|
|
|
|
const endDate = new Date(visit.end_date).toISOString().split('T')[0];
|
|
|
|
|
|
|
|
// Loop through all days and include adventure if it falls within the range
|
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
|
|
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
|
|
|
const dateString = currentDate.toISOString().split('T')[0];
|
|
|
|
|
|
|
|
// Include the current day if it falls within the adventure date range
|
|
|
|
if (dateString >= adventureDate && dateString <= endDate) {
|
|
|
|
if (groupedAdventures[dateString]) {
|
|
|
|
groupedAdventures[dateString].push(adventure);
|
|
|
|
}
|
2024-08-19 16:32:08 -04:00
|
|
|
}
|
|
|
|
}
|
2024-10-01 09:32:02 -04:00
|
|
|
} else if (groupedAdventures[adventureDate]) {
|
|
|
|
// If there's no end date, add adventure to the start date only
|
|
|
|
groupedAdventures[adventureDate].push(adventure);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function groupTransportationsByDate(
|
|
|
|
transportations: Transportation[],
|
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Transportation[]> {
|
|
|
|
const groupedTransportations: Record<string, Transportation[]> = {};
|
|
|
|
|
2024-09-16 20:02:17 -04:00
|
|
|
// Initialize all days in the range
|
2024-08-05 18:48:11 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
2024-09-16 20:02:17 -04:00
|
|
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
2024-08-05 18:48:11 -04:00
|
|
|
const dateString = currentDate.toISOString().split('T')[0];
|
|
|
|
groupedTransportations[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
transportations.forEach((transportation) => {
|
|
|
|
if (transportation.date) {
|
|
|
|
const transportationDate = new Date(transportation.date).toISOString().split('T')[0];
|
2024-08-19 16:32:08 -04:00
|
|
|
if (transportation.end_date) {
|
|
|
|
const endDate = new Date(transportation.end_date).toISOString().split('T')[0];
|
2024-09-16 20:02:17 -04:00
|
|
|
|
|
|
|
// Loop through all days and include transportation if it falls within the range
|
2024-08-19 16:32:08 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
2024-09-16 20:02:17 -04:00
|
|
|
const currentDate = new Date(startDate);
|
|
|
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
2024-08-19 16:32:08 -04:00
|
|
|
const dateString = currentDate.toISOString().split('T')[0];
|
2024-09-16 20:02:17 -04:00
|
|
|
|
|
|
|
// Include the current day if it falls within the transportation date range
|
2024-08-19 16:32:08 -04:00
|
|
|
if (dateString >= transportationDate && dateString <= endDate) {
|
|
|
|
if (groupedTransportations[dateString]) {
|
|
|
|
groupedTransportations[dateString].push(transportation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (groupedTransportations[transportationDate]) {
|
2024-09-16 20:02:17 -04:00
|
|
|
// If there's no end date, add transportation to the start date only
|
2024-08-05 18:48:11 -04:00
|
|
|
groupedTransportations[transportationDate].push(transportation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return groupedTransportations;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function groupNotesByDate(
|
|
|
|
notes: Note[],
|
|
|
|
startDate: Date,
|
|
|
|
numberOfDays: number
|
|
|
|
): Record<string, Note[]> {
|
|
|
|
const groupedNotes: Record<string, Note[]> = {};
|
|
|
|
|
2024-09-16 20:02:17 -04:00
|
|
|
// Initialize all days in the range
|
2024-08-05 18:48:11 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
2024-09-16 20:02:17 -04:00
|
|
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
2024-08-05 18:48:11 -04:00
|
|
|
const dateString = currentDate.toISOString().split('T')[0];
|
|
|
|
groupedNotes[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
notes.forEach((note) => {
|
|
|
|
if (note.date) {
|
|
|
|
const noteDate = new Date(note.date).toISOString().split('T')[0];
|
2024-09-16 20:02:17 -04:00
|
|
|
|
|
|
|
// Add note to the appropriate date group if it exists
|
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[]> = {};
|
|
|
|
|
2024-09-16 20:02:17 -04:00
|
|
|
// Initialize all days in the range
|
2024-08-05 21:36:38 -04:00
|
|
|
for (let i = 0; i < numberOfDays; i++) {
|
|
|
|
const currentDate = new Date(startDate);
|
2024-09-16 20:02:17 -04:00
|
|
|
currentDate.setUTCDate(startDate.getUTCDate() + i);
|
2024-08-05 21:36:38 -04:00
|
|
|
const dateString = currentDate.toISOString().split('T')[0];
|
|
|
|
groupedChecklists[dateString] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
checklists.forEach((checklist) => {
|
|
|
|
if (checklist.date) {
|
2024-09-16 20:02:17 -04:00
|
|
|
const checklistDate = new Date(checklist.date).toISOString().split('T')[0];
|
|
|
|
|
|
|
|
// Add checklist to the appropriate date group if it exists
|
|
|
|
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
|
|
|
|
|
|
|
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: '❓'
|
|
|
|
};
|
|
|
|
|
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() {
|
|
|
|
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' },
|
|
|
|
{ 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
|
|
|
];
|