Compare commits
10 Commits
92fae28383
...
2226a483c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2226a483c5 | ||
|
|
93636b6968 | ||
|
|
5718bca963 | ||
|
|
6f41f6e53e | ||
|
|
d157055ab7 | ||
|
|
76d7e815c3 | ||
|
|
c7cf053105 | ||
|
|
a7079c1f18 | ||
|
|
cf9717149f | ||
|
|
ec4eea0977 |
@@ -6,7 +6,7 @@
|
||||
import WorldMap from './lib/world-map/WorldMap.svelte';
|
||||
import JourneyView from './lib/world-map/JourneyView.svelte';
|
||||
import StatsPanel from './lib/world-map/StatsPanel.svelte';
|
||||
import TimelineView from './lib/timeline/TimelineView.svelte';
|
||||
import TimelineView from './lib/timeline/view/TimelineView.svelte';
|
||||
|
||||
let screen = $state('worldmap');
|
||||
let journeyActive = $state(false);
|
||||
|
||||
|
Before Width: | Height: | Size: 238 KiB |
|
Before Width: | Height: | Size: 322 KiB |
|
Before Width: | Height: | Size: 287 KiB |
|
Before Width: | Height: | Size: 283 KiB |
|
Before Width: | Height: | Size: 343 KiB |
|
Before Width: | Height: | Size: 108 KiB |
BIN
src/assets/home.png
Normal file
|
After Width: | Height: | Size: 436 KiB |
BIN
src/assets/logo-1-cursor.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src/assets/logo-cursor.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 340 KiB After Width: | Height: | Size: 112 KiB |
@@ -1,93 +1,72 @@
|
||||
<script>
|
||||
import { getUser, getUserProfile, setHomeCountry } from './userStore.svelte.js';
|
||||
import worldData from 'world-atlas/countries-50m.json';
|
||||
import { countryNames } from '../shared/countries.js';
|
||||
import homeImg from '../../assets/home.png';
|
||||
|
||||
let user = $derived(getUser());
|
||||
let profile = $derived(getUserProfile());
|
||||
|
||||
const countries = $derived.by(() => {
|
||||
if (!worldData?.objects?.countries?.geometries) return [];
|
||||
return worldData.objects.countries.geometries
|
||||
.map(g => ({ name: g.properties?.name, code: g.id }))
|
||||
.filter(c => c.name && c.code)
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
});
|
||||
|
||||
let search = $state('');
|
||||
let selectedCountry = $state(null);
|
||||
|
||||
let filtered = $derived(
|
||||
search
|
||||
? countries.filter(c => c.name.toLowerCase().includes(search.toLowerCase()))
|
||||
: countries
|
||||
);
|
||||
|
||||
let selectedCountry = $state('');
|
||||
let open = $state(false);
|
||||
|
||||
function select(c) {
|
||||
selectedCountry = c;
|
||||
search = c.name;
|
||||
let filtered = $derived(
|
||||
search.trim()
|
||||
? countryNames.filter(c => c.toLowerCase().includes(search.toLowerCase()))
|
||||
: countryNames
|
||||
);
|
||||
|
||||
function select(name) {
|
||||
selectedCountry = name;
|
||||
search = name;
|
||||
open = false;
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
if (selectedCountry) {
|
||||
setHomeCountry(selectedCountry.name, selectedCountry.code);
|
||||
setHomeCountry(selectedCountry, selectedCountry);
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(e) {
|
||||
if (e.key === 'Enter' && selectedCountry) {
|
||||
handleSubmit();
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
open = false;
|
||||
}
|
||||
if (e.key === 'Enter' && selectedCountry) handleSubmit();
|
||||
if (e.key === 'Escape') open = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="overlay">
|
||||
<div class="card">
|
||||
<h1 class="heading">Welcome, {profile?.displayName || 'Traveler'}!</h1>
|
||||
<p class="subtitle">Select your home country to get started</p>
|
||||
<img src={homeImg} alt="home" class="home-img" />
|
||||
<h1 class="title">Welcome, {profile?.displayName?.split(' ')[0] || 'Traveler'}!</h1>
|
||||
<p class="subtitle">Where do you call home?</p>
|
||||
|
||||
<div class="dropdown" class:open>
|
||||
<div class="dropdown">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search for a country..."
|
||||
placeholder="Search country..."
|
||||
bind:value={search}
|
||||
onfocus={() => { open = true; }}
|
||||
oninput={() => { open = true; selectedCountry = null; }}
|
||||
oninput={() => { open = true; selectedCountry = ''; }}
|
||||
onkeydown={handleKeydown}
|
||||
class="search-input"
|
||||
/>
|
||||
{#if open}
|
||||
{#if open && filtered.length > 0}
|
||||
<ul class="list" role="listbox">
|
||||
{#each filtered as country}
|
||||
{#each filtered as name}
|
||||
<li
|
||||
role="option"
|
||||
aria-selected={selectedCountry?.name === country.name}
|
||||
class:selected={selectedCountry?.name === country.name}
|
||||
onclick={() => select(country)}
|
||||
onkeydown={(e) => { if (e.key === 'Enter') select(country); }}
|
||||
aria-selected={selectedCountry === name}
|
||||
class:selected={selectedCountry === name}
|
||||
onmousedown={() => select(name)}
|
||||
tabindex="0"
|
||||
>
|
||||
{country.name}
|
||||
</li>
|
||||
>{name}</li>
|
||||
{/each}
|
||||
{#if filtered.length === 0}
|
||||
<li class="no-results">No countries found</li>
|
||||
{/if}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="continue-btn"
|
||||
disabled={!selectedCountry}
|
||||
onclick={handleSubmit}
|
||||
>
|
||||
Continue
|
||||
<button class="continue-btn" disabled={!selectedCountry} onclick={handleSubmit}>
|
||||
Set home country
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -96,113 +75,116 @@
|
||||
.overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(15, 23, 42, 0.85);
|
||||
background: var(--bg);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
backdrop-filter: blur(4px);
|
||||
padding-bottom: 20vh;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #1e2937;
|
||||
border-radius: 16px;
|
||||
padding: 40px 36px;
|
||||
text-align: center;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
|
||||
max-width: 420px;
|
||||
max-width: 360px;
|
||||
width: 90%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.heading {
|
||||
font: 700 24px/1.3 sans-serif;
|
||||
color: #f1f5f9;
|
||||
margin-bottom: 6px;
|
||||
.home-img {
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
object-fit: contain;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-family: var(--heading);
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: var(--text-h);
|
||||
letter-spacing: -0.5px;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font: 400 15px/1.4 sans-serif;
|
||||
color: #94a3b8;
|
||||
margin-bottom: 28px;
|
||||
font-family: var(--sans);
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
color: var(--text);
|
||||
margin: 0 0 24px;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: relative;
|
||||
margin-bottom: 24px;
|
||||
width: 100%;
|
||||
margin-bottom: 16px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid #475569;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: #0f172a;
|
||||
color: #f1f5f9;
|
||||
font: 400 15px/1.4 sans-serif;
|
||||
background: var(--bg-subtle);
|
||||
color: var(--text-h);
|
||||
font-family: var(--sans);
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
|
||||
.search-input::placeholder {
|
||||
color: #64748b;
|
||||
transition: border-color 0.15s;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.search-input:focus { border-color: var(--accent-border); }
|
||||
.search-input::placeholder { color: var(--text-sub); }
|
||||
|
||||
.list {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-height: 240px;
|
||||
max-height: 220px;
|
||||
overflow-y: auto;
|
||||
background: #0f172a;
|
||||
border: 1px solid #475569;
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
list-style: none;
|
||||
z-index: 10;
|
||||
padding: 4px;
|
||||
box-shadow: 0 4px 16px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.list li {
|
||||
padding: 10px 16px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
color: #cbd5e1;
|
||||
font: 400 14px/1.4 sans-serif;
|
||||
transition: background 0.15s;
|
||||
color: var(--text);
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
border-radius: 6px;
|
||||
transition: background 0.1s;
|
||||
}
|
||||
|
||||
.list li:hover,
|
||||
.list li.selected {
|
||||
background: #1e3a5f;
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
.no-results {
|
||||
color: #64748b;
|
||||
cursor: default;
|
||||
.list li:hover, .list li.selected {
|
||||
background: var(--accent-bg);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.continue-btn {
|
||||
width: 100%;
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
padding: 11px 24px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: #3b82f6;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font: 600 16px/1.4 sans-serif;
|
||||
font-family: var(--sans);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s, opacity 0.2s;
|
||||
}
|
||||
|
||||
.continue-btn:hover:not(:disabled) {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.continue-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: default;
|
||||
transition: background 0.15s, opacity 0.15s;
|
||||
}
|
||||
.continue-btn:hover:not(:disabled) { background: var(--accent-dark); }
|
||||
.continue-btn:disabled { opacity: 0.4; cursor: default; }
|
||||
</style>
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { initializeApp } from 'firebase/app';
|
||||
import { getAuth, GoogleAuthProvider } from 'firebase/auth';
|
||||
import { getFirestore } from 'firebase/firestore';
|
||||
import { getStorage } from 'firebase/storage';
|
||||
|
||||
const firebaseConfig = {
|
||||
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
|
||||
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
|
||||
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
|
||||
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
|
||||
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
|
||||
appId: import.meta.env.VITE_FIREBASE_APP_ID,
|
||||
};
|
||||
|
||||
export const app = initializeApp(firebaseConfig);
|
||||
export const auth = getAuth(app);
|
||||
export const db = getFirestore(app);
|
||||
export const storage = getStorage(app);
|
||||
export const googleProvider = new GoogleAuthProvider();
|
||||
@@ -1,7 +1,5 @@
|
||||
<script>
|
||||
import { getUser, getUserProfile, signOut } from '../auth/userStore.svelte.js';
|
||||
import logo1Img from '../../assets/logo-1.png';
|
||||
|
||||
let { screen, onNavigate } = $props();
|
||||
|
||||
let user = $derived(getUser());
|
||||
@@ -22,7 +20,6 @@
|
||||
<div class="topbar">
|
||||
<div class="left">
|
||||
<div class="brand">
|
||||
<img src={logo1Img} class="logo-img" alt="Journi logo" />
|
||||
<span class="app-name">Journi</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -34,7 +31,7 @@
|
||||
style="transform: translateX({screen === 'worldmap' ? 0 : 100}%);"
|
||||
></div>
|
||||
<button class:active={screen === 'worldmap'} onclick={() => onNavigate('worldmap')}>Worldmap</button>
|
||||
<button class:active={screen === 'timeline'} onclick={() => onNavigate('timeline')}>Timeline</button>
|
||||
<button class:active={screen === 'timeline'} onclick={() => onNavigate('timeline')}>Journal</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -93,12 +90,6 @@
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.logo-img {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.app-name {
|
||||
font-family: var(--heading);
|
||||
font-size: 22px;
|
||||
|
||||
@@ -3,8 +3,8 @@ import { nameToId } from '../shared/countries.js';
|
||||
|
||||
let selected = $state(new Set());
|
||||
let totalCountries = $state(0);
|
||||
let flashing = $state(new Set());
|
||||
|
||||
// Derive visited countries from journal entries
|
||||
journals.subscribe((entries) => {
|
||||
const ids = new Set();
|
||||
for (const e of entries) {
|
||||
@@ -25,3 +25,16 @@ export function setTotalCount(n) {
|
||||
export function getTotalCount() {
|
||||
return totalCountries;
|
||||
}
|
||||
|
||||
export function getFlashing() {
|
||||
return flashing;
|
||||
}
|
||||
|
||||
export function flashCountry(countryName) {
|
||||
const id = nameToId[countryName];
|
||||
if (!id) return;
|
||||
flashing = new Set([...flashing, id]);
|
||||
setTimeout(() => {
|
||||
flashing = new Set([...flashing].filter(x => x !== id));
|
||||
}, 1600);
|
||||
}
|
||||
|
||||
184
src/lib/shared/countryCities.js
Normal file
@@ -0,0 +1,184 @@
|
||||
export const countryCities = {
|
||||
'Afghanistan': ['Kabul','Kandahar','Herat','Mazar-i-Sharif','Jalalabad'],
|
||||
'Albania': ['Tirana','Durrës','Vlorë','Shkodër','Elbasan'],
|
||||
'Algeria': ['Algiers','Oran','Constantine','Annaba','Blida'],
|
||||
'Andorra': ['Andorra la Vella','Escaldes-Engordany','Encamp'],
|
||||
'Angola': ['Luanda','Huambo','Lobito','Benguela','Lubango'],
|
||||
'Argentina': ['Buenos Aires','Córdoba','Rosario','Mendoza','Bariloche','Salta','Mar del Plata'],
|
||||
'Armenia': ['Yerevan','Gyumri','Vanadzor'],
|
||||
'Australia': ['Sydney','Melbourne','Brisbane','Perth','Adelaide','Gold Coast','Cairns','Darwin','Hobart','Canberra'],
|
||||
'Austria': ['Vienna','Salzburg','Graz','Innsbruck','Linz','Hallstatt'],
|
||||
'Azerbaijan': ['Baku','Ganja','Sumqayit'],
|
||||
'Bahamas': ['Nassau','Freeport'],
|
||||
'Bahrain': ['Manama','Riffa','Muharraq'],
|
||||
'Bangladesh': ['Dhaka','Chittagong','Sylhet','Rajshahi','Khulna'],
|
||||
'Barbados': ['Bridgetown'],
|
||||
'Belarus': ['Minsk','Gomel','Brest','Grodno'],
|
||||
'Belgium': ['Brussels','Bruges','Ghent','Antwerp','Liège'],
|
||||
'Belize': ['Belize City','San Ignacio','Placencia'],
|
||||
'Benin': ['Cotonou','Porto-Novo','Abomey'],
|
||||
'Bhutan': ['Thimphu','Paro','Punakha'],
|
||||
'Bolivia': ['La Paz','Santa Cruz','Cochabamba','Sucre','Uyuni'],
|
||||
'Bosnia and Herz.': ['Sarajevo','Mostar','Banja Luka'],
|
||||
'Botswana': ['Gaborone','Francistown','Maun'],
|
||||
'Brazil': ['São Paulo','Rio de Janeiro','Brasília','Salvador','Fortaleza','Manaus','Recife','Florianópolis','Foz do Iguaçu'],
|
||||
'Brunei': ['Bandar Seri Begawan'],
|
||||
'Bulgaria': ['Sofia','Plovdiv','Varna','Burgas','Ruse'],
|
||||
'Burkina Faso': ['Ouagadougou','Bobo-Dioulasso'],
|
||||
'Burundi': ['Bujumbura','Gitega'],
|
||||
'Cabo Verde': ['Praia','Mindelo'],
|
||||
'Cambodia': ['Phnom Penh','Siem Reap','Sihanoukville','Battambang'],
|
||||
'Cameroon': ['Yaoundé','Douala','Bafoussam'],
|
||||
'Canada': ['Toronto','Vancouver','Montreal','Calgary','Ottawa','Edmonton','Quebec City','Whistler','Banff','Niagara Falls','Halifax'],
|
||||
'Central African Rep.': ['Bangui'],
|
||||
'Chad': ["N'Djamena",'Moundou'],
|
||||
'Chile': ['Santiago','Valparaíso','Atacama','Puerto Natales','Punta Arenas','Viña del Mar','San Pedro de Atacama'],
|
||||
'China': ['Beijing','Shanghai','Guangzhou','Shenzhen','Chengdu','Xi\'an','Hangzhou','Chongqing','Guilin','Zhangjiajie','Lijiang','Hong Kong','Macau'],
|
||||
'Colombia': ['Bogotá','Medellín','Cartagena','Cali','Santa Marta','Barranquilla'],
|
||||
'Comoros': ['Moroni'],
|
||||
'Congo': ['Brazzaville','Pointe-Noire'],
|
||||
'Costa Rica': ['San José','Manuel Antonio','Tamarindo','Arenal','Monteverde'],
|
||||
'Croatia': ['Zagreb','Dubrovnik','Split','Hvar','Zadar','Pula','Rijeka'],
|
||||
'Cuba': ['Havana','Trinidad','Varadero','Santiago de Cuba','Cienfuegos'],
|
||||
'Cyprus': ['Nicosia','Limassol','Paphos','Larnaca','Ayia Napa'],
|
||||
'Czechia': ['Prague','Brno','Český Krumlov','Karlovy Vary','Olomouc'],
|
||||
"Côte d'Ivoire": ['Abidjan','Yamoussoukro','Bouaké'],
|
||||
'Dem. Rep. Congo': ['Kinshasa','Lubumbashi','Goma','Kisangani'],
|
||||
'Denmark': ['Copenhagen','Aarhus','Odense','Aalborg'],
|
||||
'Djibouti': ['Djibouti City'],
|
||||
'Dominican Rep.': ['Santo Domingo','Punta Cana','Santiago','La Romana'],
|
||||
'Ecuador': ['Quito','Guayaquil','Cuenca','Baños','Galápagos Islands'],
|
||||
'Egypt': ['Cairo','Alexandria','Luxor','Aswan','Sharm el-Sheikh','Hurghada','Giza'],
|
||||
'El Salvador': ['San Salvador','Santa Ana','San Miguel'],
|
||||
'Eq. Guinea': ['Malabo','Bata'],
|
||||
'Eritrea': ['Asmara','Massawa'],
|
||||
'Estonia': ['Tallinn','Tartu','Pärnu'],
|
||||
'Ethiopia': ['Addis Ababa','Lalibela','Gondar','Axum','Dire Dawa'],
|
||||
'Fiji': ['Suva','Nadi','Mamanuca Islands'],
|
||||
'Finland': ['Helsinki','Rovaniemi','Tampere','Turku','Oulu'],
|
||||
'Fr. Polynesia': ['Papeete','Bora Bora','Moorea'],
|
||||
'France': ['Paris','Nice','Lyon','Marseille','Bordeaux','Strasbourg','Toulouse','Cannes','Monaco','Mont Saint-Michel','Versailles'],
|
||||
'Gabon': ['Libreville','Port-Gentil'],
|
||||
'Gambia': ['Banjul','Serekunda'],
|
||||
'Georgia': ['Tbilisi','Batumi','Kutaisi','Sighnaghi'],
|
||||
'Germany': ['Berlin','Munich','Hamburg','Frankfurt','Cologne','Dresden','Heidelberg','Rothenburg ob der Tauber','Neuschwanstein','Stuttgart'],
|
||||
'Ghana': ['Accra','Kumasi','Cape Coast','Tamale'],
|
||||
'Greece': ['Athens','Santorini','Mykonos','Rhodes','Thessaloniki','Crete','Corfu','Meteora'],
|
||||
'Greenland': ['Nuuk','Ilulissat'],
|
||||
'Grenada': ["St. George's"],
|
||||
'Guatemala': ['Guatemala City','Antigua','Lake Atitlán','Tikal','Quetzaltenango'],
|
||||
'Guinea': ['Conakry'],
|
||||
'Guyana': ['Georgetown'],
|
||||
'Haiti': ['Port-au-Prince','Cap-Haïtien'],
|
||||
'Honduras': ['Tegucigalpa','San Pedro Sula','Roatán'],
|
||||
'Hong Kong': ['Hong Kong'],
|
||||
'Hungary': ['Budapest','Debrecen','Pécs','Eger','Győr'],
|
||||
'Iceland': ['Reykjavik','Akureyri','Blue Lagoon','Golden Circle'],
|
||||
'India': ['Mumbai','Delhi','Jaipur','Agra','Bangalore','Chennai','Kolkata','Goa','Varanasi','Udaipur','Kerala','Leh','Shimla'],
|
||||
'Indonesia': ['Jakarta','Bali','Yogyakarta','Lombok','Medan','Komodo','Raja Ampat','Surabaya'],
|
||||
'Iran': ['Tehran','Isfahan','Shiraz','Persepolis','Yazd'],
|
||||
'Iraq': ['Baghdad','Erbil','Basra','Najaf'],
|
||||
'Ireland': ['Dublin','Cork','Galway','Killarney','Limerick'],
|
||||
'Israel': ['Jerusalem','Tel Aviv','Haifa','Eilat','Dead Sea'],
|
||||
'Italy': ['Rome','Florence','Venice','Milan','Naples','Amalfi','Sicily','Cinque Terre','Bologna','Turin'],
|
||||
'Jamaica': ['Kingston','Montego Bay','Negril','Ocho Rios'],
|
||||
'Japan': ['Tokyo','Kyoto','Osaka','Hiroshima','Nara','Sapporo','Hakone','Nikko','Kanazawa','Okinawa','Fukuoka'],
|
||||
'Jordan': ['Amman','Petra','Wadi Rum','Aqaba','Jerash'],
|
||||
'Kazakhstan': ['Almaty','Nur-Sultan','Shymkent'],
|
||||
'Kenya': ['Nairobi','Mombasa','Masai Mara','Amboseli','Zanzibar'],
|
||||
'Kosovo': ['Pristina','Prizren'],
|
||||
'Kuwait': ['Kuwait City'],
|
||||
'Kyrgyzstan': ['Bishkek','Osh','Karakol'],
|
||||
'Laos': ['Vientiane','Luang Prabang','Vang Vieng'],
|
||||
'Latvia': ['Riga','Jūrmala','Sigulda'],
|
||||
'Lebanon': ['Beirut','Byblos','Baalbek','Sidon'],
|
||||
'Libya': ['Tripoli','Benghazi','Leptis Magna'],
|
||||
'Liechtenstein': ['Vaduz'],
|
||||
'Lithuania': ['Vilnius','Kaunas','Trakai','Klaipėda'],
|
||||
'Luxembourg': ['Luxembourg City','Vianden'],
|
||||
'Madagascar': ['Antananarivo','Nosy Be','Morondava'],
|
||||
'Malawi': ['Lilongwe','Blantyre','Lake Malawi'],
|
||||
'Malaysia': ['Kuala Lumpur','Penang','Langkawi','Kota Kinabalu','Malacca','George Town'],
|
||||
'Maldives': ['Malé','Maafushi'],
|
||||
'Mali': ['Bamako','Timbuktu','Djenné'],
|
||||
'Malta': ['Valletta','Mdina','Gozo'],
|
||||
'Mauritania': ['Nouakchott'],
|
||||
'Mauritius': ['Port Louis','Grand Baie','Flic en Flac'],
|
||||
'Mexico': ['Mexico City','Cancún','Guadalajara','Oaxaca','Tulum','Playa del Carmen','San Miguel de Allende','Monterrey','Chichen Itza'],
|
||||
'Moldova': ['Chișinău'],
|
||||
'Monaco': ['Monaco'],
|
||||
'Mongolia': ['Ulaanbaatar','Gobi Desert'],
|
||||
'Montenegro': ['Podgorica','Kotor','Budva','Bar'],
|
||||
'Morocco': ['Marrakech','Fes','Casablanca','Rabat','Chefchaouen','Essaouira','Sahara Desert'],
|
||||
'Mozambique': ['Maputo','Beira','Pemba'],
|
||||
'Myanmar': ['Yangon','Bagan','Mandalay','Inle Lake'],
|
||||
'Namibia': ['Windhoek','Swakopmund','Etosha','Sossusvlei'],
|
||||
'Nepal': ['Kathmandu','Pokhara','Everest Base Camp','Chitwan','Lumbini'],
|
||||
'Netherlands': ['Amsterdam','Rotterdam','The Hague','Utrecht','Delft','Eindhoven'],
|
||||
'New Zealand': ['Auckland','Queenstown','Wellington','Christchurch','Rotorua','Milford Sound'],
|
||||
'Nicaragua': ['Managua','Granada','León'],
|
||||
'Niger': ['Niamey','Agadez'],
|
||||
'Nigeria': ['Lagos','Abuja','Kano','Ibadan'],
|
||||
'North Korea': ['Pyongyang'],
|
||||
'North Macedonia': ['Skopje','Ohrid'],
|
||||
'Norway': ['Oslo','Bergen','Tromsø','Flåm','Ålesund','Stavanger'],
|
||||
'Oman': ['Muscat','Nizwa','Salalah','Wahiba Sands'],
|
||||
'Pakistan': ['Karachi','Lahore','Islamabad','Peshawar','Gilgit'],
|
||||
'Palestine': ['Ramallah','Bethlehem','Jericho','Hebron'],
|
||||
'Panama': ['Panama City','Bocas del Toro','Boquete'],
|
||||
'Papua New Guinea': ['Port Moresby'],
|
||||
'Paraguay': ['Asunción','Ciudad del Este'],
|
||||
'Peru': ['Lima','Cusco','Machu Picchu','Arequipa','Puno','Iquitos'],
|
||||
'Philippines': ['Manila','Cebu','Palawan','Boracay','Davao','Siargao'],
|
||||
'Poland': ['Warsaw','Kraków','Gdańsk','Wrocław','Poznań','Zakopane'],
|
||||
'Portugal': ['Lisbon','Porto','Algarve','Sintra','Madeira','Azores','Évora'],
|
||||
'Puerto Rico': ['San Juan','Ponce','Rincon'],
|
||||
'Qatar': ['Doha'],
|
||||
'Romania': ['Bucharest','Transylvania','Cluj-Napoca','Sibiu','Brașov','Sinaia'],
|
||||
'Russia': ['Moscow','St. Petersburg','Irkutsk','Vladivostok','Sochi','Kazan','Novosibirsk'],
|
||||
'Rwanda': ['Kigali','Volcanoes National Park'],
|
||||
'S. Sudan': ['Juba'],
|
||||
'Saint Lucia': ['Castries','Soufrière'],
|
||||
'Saudi Arabia': ['Riyadh','Jeddah','Mecca','Medina','AlUla','NEOM'],
|
||||
'Senegal': ['Dakar','Saint-Louis','Ziguinchor'],
|
||||
'Serbia': ['Belgrade','Novi Sad','Niš'],
|
||||
'Seychelles': ['Victoria','La Digue','Praslin','Mahé'],
|
||||
'Sierra Leone': ['Freetown'],
|
||||
'Singapore': ['Singapore'],
|
||||
'Slovakia': ['Bratislava','Košice','Banská Bystrica'],
|
||||
'Slovenia': ['Ljubljana','Bled','Piran','Maribor'],
|
||||
'Solomon Is.': ['Honiara'],
|
||||
'Somalia': ['Mogadishu'],
|
||||
'South Africa': ['Cape Town','Johannesburg','Durban','Stellenbosch','Kruger','Garden Route','Pretoria'],
|
||||
'South Korea': ['Seoul','Busan','Jeju','Gyeongju','Incheon','Suwon'],
|
||||
'Spain': ['Barcelona','Madrid','Seville','Granada','Valencia','Bilbao','Toledo','San Sebastián','Ibiza','Mallorca'],
|
||||
'Sri Lanka': ['Colombo','Kandy','Galle','Ella','Sigiriya','Mirissa'],
|
||||
'Sudan': ['Khartoum','Omdurman'],
|
||||
'Suriname': ['Paramaribo'],
|
||||
'Sweden': ['Stockholm','Gothenburg','Malmö','Uppsala','Kiruna'],
|
||||
'Switzerland': ['Zurich','Geneva','Bern','Interlaken','Lucerne','Zermatt','Lugano','Grindelwald'],
|
||||
'Syria': ['Damascus','Aleppo','Palmyra'],
|
||||
'São Tomé and Príncipe': ['São Tomé'],
|
||||
'Taiwan': ['Taipei','Kaohsiung','Tainan','Taichung'],
|
||||
'Tajikistan': ['Dushanbe','Khujand'],
|
||||
'Tanzania': ['Dar es Salaam','Zanzibar','Serengeti','Arusha','Kilimanjaro'],
|
||||
'Thailand': ['Bangkok','Chiang Mai','Phuket','Koh Samui','Koh Phi Phi','Ayutthaya','Pai','Krabi'],
|
||||
'Timor-Leste': ['Dili'],
|
||||
'Togo': ['Lomé'],
|
||||
'Trinidad and Tobago': ['Port of Spain'],
|
||||
'Tunisia': ['Tunis','Carthage','Sousse','Hammamet','Djerba'],
|
||||
'Turkey': ['Istanbul','Cappadocia','Antalya','Bodrum','Ankara','Ephesus','Pamukkale','Trabzon'],
|
||||
'Turkmenistan': ['Ashgabat','Merv'],
|
||||
'Uganda': ['Kampala','Bwindi','Jinja'],
|
||||
'Ukraine': ['Kyiv','Lviv','Odessa','Kharkiv'],
|
||||
'United Arab Emirates': ['Dubai','Abu Dhabi','Sharjah'],
|
||||
'United Kingdom': ['London','Edinburgh','Manchester','Liverpool','Oxford','Cambridge','Bath','York','Brighton','Glasgow','Dublin'],
|
||||
'United States of America': ['New York','Los Angeles','Chicago','Miami','San Francisco','Las Vegas','New Orleans','Seattle','Boston','Washington D.C.','Nashville','Denver','Honolulu','Anchorage','Portland'],
|
||||
'Uruguay': ['Montevideo','Punta del Este','Colonia del Sacramento'],
|
||||
'Uzbekistan': ['Tashkent','Samarkand','Bukhara','Khiva'],
|
||||
'Venezuela': ['Caracas','Medellín','Canaima','Los Roques'],
|
||||
'Vietnam': ['Hanoi','Ho Chi Minh City','Hoi An','Da Nang','Ha Long Bay','Hue','Sapa','Phu Quoc'],
|
||||
'Yemen': ["Sana'a",'Aden'],
|
||||
'Zambia': ['Lusaka','Livingstone','Victoria Falls'],
|
||||
'Zimbabwe': ['Harare','Bulawayo','Victoria Falls'],
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
import { db } from '../firebase.js';
|
||||
import { collection, doc, onSnapshot, query, orderBy, addDoc, updateDoc, deleteDoc, serverTimestamp } from 'firebase/firestore';
|
||||
|
||||
let entries = $state([]);
|
||||
let _uid = null;
|
||||
let _unsubscribe = null;
|
||||
|
||||
export function getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
export function initEntriesListener(uid) {
|
||||
if (_unsubscribe) _unsubscribe();
|
||||
_uid = uid;
|
||||
const q = query(
|
||||
collection(db, 'users', uid, 'entries'),
|
||||
orderBy('createdAt', 'desc')
|
||||
);
|
||||
_unsubscribe = onSnapshot(q, (snap) => {
|
||||
entries = snap.docs.map((d) => ({ id: d.id, ...d.data() }));
|
||||
});
|
||||
}
|
||||
|
||||
export async function addEntry(data) {
|
||||
if (!_uid) return null;
|
||||
const ref = await addDoc(collection(db, 'users', _uid, 'entries'), {
|
||||
...data,
|
||||
createdAt: serverTimestamp(),
|
||||
updatedAt: serverTimestamp(),
|
||||
});
|
||||
return ref.id;
|
||||
}
|
||||
|
||||
export async function updateEntry(id, data) {
|
||||
if (!_uid) return;
|
||||
await updateDoc(doc(db, 'users', _uid, 'entries', id), {
|
||||
...data,
|
||||
updatedAt: serverTimestamp(),
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeEntry(id) {
|
||||
if (!_uid) return;
|
||||
await deleteDoc(doc(db, 'users', _uid, 'entries', id));
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export function initEntriesListener(uid) {
|
||||
}
|
||||
|
||||
export async function addEntry(data) {
|
||||
if (!_uid) return null;
|
||||
if (!_uid) throw new Error('Not logged in');
|
||||
const ref = await addDoc(collection(db, 'users', _uid, 'entries'), {
|
||||
...data,
|
||||
createdAt: serverTimestamp(),
|
||||
|
||||
@@ -1,454 +0,0 @@
|
||||
<script>
|
||||
import { get } from 'svelte/store';
|
||||
import { journals, addJournal } from '../stores/journalStore.js';
|
||||
import { countryNames } from '../shared/countries.js';
|
||||
import SearchInput from '../shared/SearchInput.svelte';
|
||||
import PhotoEditor from './PhotoEditor.svelte';
|
||||
|
||||
let { initialCountry = '', onBack } = $props();
|
||||
|
||||
// ── Fields ─────────────────────────────────────────────────────────
|
||||
let cities = $state([]);
|
||||
let cityInput = $state('');
|
||||
let country = $state(initialCountry);
|
||||
let date = $state(new Date().toISOString().slice(0, 10));
|
||||
let days = $state('');
|
||||
let tripType = $state('');
|
||||
let transport = $state('');
|
||||
let photos = $state([]);
|
||||
let answers = $state(['', '', '']);
|
||||
|
||||
let errors = $state({ country: '', cities: '', date: '', days: '', tripType: '', transport: '' });
|
||||
|
||||
// ── Steps ──────────────────────────────────────────────────────────
|
||||
let step = $state(1); // 1 | 2 | 3
|
||||
|
||||
// ── Random questions ───────────────────────────────────────────────
|
||||
const ALL_QUESTIONS = [
|
||||
'If this trip had a movie title, what would it be?',
|
||||
'What was the most unexpected thing that happened?',
|
||||
'Which moment would you relive for just 10 more minutes?',
|
||||
'What was your best accidental discovery?\n(A café, a street, a person, a view…)',
|
||||
'If your trip had a theme song, what would it sound like?',
|
||||
'What did you pack but never use?',
|
||||
'What was the smallest thing that made you surprisingly happy?',
|
||||
'If you could steal one thing from this place (without consequences), what would it be?\n(A tradition, a smell, a sunset, a food…)',
|
||||
'What story from this trip will you probably tell your friends first?',
|
||||
'What version of yourself showed up on this trip?',
|
||||
];
|
||||
|
||||
function pickRandom() {
|
||||
const shuffled = [...ALL_QUESTIONS].sort(() => Math.random() - 0.5);
|
||||
return shuffled.slice(0, 3);
|
||||
}
|
||||
|
||||
const questions = pickRandom();
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────
|
||||
// Suggest cities — if a country is selected, show cities only from that country;
|
||||
// otherwise show all known cities.
|
||||
let cityOptions = $derived(
|
||||
country.trim()
|
||||
? [...new Set(get(journals).filter(j => (j.location.country || '').toLowerCase() === country.trim().toLowerCase()).flatMap(e => e.location.cities))].sort()
|
||||
: [...new Set(get(journals).flatMap(e => e.location.cities))].sort()
|
||||
);
|
||||
|
||||
function addCity(val) {
|
||||
const t = (val ?? cityInput).trim();
|
||||
if (t && !cities.includes(t)) cities = [...cities, t];
|
||||
cityInput = '';
|
||||
}
|
||||
|
||||
function removeCity(c) { cities = cities.filter(x => x !== c); }
|
||||
|
||||
$effect(() => { if (country.trim()) errors.country = ''; });
|
||||
$effect(() => { if (cities.length > 0) errors.cities = ''; });
|
||||
$effect(() => { if (date) errors.date = ''; });
|
||||
$effect(() => { if (days && Number(days) >= 1) errors.days = ''; });
|
||||
$effect(() => { if (tripType) errors.tripType = ''; });
|
||||
$effect(() => { if (transport) errors.transport = ''; });
|
||||
|
||||
const transportOptions = [
|
||||
{ value: 'flight', label: '✈ Flight' },
|
||||
{ value: 'train', label: '🚂 Train' },
|
||||
{ value: 'bus', label: '🚌 Bus' },
|
||||
{ value: 'car', label: '🚗 Car' },
|
||||
{ value: 'ship', label: '🚢 Ship' },
|
||||
{ value: 'walk', label: '🚶 Walk' },
|
||||
];
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────
|
||||
function nextStep() {
|
||||
if (step === 1) {
|
||||
errors = { country: '', cities: '', date: '', days: '', tripType: '', transport: '' };
|
||||
let hasError = false;
|
||||
if (!country.trim()) { errors.country = 'Country is required.'; hasError = true; }
|
||||
if (cities.length === 0) { errors.cities = 'Add at least one city.'; hasError = true; }
|
||||
if (!date) { errors.date = 'Date is required.'; hasError = true; }
|
||||
if (!days || Number(days) < 1) { errors.days = 'Enter a valid number of days.'; hasError = true; }
|
||||
if (!tripType) { errors.tripType = 'Select a trip type.'; hasError = true; }
|
||||
if (!transport) { errors.transport = 'Select how you got there.'; hasError = true; }
|
||||
if (hasError) return;
|
||||
}
|
||||
step++;
|
||||
}
|
||||
|
||||
function prevStep() {
|
||||
if (step === 1) onBack();
|
||||
else step--;
|
||||
}
|
||||
|
||||
// ── Save ───────────────────────────────────────────────────────────
|
||||
let saving = $state(false);
|
||||
|
||||
async function save() {
|
||||
saving = true;
|
||||
const memo = questions
|
||||
.map((q, i) => answers[i].trim() ? `Q: ${q.split('\n')[0]}\nA: ${answers[i].trim()}` : '')
|
||||
.filter(Boolean)
|
||||
.join('\n\n');
|
||||
try {
|
||||
await addJournal({
|
||||
title: `${cities.join(', ')}, ${country}`,
|
||||
date,
|
||||
days: Number(days),
|
||||
tripType,
|
||||
transport,
|
||||
memo,
|
||||
photos,
|
||||
location: { cities, country },
|
||||
});
|
||||
onBack();
|
||||
} catch {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="layout">
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="ghost-btn" onclick={prevStep}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M19 12H5M12 5l-7 7 7 7"/></svg>
|
||||
{step === 1 ? 'Back' : 'Previous'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="steps">
|
||||
{#each [1,2,3] as s}
|
||||
<div class="step-dot" class:active={step === s} class:done={step > s}></div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="topbar-right">
|
||||
{#if step < 3}
|
||||
<button class="save-btn" onclick={nextStep}>Next</button>
|
||||
{:else}
|
||||
<button class="save-btn" onclick={save} disabled={saving}>
|
||||
{saving ? 'Saving…' : 'Save trip'}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="scroll">
|
||||
<div class="form">
|
||||
|
||||
{#if step === 1}
|
||||
<!-- ── STEP 1: Details ── -->
|
||||
<h2 class="step-title">Trip details</h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label class="label" for="nc-country">Country <span class="req">*</span></label>
|
||||
<SearchInput id="nc-country" bind:value={country} options={countryNames} />
|
||||
{#if errors.country}<span class="ferr">{errors.country}</span>{/if}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="nc-city">Cities <span class="req">*</span></label>
|
||||
<SearchInput id="nc-city" bind:value={cityInput} options={cityOptions} onselect={addCity} />
|
||||
{#if errors.cities}<span class="ferr">{errors.cities}</span>{/if}
|
||||
{#if cities.length > 0}
|
||||
<div class="tags">
|
||||
{#each cities as c}
|
||||
<span class="tag">{c}<button type="button" class="tag-rm" onclick={() => removeCity(c)}>×</button></span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label class="label" for="nc-date">Date <span class="req">*</span></label>
|
||||
<input id="nc-date" class="input" type="date" bind:value={date} />
|
||||
{#if errors.date}<span class="ferr">{errors.date}</span>{/if}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="nc-days">Days <span class="req">*</span></label>
|
||||
<input id="nc-days" class="input" type="number" min="1" bind:value={days} />
|
||||
{#if errors.days}<span class="ferr">{errors.days}</span>{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label">Trip type <span class="req">*</span></label>
|
||||
<div class="toggle-row">
|
||||
{#each ['solo','friends','family'] as t}
|
||||
<label class="toggle-opt" class:active={tripType === t}>
|
||||
<input type="radio" name="nc-tripType" value={t} bind:group={tripType} />
|
||||
{t === 'solo' ? 'Solo' : t === 'friends' ? 'With friends' : 'With family'}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{#if errors.tripType}<span class="ferr">{errors.tripType}</span>{/if}
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label">How did you get there? <span class="req">*</span></label>
|
||||
<div class="transport-grid">
|
||||
{#each transportOptions as opt}
|
||||
<label class="transport-opt" class:active={transport === opt.value}>
|
||||
<input type="radio" name="nc-transport" value={opt.value} bind:group={transport} />
|
||||
{opt.label}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{#if errors.transport}<span class="ferr">{errors.transport}</span>{/if}
|
||||
</div>
|
||||
|
||||
{:else if step === 2}
|
||||
<!-- ── STEP 2: Photos ── -->
|
||||
<h2 class="step-title">Photos</h2>
|
||||
<p class="step-sub">Optional — add photos from your trip</p>
|
||||
<PhotoEditor {photos} onchange={(p) => (photos = p)} />
|
||||
|
||||
{:else}
|
||||
<!-- ── STEP 3: Questions ── -->
|
||||
<h2 class="step-title">Your memories</h2>
|
||||
|
||||
{#each questions as q, i}
|
||||
<div class="q-card">
|
||||
<p class="q-text">{q}</p>
|
||||
<textarea class="q-input" rows="3" placeholder="Your answer…" bind:value={answers[i]}></textarea>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background: var(--bg);
|
||||
font-family: var(--sans);
|
||||
}
|
||||
|
||||
/* topbar */
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 20px;
|
||||
height: 52px;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--bg);
|
||||
}
|
||||
.topbar-left, .topbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 110px;
|
||||
}
|
||||
.topbar-right { justify-content: flex-end; }
|
||||
|
||||
.steps {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.step-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--border);
|
||||
transition: background 0.2s, transform 0.2s;
|
||||
}
|
||||
.step-dot.active {
|
||||
background: var(--accent);
|
||||
transform: scale(1.25);
|
||||
}
|
||||
.step-dot.done {
|
||||
background: var(--accent);
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
.ghost-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: var(--text);
|
||||
background: none;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
padding: 6px 10px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
}
|
||||
.ghost-btn:hover { background: var(--bg-subtle); border-color: var(--border); color: var(--text-h); }
|
||||
|
||||
.save-btn {
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: #fff;
|
||||
background: var(--accent);
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: 8px;
|
||||
padding: 7px 14px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.save-btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
|
||||
.save-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
|
||||
/* scroll + form */
|
||||
.scroll { flex: 1; overflow-y: auto; }
|
||||
|
||||
.form {
|
||||
max-width: 560px;
|
||||
margin: 0 auto;
|
||||
padding: 36px 48px 80px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.step-title {
|
||||
font-size: 20px;
|
||||
font-weight: 400;
|
||||
color: var(--text-h);
|
||||
letter-spacing: -0.3px;
|
||||
margin: 0 0 2px;
|
||||
}
|
||||
.step-sub {
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: var(--text-sub);
|
||||
margin: -10px 0 4px;
|
||||
}
|
||||
|
||||
/* fields (same as EditForm) */
|
||||
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
|
||||
|
||||
.field { display: flex; flex-direction: column; gap: 6px; }
|
||||
|
||||
.label {
|
||||
font-size: 11px;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-sub);
|
||||
}
|
||||
.req { color: var(--accent); font-size: 11px; }
|
||||
|
||||
.ferr { font-size: 11px; color: #dc2626; }
|
||||
|
||||
.input {
|
||||
font-family: var(--sans);
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
color: var(--text-h);
|
||||
background: var(--bg-subtle);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.input:focus { border-color: var(--accent-border); }
|
||||
|
||||
.toggle-row { display: flex; gap: 8px; }
|
||||
.toggle-opt {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
font-size: 13px; font-weight: 300; color: var(--text);
|
||||
padding: 7px 14px; border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
|
||||
background: var(--bg-subtle);
|
||||
}
|
||||
.toggle-opt input { display: none; }
|
||||
.toggle-opt.active { border-color: var(--accent-border); background: var(--accent-bg); color: var(--accent); }
|
||||
|
||||
.transport-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
|
||||
.transport-opt {
|
||||
display: flex; align-items: center; justify-content: center; gap: 6px;
|
||||
font-size: 13px; font-weight: 300; color: var(--text);
|
||||
padding: 8px 10px; border-radius: 8px;
|
||||
border: 1px solid var(--border); background: var(--bg-subtle);
|
||||
cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.transport-opt input { display: none; }
|
||||
.transport-opt.active { border-color: var(--accent-border); background: var(--accent-bg); color: var(--accent); }
|
||||
|
||||
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
|
||||
.tag {
|
||||
display: inline-flex; align-items: center; gap: 4px;
|
||||
font-size: 12px; font-weight: 300; color: var(--accent);
|
||||
background: var(--accent-bg); border: 1px solid var(--accent-border);
|
||||
border-radius: 20px; padding: 3px 10px 3px 12px;
|
||||
}
|
||||
.tag-rm {
|
||||
background: none; border: none; color: var(--accent);
|
||||
font-size: 15px; line-height: 1; cursor: pointer; padding: 0; opacity: 0.6;
|
||||
}
|
||||
.tag-rm:hover { opacity: 1; }
|
||||
|
||||
/* question cards */
|
||||
.q-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
background: var(--bg-subtle);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
}
|
||||
.q-text {
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
color: var(--text-h);
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
white-space: pre-line;
|
||||
}
|
||||
.q-input {
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: var(--text-h);
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
outline: none;
|
||||
resize: none;
|
||||
line-height: 1.6;
|
||||
transition: border-color 0.15s;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.q-input:focus { border-color: var(--accent-border); }
|
||||
.q-input::placeholder { color: var(--text-sub); font-style: italic; }
|
||||
</style>
|
||||
@@ -1,465 +0,0 @@
|
||||
<script>
|
||||
import { get } from 'svelte/store';
|
||||
import { journals, addJournal } from '../stores/journalStore.js';
|
||||
import { countryNames } from '../shared/countries.js';
|
||||
import SearchInput from '../shared/SearchInput.svelte';
|
||||
import PhotoEditor from './PhotoEditor.svelte';
|
||||
import airplaneImg from '../../assets/airplane.png';
|
||||
import trainImg from '../../assets/train.png';
|
||||
import busImg from '../../assets/bus.png';
|
||||
import carImg from '../../assets/car.png';
|
||||
import shipImg from '../../assets/ship.png';
|
||||
import walkImg from '../../assets/walk.png';
|
||||
|
||||
let { initialCountry = '', onBack } = $props();
|
||||
|
||||
// ── Fields ─────────────────────────────────────────────────────────
|
||||
let cities = $state([]);
|
||||
let cityInput = $state('');
|
||||
let country = $state(initialCountry);
|
||||
let date = $state(new Date().toISOString().slice(0, 10));
|
||||
let days = $state('');
|
||||
let tripType = $state('');
|
||||
let transport = $state('');
|
||||
let photos = $state([]);
|
||||
let answers = $state(['', '', '']);
|
||||
|
||||
let errors = $state({ country: '', cities: '', date: '', days: '', tripType: '', transport: '' });
|
||||
|
||||
// ── Steps ──────────────────────────────────────────────────────────
|
||||
let step = $state(1); // 1 | 2 | 3
|
||||
|
||||
// ── Random questions ───────────────────────────────────────────────
|
||||
const ALL_QUESTIONS = [
|
||||
'If this trip had a movie title, what would it be?',
|
||||
'What was the most unexpected thing that happened?',
|
||||
'Which moment would you relive for just 10 more minutes?',
|
||||
'What was your best accidental discovery?\n(A café, a street, a person, a view…)',
|
||||
'If your trip had a theme song, what would it sound like?',
|
||||
'What did you pack but never use?',
|
||||
'What was the smallest thing that made you surprisingly happy?',
|
||||
'If you could steal one thing from this place (without consequences), what would it be?\n(A tradition, a smell, a sunset, a food…)',
|
||||
'What story from this trip will you probably tell your friends first?',
|
||||
'What version of yourself showed up on this trip?',
|
||||
];
|
||||
|
||||
function pickRandom() {
|
||||
const shuffled = [...ALL_QUESTIONS].sort(() => Math.random() - 0.5);
|
||||
return shuffled.slice(0, 3);
|
||||
}
|
||||
|
||||
const questions = pickRandom();
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────
|
||||
// Suggest cities — if a country is selected, show cities only from that country;
|
||||
// otherwise show all known cities.
|
||||
let cityOptions = $derived(
|
||||
country.trim()
|
||||
? [...new Set(get(journals).filter(j => (j.location.country || '').toLowerCase() === country.trim().toLowerCase()).flatMap(e => e.location.cities))].sort()
|
||||
: [...new Set(get(journals).flatMap(e => e.location.cities))].sort()
|
||||
);
|
||||
|
||||
function addCity(val) {
|
||||
const t = (val ?? cityInput).trim();
|
||||
if (t && !cities.includes(t)) cities = [...cities, t];
|
||||
cityInput = '';
|
||||
}
|
||||
|
||||
function removeCity(c) { cities = cities.filter(x => x !== c); }
|
||||
|
||||
$effect(() => { if (country.trim()) errors.country = ''; });
|
||||
$effect(() => { if (cities.length > 0) errors.cities = ''; });
|
||||
$effect(() => { if (date) errors.date = ''; });
|
||||
$effect(() => { if (days && Number(days) >= 1) errors.days = ''; });
|
||||
$effect(() => { if (tripType) errors.tripType = ''; });
|
||||
$effect(() => { if (transport) errors.transport = ''; });
|
||||
|
||||
const transportOptions = [
|
||||
{ value: 'flight', label: 'Flight', img: airplaneImg },
|
||||
{ value: 'train', label: 'Train', img: trainImg },
|
||||
{ value: 'bus', label: 'Bus', img: busImg },
|
||||
{ value: 'car', label: 'Car', img: carImg },
|
||||
{ value: 'ship', label: 'Ship', img: shipImg },
|
||||
{ value: 'walk', label: 'Walk', img: walkImg },
|
||||
];
|
||||
|
||||
// ── Navigation ─────────────────────────────────────────────────────
|
||||
function nextStep() {
|
||||
if (step === 1) {
|
||||
errors = { country: '', cities: '', date: '', days: '', tripType: '', transport: '' };
|
||||
let hasError = false;
|
||||
if (!country.trim()) { errors.country = 'Country is required.'; hasError = true; }
|
||||
if (cities.length === 0) { errors.cities = 'Add at least one city.'; hasError = true; }
|
||||
if (!date) { errors.date = 'Date is required.'; hasError = true; }
|
||||
if (!days || Number(days) < 1) { errors.days = 'Enter a valid number of days.'; hasError = true; }
|
||||
if (!tripType) { errors.tripType = 'Select a trip type.'; hasError = true; }
|
||||
if (!transport) { errors.transport = 'Select how you got there.'; hasError = true; }
|
||||
if (hasError) return;
|
||||
}
|
||||
step++;
|
||||
}
|
||||
|
||||
function prevStep() {
|
||||
if (step === 1) onBack();
|
||||
else step--;
|
||||
}
|
||||
|
||||
// ── Save ───────────────────────────────────────────────────────────
|
||||
let saving = $state(false);
|
||||
|
||||
async function save() {
|
||||
saving = true;
|
||||
const memo = questions
|
||||
.map((q, i) => answers[i].trim() ? `Q: ${q.split('\n')[0]}\nA: ${answers[i].trim()}` : '')
|
||||
.filter(Boolean)
|
||||
.join('\n\n');
|
||||
try {
|
||||
await addJournal({
|
||||
title: `${cities.join(', ')}, ${country}`,
|
||||
date,
|
||||
days: Number(days),
|
||||
tripType,
|
||||
transport,
|
||||
memo,
|
||||
photos,
|
||||
location: { cities, country },
|
||||
});
|
||||
onBack();
|
||||
} catch {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="layout">
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="ghost-btn" onclick={prevStep}>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M19 12H5M12 5l-7 7 7 7"/></svg>
|
||||
{step === 1 ? 'Back' : 'Previous'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="steps">
|
||||
{#each [1,2,3] as s}
|
||||
<div class="step-dot" class:active={step === s} class:done={step > s}></div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="topbar-right">
|
||||
{#if step < 3}
|
||||
<button class="save-btn" onclick={nextStep}>Next</button>
|
||||
{:else}
|
||||
<button class="save-btn" onclick={save} disabled={saving}>
|
||||
{saving ? 'Saving…' : 'Save trip'}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="scroll">
|
||||
<div class="form">
|
||||
|
||||
{#if step === 1}
|
||||
<!-- ── STEP 1: Details ── -->
|
||||
<h2 class="step-title">Trip details</h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label class="label" for="nc-country">Country <span class="req">*</span></label>
|
||||
<SearchInput id="nc-country" bind:value={country} options={countryNames} />
|
||||
{#if errors.country}<span class="ferr">{errors.country}</span>{/if}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="nc-city">Cities <span class="req">*</span></label>
|
||||
<SearchInput id="nc-city" bind:value={cityInput} options={cityOptions} onselect={addCity} />
|
||||
{#if errors.cities}<span class="ferr">{errors.cities}</span>{/if}
|
||||
{#if cities.length > 0}
|
||||
<div class="tags">
|
||||
{#each cities as c}
|
||||
<span class="tag">{c}<button type="button" class="tag-rm" onclick={() => removeCity(c)}>×</button></span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label class="label" for="nc-date">Date <span class="req">*</span></label>
|
||||
<input id="nc-date" class="input" type="date" bind:value={date} />
|
||||
{#if errors.date}<span class="ferr">{errors.date}</span>{/if}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="nc-days">Days <span class="req">*</span></label>
|
||||
<input id="nc-days" class="input" type="number" min="1" bind:value={days} />
|
||||
{#if errors.days}<span class="ferr">{errors.days}</span>{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label">Trip type <span class="req">*</span></label>
|
||||
<div class="toggle-row">
|
||||
{#each ['solo','friends','family'] as t}
|
||||
<label class="toggle-opt" class:active={tripType === t}>
|
||||
<input type="radio" name="nc-tripType" value={t} bind:group={tripType} />
|
||||
{t === 'solo' ? 'Solo' : t === 'friends' ? 'With friends' : 'With family'}
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{#if errors.tripType}<span class="ferr">{errors.tripType}</span>{/if}
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label">How did you get there? <span class="req">*</span></label>
|
||||
<div class="transport-grid">
|
||||
{#each transportOptions as opt}
|
||||
<label class="transport-opt" class:active={transport === opt.value}>
|
||||
<input type="radio" name="nc-transport" value={opt.value} bind:group={transport} />
|
||||
<img src={opt.img} alt={opt.label} class="transport-img" />
|
||||
<span class="transport-label">{opt.label}</span>
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{#if errors.transport}<span class="ferr">{errors.transport}</span>{/if}
|
||||
</div>
|
||||
|
||||
{:else if step === 2}
|
||||
<!-- ── STEP 2: Photos ── -->
|
||||
<h2 class="step-title">Photos</h2>
|
||||
<p class="step-sub">Optional — add photos from your trip</p>
|
||||
<PhotoEditor {photos} onchange={(p) => (photos = p)} />
|
||||
|
||||
{:else}
|
||||
<!-- ── STEP 3: Questions ── -->
|
||||
<h2 class="step-title">Your memories</h2>
|
||||
|
||||
{#each questions as q, i}
|
||||
<div class="q-card">
|
||||
<p class="q-text">{q}</p>
|
||||
<textarea class="q-input" rows="3" placeholder="Your answer…" bind:value={answers[i]}></textarea>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background: var(--bg);
|
||||
font-family: var(--sans);
|
||||
}
|
||||
|
||||
/* topbar */
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 20px;
|
||||
height: 52px;
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--bg);
|
||||
}
|
||||
.topbar-left, .topbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 110px;
|
||||
}
|
||||
.topbar-right { justify-content: flex-end; }
|
||||
|
||||
.steps {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
.step-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--border);
|
||||
transition: background 0.2s, transform 0.2s;
|
||||
}
|
||||
.step-dot.active {
|
||||
background: var(--accent);
|
||||
transform: scale(1.25);
|
||||
}
|
||||
.step-dot.done {
|
||||
background: var(--accent);
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
.ghost-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: var(--text);
|
||||
background: none;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
padding: 6px 10px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
}
|
||||
.ghost-btn:hover { background: var(--bg-subtle); border-color: var(--border); color: var(--text-h); }
|
||||
|
||||
.save-btn {
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: #fff;
|
||||
background: var(--accent);
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: 8px;
|
||||
padding: 7px 14px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.save-btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
|
||||
.save-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
|
||||
/* scroll + form */
|
||||
.scroll { flex: 1; overflow-y: auto; }
|
||||
|
||||
.form {
|
||||
max-width: 560px;
|
||||
margin: 0 auto;
|
||||
padding: 36px 48px 80px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.step-title {
|
||||
font-size: 20px;
|
||||
font-weight: 400;
|
||||
color: var(--text-h);
|
||||
letter-spacing: -0.3px;
|
||||
margin: 0 0 2px;
|
||||
}
|
||||
.step-sub {
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: var(--text-sub);
|
||||
margin: -10px 0 4px;
|
||||
}
|
||||
|
||||
/* fields (same as EditForm) */
|
||||
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
|
||||
|
||||
.field { display: flex; flex-direction: column; gap: 6px; }
|
||||
|
||||
.label {
|
||||
font-size: 11px;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-sub);
|
||||
}
|
||||
.req { color: var(--accent); font-size: 11px; }
|
||||
|
||||
.ferr { font-size: 11px; color: #dc2626; }
|
||||
|
||||
.input {
|
||||
font-family: var(--sans);
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
color: var(--text-h);
|
||||
background: var(--bg-subtle);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.input:focus { border-color: var(--accent-border); }
|
||||
|
||||
.toggle-row { display: flex; gap: 8px; }
|
||||
.toggle-opt {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
font-size: 13px; font-weight: 300; color: var(--text);
|
||||
padding: 7px 14px; border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
|
||||
background: var(--bg-subtle);
|
||||
}
|
||||
.toggle-opt input { display: none; }
|
||||
.toggle-opt.active { border-color: var(--accent-border); background: var(--accent-bg); color: var(--accent); }
|
||||
|
||||
.transport-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
|
||||
.transport-opt {
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||
gap: 8px; aspect-ratio: 1;
|
||||
border-radius: 12px; border: 1px solid var(--border); background: var(--bg-subtle);
|
||||
cursor: pointer; transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
.transport-opt input { display: none; }
|
||||
.transport-opt.active { border-color: var(--accent-border); background: var(--accent-bg); }
|
||||
.transport-img { width: 60px; height: 60px; object-fit: contain; }
|
||||
.transport-label {
|
||||
font-size: 12px; font-weight: 300; color: var(--text-sub);
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
.transport-opt.active .transport-label { color: var(--accent); }
|
||||
|
||||
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
|
||||
.tag {
|
||||
display: inline-flex; align-items: center; gap: 4px;
|
||||
font-size: 12px; font-weight: 300; color: var(--accent);
|
||||
background: var(--accent-bg); border: 1px solid var(--accent-border);
|
||||
border-radius: 20px; padding: 3px 10px 3px 12px;
|
||||
}
|
||||
.tag-rm {
|
||||
background: none; border: none; color: var(--accent);
|
||||
font-size: 15px; line-height: 1; cursor: pointer; padding: 0; opacity: 0.6;
|
||||
}
|
||||
.tag-rm:hover { opacity: 1; }
|
||||
|
||||
/* question cards */
|
||||
.q-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
background: var(--bg-subtle);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
}
|
||||
.q-text {
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
color: var(--text-h);
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
white-space: pre-line;
|
||||
}
|
||||
.q-input {
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
font-weight: 300;
|
||||
color: var(--text-h);
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
outline: none;
|
||||
resize: none;
|
||||
line-height: 1.6;
|
||||
transition: border-color 0.15s;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.q-input:focus { border-color: var(--accent-border); }
|
||||
.q-input::placeholder { color: var(--text-sub); font-style: italic; }
|
||||
</style>
|
||||
@@ -1,9 +1,9 @@
|
||||
<script>
|
||||
import { getEntries } from '../stores/entriesStore.svelte.js';
|
||||
import { addEntry, updateEntry } from '../stores/entriesStore.svelte.js';
|
||||
import { countryNames } from '../shared/countries.js';
|
||||
import { getCitiesForCountry, ALL_CITIES } from '../shared/cities.js';
|
||||
import SearchInput from '../shared/SearchInput.svelte';
|
||||
import { getEntries } from '../../stores/entriesStore.svelte.js';
|
||||
import { addEntry, updateEntry } from '../../stores/entriesStore.svelte.js';
|
||||
import { countryNames } from '../../shared/countries.js';
|
||||
import { getCitiesForCountry, ALL_CITIES } from '../../shared/cities.js';
|
||||
import SearchInput from '../../shared/SearchInput.svelte';
|
||||
import PhotoEditor from './PhotoEditor.svelte';
|
||||
|
||||
/**
|
||||
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { removeEntry } from '../stores/entriesStore.svelte.js';
|
||||
import { flagEmoji } from '../shared/countries.js';
|
||||
import { removeEntry } from '../../stores/entriesStore.svelte.js';
|
||||
import { flagEmoji } from '../../shared/countries.js';
|
||||
import DeleteConfirm from './DeleteConfirm.svelte';
|
||||
|
||||
/** @type {{ entry: import('../shared/types.js').JournalEntry, onBack: () => void, onEdit: () => void }} */
|
||||
@@ -1,18 +1,27 @@
|
||||
<script>
|
||||
import { journals, addJournal } from '../../stores/journalStore.js';
|
||||
import { get } from 'svelte/store';
|
||||
import { journals, addJournal } from '../stores/journalStore.js';
|
||||
import { countryNames } from '../shared/countries.js';
|
||||
import SearchInput from '../shared/SearchInput.svelte';
|
||||
import { flashCountry } from '../../layout/selection.svelte.js';
|
||||
import { countryNames } from '../../shared/countries.js';
|
||||
import { countryCities } from '../../shared/countryCities.js';
|
||||
import SearchInput from '../../shared/SearchInput.svelte';
|
||||
import PhotoEditor from './PhotoEditor.svelte';
|
||||
import airplaneImg from '../../assets/airplane.png';
|
||||
import trainImg from '../../assets/train.png';
|
||||
import busImg from '../../assets/bus.png';
|
||||
import carImg from '../../assets/car.png';
|
||||
import shipImg from '../../assets/ship.png';
|
||||
import walkImg from '../../assets/walk.png';
|
||||
import airplaneImg from '../../../assets/airplane.png';
|
||||
import trainImg from '../../../assets/train.png';
|
||||
import busImg from '../../../assets/bus.png';
|
||||
import carImg from '../../../assets/car.png';
|
||||
import shipImg from '../../../assets/ship.png';
|
||||
import walkImg from '../../../assets/walk.png';
|
||||
|
||||
let { initialCountry = '', onBack, onSaved = onBack } = $props();
|
||||
|
||||
// ── Journal store (reactive) ────────────────────────────────────────
|
||||
let journalEntries = $state(get(journals));
|
||||
$effect(() => {
|
||||
const unsub = journals.subscribe(v => { journalEntries = v; });
|
||||
return unsub;
|
||||
});
|
||||
|
||||
// ── Fields ─────────────────────────────────────────────────────────
|
||||
let cities = $state([]);
|
||||
let cityInput = $state('');
|
||||
@@ -55,8 +64,11 @@
|
||||
// otherwise show all known cities.
|
||||
let cityOptions = $derived(
|
||||
country.trim()
|
||||
? [...new Set(get(journals).filter(j => (j.location.country || '').toLowerCase() === country.trim().toLowerCase()).flatMap(e => e.location.cities))].sort()
|
||||
: [...new Set(get(journals).flatMap(e => e.location.cities))].sort()
|
||||
? [...new Set([
|
||||
...(countryCities[country.trim()] ?? []),
|
||||
...journalEntries.filter(j => (j.location?.country || '').toLowerCase() === country.trim().toLowerCase()).flatMap(e => e.location?.cities ?? []),
|
||||
])]
|
||||
: []
|
||||
);
|
||||
|
||||
function addCity(val) {
|
||||
@@ -106,9 +118,11 @@
|
||||
|
||||
// ── Save ───────────────────────────────────────────────────────────
|
||||
let saving = $state(false);
|
||||
let saveError = $state('');
|
||||
|
||||
async function save() {
|
||||
saving = true;
|
||||
saveError = '';
|
||||
const memo = questions
|
||||
.map((q, i) => answers[i].trim() ? `Q: ${q.split('\n')[0]}\nA: ${answers[i].trim()}` : '')
|
||||
.filter(Boolean)
|
||||
@@ -124,9 +138,11 @@
|
||||
photos,
|
||||
location: { cities, country },
|
||||
});
|
||||
flashCountry(country);
|
||||
onSaved();
|
||||
} catch {
|
||||
} catch (e) {
|
||||
saving = false;
|
||||
saveError = e?.message ?? 'Failed to save. Please try again.';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -153,6 +169,7 @@
|
||||
<button class="save-btn" onclick={save} disabled={saving}>
|
||||
{saving ? 'Saving…' : 'Save trip'}
|
||||
</button>
|
||||
{#if saveError}<span class="save-err">{saveError}</span>{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</header>
|
||||
@@ -166,12 +183,12 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label class="label" for="nc-country">Country <span class="req">*</span></label>
|
||||
<label class="label" for="nc-country">Where did you go? <span class="req">*</span></label>
|
||||
<SearchInput id="nc-country" bind:value={country} options={countryNames} />
|
||||
{#if errors.country}<span class="ferr">{errors.country}</span>{/if}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="nc-city">Cities <span class="req">*</span></label>
|
||||
<label class="label" for="nc-city">Which cities did you visit? <span class="req">*</span></label>
|
||||
<SearchInput id="nc-city" bind:value={cityInput} options={cityOptions} onselect={addCity} onblurcommit={addCity} />
|
||||
{#if errors.cities}<span class="ferr">{errors.cities}</span>{/if}
|
||||
{#if cities.length > 0}
|
||||
@@ -186,19 +203,19 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="field">
|
||||
<label class="label" for="nc-date">Date <span class="req">*</span></label>
|
||||
<label class="label" for="nc-date">When did you travel? <span class="req">*</span></label>
|
||||
<input id="nc-date" class="input" type="date" bind:value={date} />
|
||||
{#if errors.date}<span class="ferr">{errors.date}</span>{/if}
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label" for="nc-days">Days <span class="req">*</span></label>
|
||||
<label class="label" for="nc-days">How long was the trip? <span class="req">*</span></label>
|
||||
<input id="nc-days" class="input" type="number" min="1" bind:value={days} />
|
||||
{#if errors.days}<span class="ferr">{errors.days}</span>{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label">Trip type <span class="req">*</span></label>
|
||||
<label class="label">Who did you travel with? <span class="req">*</span></label>
|
||||
<div class="toggle-row">
|
||||
{#each ['solo','friends','family'] as t}
|
||||
<label class="toggle-opt" class:active={tripType === t}>
|
||||
@@ -326,6 +343,7 @@
|
||||
}
|
||||
.save-btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
|
||||
.save-btn:disabled { opacity: 0.6; cursor: not-allowed; }
|
||||
.save-err { font-size: 12px; color: #ef4444; margin-top: 4px; display: block; text-align: right; }
|
||||
|
||||
/* scroll + form */
|
||||
.scroll { flex: 1; overflow-y: auto; }
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { storage } from '../firebase.js';
|
||||
import { storage } from '../../firebase.js';
|
||||
import { ref, uploadBytes, getDownloadURL } from 'firebase/storage';
|
||||
|
||||
/** @type {{ photos: string[], onchange: (photos: string[]) => void }} */
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { flagEmoji } from '../shared/countries.js';
|
||||
import { flagEmoji } from '../../shared/countries.js';
|
||||
|
||||
/** @type {{ entry: import('../shared/types.js').JournalEntry, onClick: () => void }} */
|
||||
let { entry, onClick } = $props();
|
||||
@@ -1,10 +1,10 @@
|
||||
<script>
|
||||
import { getEntries } from '../stores/entriesStore.svelte.js';
|
||||
import { getEntries } from '../../stores/entriesStore.svelte.js';
|
||||
import TimelineToolbar from './TimelineToolbar.svelte';
|
||||
import TimelineCard from './TimelineCard.svelte';
|
||||
import JournalDetail from './JournalDetail.svelte';
|
||||
import EditForm from './EditForm.svelte';
|
||||
import NewEntryForm from './NewEntryForm.svelte';
|
||||
import JournalDetail from '../detail/JournalDetail.svelte';
|
||||
import EditForm from '../detail/EditForm.svelte';
|
||||
import NewEntryForm from '../detail/NewEntryForm.svelte';
|
||||
import ShareCard from './ShareCard.svelte';
|
||||
import SharePreview from './SharePreview.svelte';
|
||||
|
||||
@@ -65,53 +65,55 @@
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="right-panel">
|
||||
<div class="center-col">
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">My Journey</h1>
|
||||
<button class="new-btn" onclick={() => { view = 'new'; }}>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
|
||||
<path d="M12 5v14M5 12h14"/>
|
||||
</svg>
|
||||
Add trip
|
||||
</button>
|
||||
<div class="list-view">
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">My Journey</h1>
|
||||
<button class="new-btn" onclick={() => { view = 'new'; }}>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
|
||||
<path d="M12 5v14M5 12h14"/>
|
||||
</svg>
|
||||
Add trip
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="two-col">
|
||||
<div class="left-col">
|
||||
<TimelineToolbar {sortKey} onSort={(k) => (sortKey = k)} />
|
||||
|
||||
{#if sortedEntries.length === 0}
|
||||
<p class="empty">No journal entries yet.</p>
|
||||
{:else}
|
||||
<div class="sort-row">
|
||||
<span class="sort-label">Sort by</span>
|
||||
<select class="sort-select" onchange={(e) => (sortKey = e.currentTarget.value)}>
|
||||
<option value="date-desc" selected={sortKey === 'date-desc'}>Newest first</option>
|
||||
<option value="date-asc" selected={sortKey === 'date-asc'}>Oldest first</option>
|
||||
<option value="country-asc" selected={sortKey === 'country-asc'}>Country A → Z</option>
|
||||
<option value="country-desc" selected={sortKey === 'country-desc'}>Country Z → A</option>
|
||||
</select>
|
||||
</div>
|
||||
<ol class="v-list">
|
||||
{#each sortedEntries as entry, i (entry.id)}
|
||||
{#if i === 0 || getYear(entry.date) !== getYear(sortedEntries[i - 1].date)}
|
||||
<li class="year-marker" aria-hidden="true">
|
||||
<span class="year-label">{getYear(entry.date)}</span>
|
||||
</li>
|
||||
{/if}
|
||||
<TimelineCard {entry} onClick={() => { selectedId = entry.id; view = 'detail'; onDetailChange(true); }} />
|
||||
{/each}
|
||||
</ol>
|
||||
{/if}
|
||||
|
||||
<footer class="page-footer">
|
||||
{sortedEntries.length} {sortedEntries.length === 1 ? 'trip' : 'trips'}
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
{#if sortedEntries.length > 0}
|
||||
<div class="share-row">
|
||||
<div class="right-col">
|
||||
<SharePreview entries={sortedEntries} onClick={() => (showShare = true)} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<TimelineToolbar {sortKey} onSort={(k) => (sortKey = k)} />
|
||||
|
||||
{#if sortedEntries.length === 0}
|
||||
<p class="empty">No journal entries yet.</p>
|
||||
{:else}
|
||||
<div class="sort-row">
|
||||
<span class="sort-label">Sort by</span>
|
||||
<select class="sort-select" onchange={(e) => (sortKey = e.currentTarget.value)}>
|
||||
<option value="date-desc" selected={sortKey === 'date-desc'}>Newest first</option>
|
||||
<option value="date-asc" selected={sortKey === 'date-asc'}>Oldest first</option>
|
||||
<option value="country-asc" selected={sortKey === 'country-asc'}>Country A → Z</option>
|
||||
<option value="country-desc" selected={sortKey === 'country-desc'}>Country Z → A</option>
|
||||
</select>
|
||||
</div>
|
||||
<ol class="v-list">
|
||||
{#each sortedEntries as entry, i (entry.id)}
|
||||
{#if i === 0 || getYear(entry.date) !== getYear(sortedEntries[i - 1].date)}
|
||||
<li class="year-marker" aria-hidden="true">
|
||||
<span class="year-label">{getYear(entry.date)}</span>
|
||||
</li>
|
||||
{/if}
|
||||
<TimelineCard {entry} onClick={() => { selectedId = entry.id; view = 'detail'; onDetailChange(true); }} />
|
||||
{/each}
|
||||
</ol>
|
||||
{/if}
|
||||
|
||||
<footer class="page-footer">
|
||||
{sortedEntries.length} {sortedEntries.length === 1 ? 'trip' : 'trips'}
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -132,31 +134,51 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Right panel ── */
|
||||
.right-panel {
|
||||
/* ── List view wrapper (scrollable) ── */
|
||||
.list-view {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 48px 0 80px;
|
||||
box-sizing: border-box;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.page-header,
|
||||
.two-col {
|
||||
max-width: 960px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding-left: 48px;
|
||||
padding-right: 48px;
|
||||
}
|
||||
|
||||
/* ── Two-column below header ── */
|
||||
.two-col {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 32px;
|
||||
align-items: flex-start;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.left-col {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow-y: auto;
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
/* ── Centered single column ── */
|
||||
.center-col {
|
||||
max-width: 680px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
padding: 48px 48px 80px;
|
||||
box-sizing: border-box;
|
||||
.right-col {
|
||||
width: 260px;
|
||||
flex-shrink: 0;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.share-row {
|
||||
margin-bottom: 24px;
|
||||
@media (max-width: 900px) {
|
||||
.right-col { display: none; }
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.center-col {
|
||||
padding: 32px 24px 60px;
|
||||
}
|
||||
.list-view { padding: 32px 24px 60px; }
|
||||
}
|
||||
|
||||
/* ── Detail view ── */
|
||||
@@ -1,391 +0,0 @@
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import * as d3 from 'd3';
|
||||
import { feature } from 'topojson-client';
|
||||
import worldData from 'world-atlas/countries-50m.json';
|
||||
|
||||
let { onclose, onprogress } = $props();
|
||||
|
||||
const HOME_CODE = '203';
|
||||
|
||||
const MOCK_TRIPS = [
|
||||
{ countryName: 'Japan', countryCode: '392', date: '2024-03-15', city: 'Tokyo' },
|
||||
{ countryName: 'France', countryCode: '191', date: '2024-06-20', city: 'Paris' },
|
||||
{ countryName: 'Spain', countryCode: '724', date: '2024-09-10', city: 'Barcelona' },
|
||||
{ countryName: 'United States', countryCode: '840', date: '2025-01-05', city: 'New York' },
|
||||
{ countryName: 'Thailand', countryCode: '764', date: '2025-04-18', city: 'Bangkok' },
|
||||
{ countryName: 'Australia', countryCode: '036', date: '2025-08-22', city: 'Sydney' },
|
||||
];
|
||||
|
||||
const HOME_COLOR = '#8b5cf6';
|
||||
const VISITED_COLOR = '#22c55e';
|
||||
const ARC_COLOR = '#000000';
|
||||
const PLANE_COLOR = '#7c3aed';
|
||||
const PLANE_PATH = 'M14,0 L4,-3 L0,-7 L-3,-5 L0,-2 L-5,-1 L-9,-5 L-11,-4 L-7,0 L-11,4 L-9,5 L-5,1 L0,2 L-3,5 L0,7 L4,3 Z';
|
||||
const UNVISITED = '#ffffff';
|
||||
|
||||
const TERRITORY_PARENT = {
|
||||
'016': '840', '060': '826', '086': '826', '092': '826', '136': '826',
|
||||
'184': '554', '234': '208', '238': '826', '239': '826', '248': '246',
|
||||
'258': '250', '260': '250', '304': '208', '316': '840', '334': '036',
|
||||
'446': '156', '500': '826', '531': '528', '533': '528', '534': '528',
|
||||
'540': '250', '570': '554', '574': '036', '580': '840', '612': '826',
|
||||
'630': '840', '652': '250', '654': '826', '660': '826', '663': '250',
|
||||
'666': '250', '796': '826', '831': '826', '832': '826', '833': '826',
|
||||
'850': '840', '876': '250',
|
||||
};
|
||||
|
||||
function effId(d) {
|
||||
return TERRITORY_PARENT[d.id] || d.id;
|
||||
}
|
||||
|
||||
let frameEl;
|
||||
let svg, g, pathFn, projection;
|
||||
let countryPaths;
|
||||
let homeFeature;
|
||||
let featuresById = {};
|
||||
let isCancelled = false;
|
||||
let isPlaying = $state(false);
|
||||
let isFinished = $state(false);
|
||||
|
||||
function fitProjection(proj, w, h) {
|
||||
proj.fitSize([w, h], { type: 'Sphere' });
|
||||
const s = proj.scale() * 1.5;
|
||||
proj.scale(s).translate([w / 2, h * 0.70]);
|
||||
}
|
||||
|
||||
function computeArc(p1, p2) {
|
||||
const interp = d3.geoInterpolate(p1, p2);
|
||||
const steps = 80;
|
||||
const raw = [];
|
||||
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const t = i / steps;
|
||||
const geo = interp(t);
|
||||
const pt = projection(geo);
|
||||
if (!pt) continue;
|
||||
raw.push({ t, x: pt[0], y: pt[1] });
|
||||
}
|
||||
|
||||
if (raw.length < 2) return [];
|
||||
|
||||
const first = raw[0];
|
||||
const last = raw[raw.length - 1];
|
||||
const dx = last.x - first.x;
|
||||
const dy = last.y - first.y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
const arcH = Math.max(40, Math.min(200, dist * 0.22));
|
||||
|
||||
return raw.map(p => [p.x, p.y - arcH * Math.sin(Math.PI * p.t)]);
|
||||
}
|
||||
|
||||
function getAngleAtLength(node, len) {
|
||||
const d = 0.5;
|
||||
const total = node.getTotalLength();
|
||||
const p1 = node.getPointAtLength(Math.max(0, len - d));
|
||||
const p2 = node.getPointAtLength(Math.min(total, len + d));
|
||||
return Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
|
||||
}
|
||||
|
||||
function animateStroke(pathEl, tipEl, startOffset, endOffset, duration) {
|
||||
return new Promise((resolve) => {
|
||||
const node = pathEl.node();
|
||||
if (!node) { resolve(); return; }
|
||||
const totalLength = node.getTotalLength();
|
||||
|
||||
if (totalLength === 0) { resolve(); return; }
|
||||
|
||||
d3.timer(elapsed => {
|
||||
if (isCancelled) { resolve(); return true; }
|
||||
|
||||
const t = Math.min(elapsed / duration, 1);
|
||||
const offset = startOffset + (endOffset - startOffset) * t;
|
||||
|
||||
pathEl.attr('stroke-dashoffset', offset);
|
||||
|
||||
const drawn = totalLength - offset;
|
||||
const clamped = Math.max(0, Math.min(drawn, totalLength));
|
||||
try {
|
||||
const pt = node.getPointAtLength(clamped);
|
||||
const angle = getAngleAtLength(node, clamped);
|
||||
tipEl.attr('transform', `translate(${pt.x}, ${pt.y}) rotate(${angle}) scale(1.4)`).attr('opacity', 1);
|
||||
} catch (e) {
|
||||
// ignore SVG errors
|
||||
}
|
||||
|
||||
if (t >= 1) {
|
||||
resolve();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => {
|
||||
if (isCancelled) { resolve(); return; }
|
||||
const id = setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
async function animateTrip(destCode, destFeature) {
|
||||
if (!homeFeature || !destFeature) return;
|
||||
|
||||
const homeCentroid = d3.geoCentroid(homeFeature);
|
||||
const destCentroid = d3.geoCentroid(destFeature);
|
||||
|
||||
const pts = computeArc(homeCentroid, destCentroid);
|
||||
if (pts.length < 2) return;
|
||||
|
||||
const lineGen = d3.line().curve(d3.curveBasis);
|
||||
const pathData = lineGen(pts);
|
||||
|
||||
if (!pathData) return;
|
||||
|
||||
function createArc(pathData) {
|
||||
const el = g.append('path')
|
||||
.attr('d', pathData)
|
||||
.attr('fill', 'none')
|
||||
.attr('stroke', ARC_COLOR)
|
||||
.attr('stroke-width', 2.5)
|
||||
.attr('stroke-opacity', 0.8)
|
||||
.attr('stroke-linecap', 'round');
|
||||
const tip = g.append('path')
|
||||
.attr('d', PLANE_PATH)
|
||||
.attr('fill', PLANE_COLOR)
|
||||
.attr('opacity', 0);
|
||||
return { el, tip };
|
||||
}
|
||||
|
||||
// --- Outbound: home -> dest ---
|
||||
let { el: outEl, tip: outTip } = createArc(pathData);
|
||||
const outLen = outEl.node().getTotalLength();
|
||||
outEl.attr('stroke-dasharray', outLen).attr('stroke-dashoffset', outLen);
|
||||
|
||||
const homeDot = g.append('circle')
|
||||
.attr('r', 4)
|
||||
.attr('fill', PLANE_COLOR)
|
||||
.attr('cx', pts[0][0])
|
||||
.attr('cy', pts[0][1])
|
||||
.attr('opacity', 1);
|
||||
|
||||
await animateStroke(outEl, outTip, outLen, 0, 2500);
|
||||
if (isCancelled) return;
|
||||
|
||||
outEl.remove();
|
||||
outTip.remove();
|
||||
homeDot.remove();
|
||||
|
||||
// Color the destination country
|
||||
const targetPath = countryPaths.filter(d => effId(d) === destCode);
|
||||
targetPath.transition().duration(500).attr('fill', VISITED_COLOR);
|
||||
g.selectAll('.micro-state-j')
|
||||
.filter(d => effId(d) === destCode)
|
||||
.transition().duration(500)
|
||||
.attr('fill', VISITED_COLOR);
|
||||
|
||||
await delay(800);
|
||||
if (isCancelled) return;
|
||||
|
||||
// --- Return: dest -> home ---
|
||||
const revPts = [...pts].reverse();
|
||||
const revData = d3.line().curve(d3.curveBasis)(revPts);
|
||||
let { el: retEl, tip: retTip } = createArc(revData);
|
||||
const retLen = retEl.node().getTotalLength();
|
||||
retEl.attr('stroke-dasharray', retLen).attr('stroke-dashoffset', retLen);
|
||||
|
||||
const destDot = g.append('circle')
|
||||
.attr('r', 4)
|
||||
.attr('fill', PLANE_COLOR)
|
||||
.attr('cx', revPts[0][0])
|
||||
.attr('cy', revPts[0][1])
|
||||
.attr('opacity', 1);
|
||||
|
||||
await animateStroke(retEl, retTip, retLen, 0, 2200);
|
||||
if (isCancelled) return;
|
||||
|
||||
retEl.remove();
|
||||
retTip.remove();
|
||||
destDot.remove();
|
||||
|
||||
await delay(300);
|
||||
}
|
||||
|
||||
async function startJourney() {
|
||||
isPlaying = true;
|
||||
isFinished = false;
|
||||
isCancelled = false;
|
||||
|
||||
const trips = MOCK_TRIPS;
|
||||
const total = trips.length;
|
||||
|
||||
for (let i = 0; i < total; i++) {
|
||||
if (isCancelled) break;
|
||||
|
||||
const trip = trips[i];
|
||||
const destFeature = featuresById[trip.countryCode];
|
||||
if (!destFeature) continue;
|
||||
|
||||
const label = `${trip.city}, ${trip.countryName}`;
|
||||
if (onprogress) onprogress({ index: i + 1, total, label });
|
||||
|
||||
await animateTrip(trip.countryCode, destFeature);
|
||||
}
|
||||
|
||||
if (!isCancelled) {
|
||||
isFinished = true;
|
||||
isPlaying = false;
|
||||
if (onprogress) onprogress({ index: trips.length, total: trips.length, label: 'Journey complete!' });
|
||||
} else {
|
||||
isPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
function stopJourney() {
|
||||
isCancelled = true;
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const width = frameEl.clientWidth;
|
||||
const height = frameEl.clientHeight;
|
||||
|
||||
projection = d3.geoMercator();
|
||||
fitProjection(projection, width, height);
|
||||
|
||||
pathFn = d3.geoPath().projection(projection);
|
||||
|
||||
const countries = feature(worldData, worldData.objects.countries)
|
||||
.features.filter(f => (f.id || f.properties.name === 'Kosovo') && f.id !== '010');
|
||||
|
||||
countries.forEach(f => {
|
||||
if (!f.id) f.id = 'XK';
|
||||
});
|
||||
|
||||
for (const f of countries) {
|
||||
featuresById[effId(f)] = f;
|
||||
}
|
||||
|
||||
homeFeature = featuresById[HOME_CODE];
|
||||
|
||||
svg = d3.select(frameEl)
|
||||
.append('svg')
|
||||
.attr('width', width)
|
||||
.attr('height', height)
|
||||
.style('cursor', 'default');
|
||||
|
||||
g = svg.append('g');
|
||||
|
||||
countryPaths = g.selectAll('path')
|
||||
.data(countries)
|
||||
.join('path')
|
||||
.attr('d', pathFn)
|
||||
.attr('fill', d => effId(d) === HOME_CODE ? HOME_COLOR : UNVISITED)
|
||||
.attr('stroke', '#d4d4d4')
|
||||
.attr('stroke-width', 0.5);
|
||||
|
||||
function renderMicrostates() {
|
||||
g.selectAll('.micro-state-j').remove();
|
||||
const threshold = 4;
|
||||
countryPaths.each(function (d) {
|
||||
if (effId(d) !== d.id) return;
|
||||
const { width, height } = this.getBBox();
|
||||
if (width < threshold && height < threshold) {
|
||||
const [cx, cy] = pathFn.centroid(d);
|
||||
g.append('circle')
|
||||
.attr('class', 'micro-state-j')
|
||||
.datum(d)
|
||||
.attr('cx', cx)
|
||||
.attr('cy', cy)
|
||||
.attr('r', 2)
|
||||
.attr('fill', effId(d) === HOME_CODE ? HOME_COLOR : UNVISITED)
|
||||
.attr('stroke', '#94a3b8')
|
||||
.attr('stroke-width', 0.5);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
renderMicrostates();
|
||||
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const { width, height } = entry.contentRect;
|
||||
svg.attr('width', width).attr('height', height);
|
||||
fitProjection(projection, width, height);
|
||||
countryPaths.attr('d', pathFn);
|
||||
renderMicrostates();
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(frameEl);
|
||||
|
||||
startJourney();
|
||||
|
||||
return () => {
|
||||
stopJourney();
|
||||
observer.disconnect();
|
||||
if (svg) svg.remove();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<div bind:this={frameEl} class="journey-frame">
|
||||
<button class="close-btn" onclick={() => { stopJourney(); onclose?.(); }}>✕</button>
|
||||
{#if isFinished}
|
||||
<div class="done-badge">Journey complete!</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.journey-frame {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
background: #a4c8e0;
|
||||
}
|
||||
|
||||
.journey-frame :global(svg) {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
z-index: 10;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
background: rgba(0,0,0,0.55);
|
||||
color: #fff;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: rgba(0,0,0,0.75);
|
||||
}
|
||||
|
||||
.done-badge {
|
||||
position: absolute;
|
||||
bottom: 24px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 10;
|
||||
background: rgba(0,0,0,0.65);
|
||||
color: #fff;
|
||||
font-family: var(--heading, sans-serif);
|
||||
font-size: 16px;
|
||||
padding: 10px 24px;
|
||||
border-radius: 24px;
|
||||
white-space: nowrap;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
</style>
|
||||
@@ -3,7 +3,10 @@
|
||||
import * as d3 from 'd3';
|
||||
import { feature } from 'topojson-client';
|
||||
import worldData from 'world-atlas/countries-50m.json';
|
||||
import { getSelected, setTotalCount } from '../layout/selection.svelte.js';
|
||||
import { getSelected, setTotalCount, getFlashing } from '../layout/selection.svelte.js';
|
||||
import { getUserProfile } from '../auth/userStore.svelte.js';
|
||||
import homeIconUrl from '../../assets/home.png';
|
||||
import crayonCursorUrl from '../../assets/logo-cursor.png';
|
||||
|
||||
let { onCountryClick = (_name) => {} } = $props();
|
||||
|
||||
@@ -73,8 +76,34 @@
|
||||
}
|
||||
|
||||
let frameEl;
|
||||
let _paths = null;
|
||||
let _paths = $state(null);
|
||||
let _g = null;
|
||||
let _pathFn = null;
|
||||
let _countries = null;
|
||||
|
||||
function updateHomeMarker(homeCountryName) {
|
||||
if (!_g || !_pathFn || !_countries) return;
|
||||
_g.selectAll('.home-marker').remove();
|
||||
if (!homeCountryName) return;
|
||||
const found = _countries.find(f => f.properties.name === homeCountryName);
|
||||
if (!found) return;
|
||||
const [cx, cy] = _pathFn.centroid(found);
|
||||
if (isNaN(cx) || isNaN(cy)) return;
|
||||
const SIZE = 24;
|
||||
_g.append('image')
|
||||
.attr('class', 'home-marker')
|
||||
.attr('href', homeIconUrl)
|
||||
.attr('x', cx - SIZE / 2)
|
||||
.attr('y', cy - SIZE / 2)
|
||||
.attr('width', SIZE)
|
||||
.attr('height', SIZE)
|
||||
.style('pointer-events', 'none');
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
const homeCountry = getUserProfile()?.homeCountry ?? null;
|
||||
updateHomeMarker(homeCountry);
|
||||
});
|
||||
|
||||
function fitProjection(proj, w, h) {
|
||||
proj.fitSize([w, h], { type: 'Sphere' });
|
||||
@@ -91,6 +120,23 @@
|
||||
|
||||
$effect(updateAllFills);
|
||||
|
||||
$effect(() => {
|
||||
const flashSet = getFlashing();
|
||||
const paths = _paths; // reactive read so effect re-runs when _paths is set
|
||||
if (!paths || flashSet.size === 0) return;
|
||||
paths
|
||||
.filter(d => flashSet.has(effId(d)))
|
||||
.each(function() {
|
||||
d3.select(this).interrupt()
|
||||
.transition().duration(200).attr('fill', '#facc15')
|
||||
.transition().duration(200).attr('fill', '#fb923c')
|
||||
.transition().duration(200).attr('fill', '#facc15')
|
||||
.transition().duration(200).attr('fill', '#fb923c')
|
||||
.transition().duration(200).attr('fill', '#facc15')
|
||||
.transition().duration(400).attr('fill', VISITED_COLOR);
|
||||
});
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
const width = frameEl.clientWidth;
|
||||
const height = frameEl.clientHeight;
|
||||
@@ -107,6 +153,9 @@
|
||||
if (!f.id) f.id = 'XK';
|
||||
});
|
||||
|
||||
_pathFn = path;
|
||||
_countries = countries;
|
||||
|
||||
const sovereignIds = new Set(countries.map(f => effId(f)));
|
||||
setTotalCount(sovereignIds.size);
|
||||
|
||||
@@ -175,6 +224,7 @@
|
||||
}
|
||||
|
||||
renderMicrostates();
|
||||
updateHomeMarker(getUserProfile()?.homeCountry ?? null);
|
||||
|
||||
const zoom = d3.zoom()
|
||||
.scaleExtent([1, 32])
|
||||
@@ -212,7 +262,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
<div bind:this={frameEl} class="map-frame"></div>
|
||||
<div bind:this={frameEl} class="map-frame" style="cursor: url({crayonCursorUrl}) 4 28, crosshair;"></div>
|
||||
|
||||
<style>
|
||||
.map-frame {
|
||||
@@ -225,15 +275,15 @@
|
||||
|
||||
.map-frame :global(svg) {
|
||||
display: block;
|
||||
cursor: grab;
|
||||
cursor: inherit;
|
||||
}
|
||||
|
||||
.map-frame :global(svg:active) {
|
||||
cursor: grabbing;
|
||||
cursor: inherit;
|
||||
}
|
||||
|
||||
.map-frame :global(svg path) {
|
||||
cursor: pointer;
|
||||
cursor: inherit;
|
||||
}
|
||||
|
||||
.map-frame :global(.tooltip) {
|
||||
|
||||