mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
fix: miscellaneous bug fixes (#1139)
* fix(share): serve place thumbnails in shared trip links (#1100) Google-sourced place photos are stored as image_url pointing at the JWT-guarded /api/maps/place-photo/:placeId/bytes endpoint, so they 401 for an unauthenticated shared-trip viewer and render as broken images. Rewrite place image_url values in the shared payload to a public, token-scoped proxy (/api/shared/:token/place-photo/:placeId/bytes) and add an unguarded SharedController route that validates the token and that the place belongs to its trip before streaming the cached bytes. Mirrors the existing JourneyPublicController precedent. No client changes needed. * fix(atlas): replace Natural Earth with geoBoundaries for up-to-date regions (#1119) Atlas sourced country and sub-national boundaries from Natural Earth's GitHub `master` at runtime. That data is stale (e.g. it still shows Norway's pre-2020 counties such as Oppland/Hordaland) and depicts some contested territory in unwanted ways (nvkelso/natural-earth-vector#391), so Natural Earth is dropped entirely. - Country borders (admin0) now come from the geoBoundaries CGAZ composite; sub-national regions (admin1) from per-country gbOpen, which carries ISO 3166-2 codes. A new script (server/scripts/build-atlas-geo.mjs) normalizes and quantizes them into committed gzipped bundles under server/assets/atlas, read server-side at runtime (no network at boot, no GitHub CSP allowlist entry). - New GET /addons/atlas/countries/geo serves the country layer; the client fetches it from the API instead of GitHub. - A migration reconciles manually-marked visited_regions against the new bundle (valid code -> keep; region name still matches -> re-code; curated merge crosswalk for renamed reforms; else leave intact), with UNIQUE-safe dedup. bucket_list and visited_countries hold only invariant alpha-2 country codes, so they are untouched. - Attribution added (NOTICE.md + README) per geoBoundaries CC BY 4.0. Closes #1119 * fix(packing): make templates admin-only to create, usable by members Creating a packing-list template was gated only by trip access, so any trip member could create one from the Lists feature, while applying a template silently failed for non-admins because the apply dropdown was populated from the AdminGuard-protected /api/admin/packing-templates endpoint. - save-as-template now returns 403 for non-admins; the Save-as-Template button is hidden unless the user is an admin (both the TripPlanner toolbar and the inline packing header). - add member-accessible GET /api/trips/:tripId/packing/templates so the apply dropdown lists templates for any trip member; client fetches from it instead of the admin endpoint. Closes #1120 Closes #1121 * fix(packing): show bag tracking to non-admin members The global Bag Tracking toggle was only readable via the admin-gated GET /api/admin/bag-tracking, so non-admin trip members got 403 and the weight fields, bag circles, and BAGS sidebar never rendered (#1124). Surface the flag through the already-authenticated GET /api/addons (loaded into the client addon store on app start for every user); the packing hook reads it from the store instead of the admin endpoint. The admin write path stays admin-gated and unchanged.
This commit is contained in:
@@ -394,6 +394,7 @@ export const packingApi = {
|
||||
reorder: (tripId: number | string, orderedIds: number[]) => apiClient.put(`/trips/${tripId}/packing/reorder`, { orderedIds } satisfies PackingReorderRequest).then(r => r.data),
|
||||
getCategoryAssignees: (tripId: number | string) => apiClient.get(`/trips/${tripId}/packing/category-assignees`).then(r => r.data),
|
||||
setCategoryAssignees: (tripId: number | string, categoryName: string, userIds: number[]) => apiClient.put(`/trips/${tripId}/packing/category-assignees/${encodeURIComponent(categoryName)}`, { user_ids: userIds } satisfies PackingCategoryAssigneesRequest).then(r => r.data),
|
||||
listTemplates: (tripId: number | string) => apiClient.get(`/trips/${tripId}/packing/templates`).then(r => r.data),
|
||||
applyTemplate: (tripId: number | string, templateId: number) => apiClient.post(`/trips/${tripId}/packing/apply-template/${templateId}`).then(r => r.data),
|
||||
saveAsTemplate: (tripId: number | string, name: string) => apiClient.post(`/trips/${tripId}/packing/save-as-template`, { name }).then(r => r.data),
|
||||
setBagMembers: (tripId: number | string, bagId: number, userIds: number[]) => apiClient.put(`/trips/${tripId}/packing/bags/${bagId}/members`, { user_ids: userIds } satisfies PackingBagMembersRequest).then(r => r.data),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { Package } from 'lucide-react'
|
||||
import { adminApi, packingApi } from '../../api/client'
|
||||
import { packingApi } from '../../api/client'
|
||||
import { useTripStore } from '../../store/tripStore'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import { useTranslation } from '../../i18n'
|
||||
@@ -28,7 +28,7 @@ export default function ApplyTemplateButton({ tripId, style, className }: ApplyT
|
||||
const { t } = useTranslation()
|
||||
|
||||
useEffect(() => {
|
||||
adminApi.packingTemplates().then(d => setTemplates(d.templates || [])).catch(() => {})
|
||||
packingApi.listTemplates(tripId).then(d => setTemplates(d.templates || [])).catch(() => {})
|
||||
}, [tripId])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { server } from '../../../tests/helpers/msw/server';
|
||||
import { useAuthStore } from '../../store/authStore';
|
||||
import { useTripStore } from '../../store/tripStore';
|
||||
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
|
||||
import { buildUser, buildTrip, buildPackingItem } from '../../../tests/helpers/factories';
|
||||
import { buildUser, buildAdmin, buildTrip, buildPackingItem } from '../../../tests/helpers/factories';
|
||||
import PackingListPanel, { itemWeight } from './PackingListPanel';
|
||||
|
||||
describe('itemWeight (bag total weight calc)', () => {
|
||||
@@ -34,10 +34,10 @@ beforeEach(() => {
|
||||
http.get('/api/trips/:id/packing/category-assignees', () =>
|
||||
HttpResponse.json({ assignees: {} })
|
||||
),
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: false })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: false, addons: [] })
|
||||
),
|
||||
http.get('/api/admin/packing-templates', () =>
|
||||
http.get('/api/trips/:id/packing/templates', () =>
|
||||
HttpResponse.json({ templates: [] })
|
||||
),
|
||||
);
|
||||
@@ -381,7 +381,7 @@ describe('PackingListPanel', () => {
|
||||
|
||||
it('FE-COMP-PACKING-030: packing template button present when templates available', async () => {
|
||||
server.use(
|
||||
http.get('/api/admin/packing-templates', () =>
|
||||
http.get('/api/trips/:id/packing/templates', () =>
|
||||
HttpResponse.json({ templates: [{ id: 1, name: 'Beach Trip', item_count: 5 }] })
|
||||
)
|
||||
);
|
||||
@@ -457,8 +457,8 @@ describe('PackingListPanel', () => {
|
||||
|
||||
it('FE-COMP-PACKING-034: bag tracking enabled shows Bags button and bag sidebar', async () => {
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 1, name: 'Carry-on', color: '#6366f1', weight_limit_grams: null, members: [] }] })
|
||||
@@ -556,8 +556,8 @@ describe('PackingListPanel', () => {
|
||||
it('FE-COMP-PACKING-039: bag modal opens when Bags button clicked with bag tracking enabled', async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 1, name: 'Main Bag', color: '#6366f1', weight_limit_grams: null, members: [] }] })
|
||||
@@ -585,8 +585,8 @@ describe('PackingListPanel', () => {
|
||||
|
||||
it('FE-COMP-PACKING-040: bag sidebar renders BagCard with bag name when enabled and bags exist', async () => {
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 5, name: 'Backpack', color: '#10b981', weight_limit_grams: 10000, members: [] }] })
|
||||
@@ -601,26 +601,36 @@ describe('PackingListPanel', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('FE-COMP-PACKING-041: save-as-template button present when items exist', async () => {
|
||||
it('FE-COMP-PACKING-041: save-as-template button present for admins when items exist', async () => {
|
||||
seedStore(useAuthStore, { user: buildAdmin(), isAuthenticated: true });
|
||||
const user = userEvent.setup();
|
||||
const items = [buildPackingItem({ name: 'Sunscreen', category: 'Toiletries' })];
|
||||
const { container } = render(<PackingListPanel tripId={1} items={items} />);
|
||||
render(<PackingListPanel tripId={1} items={items} />);
|
||||
|
||||
// Save-as-template button uses FolderPlus icon and "Save as template" text
|
||||
const folderPlusBtn = container.querySelector('svg.lucide-folder-plus')?.closest('button');
|
||||
expect(folderPlusBtn).toBeTruthy();
|
||||
// Save-as-template button shows its label "Save as template"
|
||||
const saveBtn = screen.getByText('Save as template').closest('button');
|
||||
expect(saveBtn).toBeTruthy();
|
||||
|
||||
// Click to show the name input
|
||||
await user.click(folderPlusBtn!);
|
||||
await user.click(saveBtn!);
|
||||
|
||||
// Template name input appears
|
||||
expect(await screen.findByPlaceholderText('Template name')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-PACKING-041b: save-as-template button hidden for non-admins', () => {
|
||||
// Default seeded user (beforeEach) is a non-admin trip owner with edit rights.
|
||||
const items = [buildPackingItem({ name: 'Sunscreen', category: 'Toiletries' })];
|
||||
render(<PackingListPanel tripId={1} items={items} />);
|
||||
|
||||
// The "Save as template" action must not be available to normal users.
|
||||
expect(screen.queryByText('Save as template')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-COMP-PACKING-042: apply template dropdown opens when template button clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(
|
||||
http.get('/api/admin/packing-templates', () =>
|
||||
http.get('/api/trips/:id/packing/templates', () =>
|
||||
HttpResponse.json({ templates: [{ id: 2, name: 'Summer Packing', item_count: 10 }] })
|
||||
)
|
||||
);
|
||||
@@ -658,8 +668,8 @@ describe('PackingListPanel', () => {
|
||||
|
||||
it('FE-COMP-PACKING-044: bag item row shows weight input and bag button when bag tracking enabled', async () => {
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [] })
|
||||
@@ -706,6 +716,7 @@ describe('PackingListPanel', () => {
|
||||
});
|
||||
|
||||
it('FE-COMP-PACKING-046: save-as-template form submission calls saveAsTemplate API', async () => {
|
||||
seedStore(useAuthStore, { user: buildAdmin(), isAuthenticated: true });
|
||||
const user = userEvent.setup();
|
||||
let savedTemplateName = '';
|
||||
server.use(
|
||||
@@ -714,16 +725,16 @@ describe('PackingListPanel', () => {
|
||||
savedTemplateName = String(body.name);
|
||||
return HttpResponse.json({ success: true });
|
||||
}),
|
||||
http.get('/api/admin/packing-templates', () =>
|
||||
http.get('/api/trips/:id/packing/templates', () =>
|
||||
HttpResponse.json({ templates: [] })
|
||||
)
|
||||
);
|
||||
const items = [buildPackingItem({ name: 'Item', category: 'Test' })];
|
||||
const { container } = render(<PackingListPanel tripId={1} items={items} />);
|
||||
render(<PackingListPanel tripId={1} items={items} />);
|
||||
|
||||
// Click the FolderPlus "Save as template" button
|
||||
const folderPlusBtn = container.querySelector('svg.lucide-folder-plus')?.closest('button');
|
||||
await user.click(folderPlusBtn!);
|
||||
// Click the "Save as template" button
|
||||
const saveBtn = screen.getByText('Save as template').closest('button');
|
||||
await user.click(saveBtn!);
|
||||
|
||||
// Type template name
|
||||
const nameInput = await screen.findByPlaceholderText('Template name');
|
||||
@@ -736,8 +747,8 @@ describe('PackingListPanel', () => {
|
||||
it('FE-COMP-PACKING-047: bag picker in item row opens when clicked with bag tracking enabled', async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 3, name: 'Carry-on', color: '#ec4899', weight_limit_grams: null, members: [] }] })
|
||||
@@ -765,8 +776,8 @@ describe('PackingListPanel', () => {
|
||||
it('FE-COMP-PACKING-048: add bag in bag modal opens form when "Add bag" clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 1, name: 'Main Bag', color: '#6366f1', weight_limit_grams: null, members: [] }] })
|
||||
@@ -805,8 +816,8 @@ describe('PackingListPanel', () => {
|
||||
let putBody: Record<string, unknown> | null = null;
|
||||
const itemId = 120;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [] })
|
||||
@@ -861,8 +872,8 @@ describe('PackingListPanel', () => {
|
||||
const itemId = 130;
|
||||
let putBody: Record<string, unknown> | null = null;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 7, name: 'Trolley', color: '#10b981', weight_limit_grams: null, members: [] }] })
|
||||
@@ -930,8 +941,8 @@ describe('PackingListPanel', () => {
|
||||
it('FE-COMP-PACKING-054: item with assigned bag shows "Unassigned" option in bag picker', async () => {
|
||||
const itemId = 140;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () =>
|
||||
HttpResponse.json({ enabled: true })
|
||||
http.get('/api/addons', () =>
|
||||
HttpResponse.json({ bagTracking: true, addons: [] })
|
||||
),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 5, name: 'MyBag', color: '#ec4899', weight_limit_grams: null, members: [] }] })
|
||||
@@ -957,7 +968,7 @@ describe('PackingListPanel', () => {
|
||||
it('FE-COMP-PACKING-055: apply template button click opens template dropdown and shows template', async () => {
|
||||
const user = userEvent.setup();
|
||||
server.use(
|
||||
http.get('/api/admin/packing-templates', () =>
|
||||
http.get('/api/trips/:id/packing/templates', () =>
|
||||
HttpResponse.json({ templates: [{ id: 3, name: 'Weekend Pack', item_count: 8 }] })
|
||||
)
|
||||
);
|
||||
@@ -1124,7 +1135,7 @@ describe('PackingListPanel', () => {
|
||||
const user = userEvent.setup();
|
||||
let applyCalled = false;
|
||||
server.use(
|
||||
http.get('/api/admin/packing-templates', () =>
|
||||
http.get('/api/trips/:id/packing/templates', () =>
|
||||
HttpResponse.json({ templates: [{ id: 5, name: 'Beach Trip', item_count: 12 }] })
|
||||
),
|
||||
http.post('/api/trips/1/packing/apply-template/5', () => {
|
||||
@@ -1177,7 +1188,7 @@ describe('PackingListPanel', () => {
|
||||
const user = userEvent.setup();
|
||||
let createBody: Record<string, unknown> | null = null;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () => HttpResponse.json({ enabled: true })),
|
||||
http.get('/api/addons', () => HttpResponse.json({ bagTracking: true, addons: [] })),
|
||||
// Start with one bag so the sidebar renders (sidebar requires bags.length > 0)
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 1, name: 'Existing Bag', color: '#6366f1', weight_limit_grams: null, members: [] }] })
|
||||
@@ -1207,7 +1218,7 @@ describe('PackingListPanel', () => {
|
||||
const user = userEvent.setup();
|
||||
let deleteCalled = false;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () => HttpResponse.json({ enabled: true })),
|
||||
http.get('/api/addons', () => HttpResponse.json({ bagTracking: true, addons: [] })),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 9, name: 'Old Bag', color: '#6366f1', weight_limit_grams: null, members: [] }] })
|
||||
),
|
||||
@@ -1235,7 +1246,7 @@ describe('PackingListPanel', () => {
|
||||
const user = userEvent.setup();
|
||||
let updateBody: Record<string, unknown> | null = null;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () => HttpResponse.json({ enabled: true })),
|
||||
http.get('/api/addons', () => HttpResponse.json({ bagTracking: true, addons: [] })),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 11, name: 'Carry-on', color: '#10b981', weight_limit_grams: null, members: [] }] })
|
||||
),
|
||||
@@ -1273,7 +1284,7 @@ describe('PackingListPanel', () => {
|
||||
current_user_id: 1,
|
||||
})
|
||||
),
|
||||
http.get('/api/admin/bag-tracking', () => HttpResponse.json({ enabled: true })),
|
||||
http.get('/api/addons', () => HttpResponse.json({ bagTracking: true, addons: [] })),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 12, name: 'Day Pack', color: '#ec4899', weight_limit_grams: null, members: [] }] })
|
||||
)
|
||||
@@ -1314,7 +1325,7 @@ describe('PackingListPanel', () => {
|
||||
current_user_id: 1,
|
||||
})
|
||||
),
|
||||
http.get('/api/admin/bag-tracking', () => HttpResponse.json({ enabled: true })),
|
||||
http.get('/api/addons', () => HttpResponse.json({ bagTracking: true, addons: [] })),
|
||||
http.get('/api/trips/:id/packing/bags', () =>
|
||||
HttpResponse.json({ bags: [{ id: 13, name: 'Weekend Bag', color: '#f97316', weight_limit_grams: null, members: [] }] })
|
||||
),
|
||||
@@ -1352,7 +1363,7 @@ describe('PackingListPanel', () => {
|
||||
it('FE-COMP-PACKING-068: inline bag create in item row picker creates bag and assigns it', async () => {
|
||||
let createBody: Record<string, unknown> | null = null;
|
||||
server.use(
|
||||
http.get('/api/admin/bag-tracking', () => HttpResponse.json({ enabled: true })),
|
||||
http.get('/api/addons', () => HttpResponse.json({ bagTracking: true, addons: [] })),
|
||||
http.get('/api/trips/:id/packing/bags', () => HttpResponse.json({ bags: [] })),
|
||||
http.post('/api/trips/1/packing/bags', async ({ request }) => {
|
||||
createBody = await request.json() as Record<string, unknown>;
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { PackingState } from './usePackingListPanel'
|
||||
|
||||
export function PackingHeader(S: PackingState) {
|
||||
const {
|
||||
inlineHeader, t, items, abgehakt, fortschritt, canEdit,
|
||||
inlineHeader, t, items, abgehakt, fortschritt, canEdit, isAdmin,
|
||||
showSaveTemplate, saveTemplateName, setSaveTemplateName, handleSaveAsTemplate, setShowSaveTemplate,
|
||||
setShowImportModal, handleClearChecked, availableTemplates, templateDropdownRef,
|
||||
showTemplateDropdown, setShowTemplateDropdown, applyingTemplate, handleApplyTemplate,
|
||||
@@ -26,7 +26,7 @@ export function PackingHeader(S: PackingState) {
|
||||
</div>
|
||||
) : <span />}
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
||||
{canEdit && items.length > 0 && showSaveTemplate && (
|
||||
{canEdit && isAdmin && items.length > 0 && showSaveTemplate && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||
<input
|
||||
type="text" autoFocus
|
||||
@@ -97,7 +97,7 @@ export function PackingHeader(S: PackingState) {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{inlineHeader && canEdit && items.length > 0 && !showSaveTemplate && (
|
||||
{inlineHeader && canEdit && isAdmin && items.length > 0 && !showSaveTemplate && (
|
||||
<button onClick={() => setShowSaveTemplate(true)} style={{
|
||||
display: 'flex', alignItems: 'center', gap: 5, padding: '5px 11px', borderRadius: 99,
|
||||
border: '1px solid var(--border-primary)', fontSize: 12, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit',
|
||||
|
||||
@@ -2,9 +2,11 @@ import { useState, useMemo, useRef, useEffect } from 'react'
|
||||
import type { ChangeEvent } from 'react'
|
||||
import { useTripStore } from '../../store/tripStore'
|
||||
import { useCanDo } from '../../store/permissionsStore'
|
||||
import { useAuthStore } from '../../store/authStore'
|
||||
import { useToast } from '../shared/Toast'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { packingApi, tripsApi, adminApi } from '../../api/client'
|
||||
import { packingApi, tripsApi } from '../../api/client'
|
||||
import { useAddonStore } from '../../store/addonStore'
|
||||
import type { PackingItem, PackingBag } from '../../types'
|
||||
import { BAG_COLORS } from './packingListPanel.constants'
|
||||
import { parseImportLines } from './packingListPanel.helpers'
|
||||
@@ -46,6 +48,7 @@ export function usePackingList({ tripId, items, openImportSignal = 0, clearCheck
|
||||
const can = useCanDo()
|
||||
const trip = useTripStore((s) => s.trip)
|
||||
const canEdit = can('packing_edit', trip)
|
||||
const isAdmin = useAuthStore((s) => s.user?.role === 'admin')
|
||||
const toast = useToast()
|
||||
const { t } = useTranslation()
|
||||
|
||||
@@ -145,19 +148,24 @@ export function usePackingList({ tripId, items, openImportSignal = 0, clearCheck
|
||||
if (failed) toast.error(t('packing.toast.deleteError'))
|
||||
}
|
||||
|
||||
// Bag tracking
|
||||
const [bagTrackingEnabled, setBagTrackingEnabled] = useState(false)
|
||||
// Bag tracking — the global toggle is a packing sub-flag surfaced to every
|
||||
// authenticated user via the addon store (loaded on app start), not the
|
||||
// admin-only endpoint, so non-admin members see weights/bags too.
|
||||
const bagTrackingEnabled = useAddonStore(s => s.bagTracking)
|
||||
const addonsLoaded = useAddonStore(s => s.loaded)
|
||||
const loadAddons = useAddonStore(s => s.loadAddons)
|
||||
const [bags, setBags] = useState<PackingBag[]>([])
|
||||
const [newBagName, setNewBagName] = useState('')
|
||||
const [showAddBag, setShowAddBag] = useState(false)
|
||||
const [showBagModal, setShowBagModal] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
adminApi.getBagTracking().then(d => {
|
||||
setBagTrackingEnabled(d.enabled)
|
||||
if (d.enabled) packingApi.listBags(tripId).then(r => setBags(r.bags || [])).catch(() => {})
|
||||
}).catch(() => {})
|
||||
}, [tripId])
|
||||
if (!addonsLoaded) loadAddons()
|
||||
}, [addonsLoaded, loadAddons])
|
||||
|
||||
useEffect(() => {
|
||||
if (bagTrackingEnabled) packingApi.listBags(tripId).then(r => setBags(r.bags || [])).catch(() => {})
|
||||
}, [tripId, bagTrackingEnabled])
|
||||
|
||||
const handleCreateBag = async () => {
|
||||
if (!newBagName.trim()) return
|
||||
@@ -234,7 +242,7 @@ export function usePackingList({ tripId, items, openImportSignal = 0, clearCheck
|
||||
const templateDropdownRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
adminApi.packingTemplates().then(d => setAvailableTemplates(d.templates || [])).catch(() => {})
|
||||
packingApi.listTemplates(tripId).then(d => setAvailableTemplates(d.templates || [])).catch(() => {})
|
||||
}, [tripId])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -267,7 +275,7 @@ export function usePackingList({ tripId, items, openImportSignal = 0, clearCheck
|
||||
toast.success(t('packing.templateSaved'))
|
||||
setShowSaveTemplate(false)
|
||||
setSaveTemplateName('')
|
||||
adminApi.packingTemplates().then(d => setAvailableTemplates(d.templates || [])).catch(() => {})
|
||||
packingApi.listTemplates(tripId).then(d => setAvailableTemplates(d.templates || [])).catch(() => {})
|
||||
} catch {
|
||||
toast.error(t('common.error'))
|
||||
}
|
||||
@@ -297,7 +305,7 @@ export function usePackingList({ tripId, items, openImportSignal = 0, clearCheck
|
||||
const font = { fontFamily: "var(--font-system)" }
|
||||
|
||||
return {
|
||||
tripId, items, inlineHeader, t, canEdit, font,
|
||||
tripId, items, inlineHeader, t, canEdit, isAdmin, font,
|
||||
filter, setFilter, addingCategory, setAddingCategory, newCatName, setNewCatName,
|
||||
tripMembers, categoryAssignees, handleSetAssignees, allCategories, gruppiert, abgehakt, fortschritt,
|
||||
handleAddItemToCategory, handleAddNewCategory, handleRenameCategory, handleDeleteCategory, handleClearChecked,
|
||||
|
||||
@@ -175,6 +175,9 @@ function useDefaultAtlasHandlers() {
|
||||
http.get('/api/addons/atlas/stats', () => HttpResponse.json(atlasStatsResponse)),
|
||||
http.get('/api/addons/atlas/bucket-list', () => HttpResponse.json({ items: [] })),
|
||||
http.get('/api/addons/atlas/regions', () => HttpResponse.json({ regions: {} })),
|
||||
// Country-border GeoJSON (admin-0) — served by the API now. Tests that need real
|
||||
// country features override this handler via server.use(...).
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json({ type: 'FeatureCollection', features: [] })),
|
||||
// Handler for region GeoJSON fetch (triggered by loadRegionsForViewport when intersects=true)
|
||||
http.get('/api/addons/atlas/regions/geo', () => HttpResponse.json({ features: [] })),
|
||||
);
|
||||
@@ -187,18 +190,6 @@ beforeEach(() => {
|
||||
seedStore(useAuthStore, { isAuthenticated: true, user: buildUser() });
|
||||
seedStore(useSettingsStore, { settings: buildSettings({ dark_mode: false }) });
|
||||
|
||||
// Stub the external GeoJSON fetch (GitHub raw URL) to avoid real network calls
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ type: 'FeatureCollection', features: [] }),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
|
||||
useDefaultAtlasHandlers();
|
||||
});
|
||||
|
||||
@@ -469,16 +460,9 @@ describe('AtlasPage', () => {
|
||||
describe('FE-PAGE-ATLAS-017: country search filters options from GeoJSON', () => {
|
||||
it('typing in search updates the input value', async () => {
|
||||
// Override fetch to return GeoJSON with FR feature
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<AtlasPage />);
|
||||
@@ -519,16 +503,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-019: confirm popup shows via Enter on search with GeoJSON', () => {
|
||||
it('pressing Enter in search with matching GeoJSON result triggers confirm popup', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.post('/api/addons/atlas/country/:code/mark', () => HttpResponse.json({ success: true })),
|
||||
@@ -600,16 +577,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-022: confirm popup for bucket type shows month/year selects', () => {
|
||||
it('selecting Add to bucket list in confirm popup shows month/year pickers', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<AtlasPage />);
|
||||
@@ -642,16 +612,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-031: confirm popup opens and mark-visited action works', () => {
|
||||
it('opens confirm popup via search and clicking Mark as visited closes it', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.post('/api/addons/atlas/country/:code/mark', () => HttpResponse.json({ success: true })),
|
||||
@@ -710,16 +673,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-032: confirm popup Add to Bucket opens bucket type', () => {
|
||||
it('clicking Add to bucket list in choose popup switches to bucket type', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<AtlasPage />);
|
||||
@@ -851,16 +807,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-029: confirm popup opens via search dropdown click', () => {
|
||||
it('clicking a country in the search dropdown opens the confirm action popup', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.post('/api/addons/atlas/country/:code/mark', () => HttpResponse.json({ success: true })),
|
||||
@@ -914,16 +863,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-030: confirm popup overlay click closes it', () => {
|
||||
it('clicking the overlay backdrop closes the confirm popup', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(geoJsonWithFR),
|
||||
} as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<AtlasPage />);
|
||||
@@ -1000,13 +942,9 @@ describe('AtlasPage', () => {
|
||||
{ type: 'Feature', properties: { ISO_A2: 'DE', ADM0_A3: 'DEU', ISO_A3: 'DEU', NAME: 'Germany', ADMIN: 'Germany' }, geometry: null },
|
||||
],
|
||||
};
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonFRandDE) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonFRandDE)),
|
||||
);
|
||||
|
||||
render(<AtlasPage />);
|
||||
|
||||
@@ -1023,13 +961,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-034: dropdown button click + mouse events', () => {
|
||||
it('clicking France dropdown button covers onClick and mouse event handlers', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonWithFR) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.post('/api/addons/atlas/country/:code/mark', () => HttpResponse.json({ success: true })),
|
||||
@@ -1100,13 +1034,9 @@ describe('AtlasPage', () => {
|
||||
http.get('/api/addons/atlas/stats', () => HttpResponse.json(emptyAtlasResponse)),
|
||||
http.post('/api/addons/atlas/country/:code/mark', () => HttpResponse.json({ success: true })),
|
||||
);
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonWithFR) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<AtlasPage />);
|
||||
@@ -1158,13 +1088,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-036: bucket popup submit action', () => {
|
||||
it('submits a bucket list item from the confirm popup', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonWithFR) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.post('/api/addons/atlas/bucket-list', () =>
|
||||
@@ -1321,13 +1247,9 @@ describe('AtlasPage', () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonWithXK) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithXK)),
|
||||
);
|
||||
|
||||
render(<AtlasPage />);
|
||||
|
||||
@@ -1345,13 +1267,9 @@ describe('AtlasPage', () => {
|
||||
{ a3: 'FRA', name: 'France', query: 'france' },
|
||||
{ a3: 'NOR', name: 'Norway', query: 'norway' },
|
||||
])('returns $name in search results when GeoJSON provides ADM0_A3=$a3 but ISO_A2 is -99', async ({ a3, name, query }) => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(makeGeoJsonWithA3Fallback(a3, name)) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(makeGeoJsonWithA3Fallback(a3, name))),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<AtlasPage />);
|
||||
@@ -1459,13 +1377,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-044: direct France dropdown button click', () => {
|
||||
it('directly finds and clicks the France button in the dropdown to cover onClick', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonWithFR) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.post('/api/addons/atlas/country/:code/mark', () => HttpResponse.json({ success: true })),
|
||||
@@ -1517,13 +1431,9 @@ describe('AtlasPage', () => {
|
||||
|
||||
describe('FE-PAGE-ATLAS-045: dark mode toggle covers map re-init + loadRegionsForViewport', () => {
|
||||
it('switching to dark mode re-initializes map and covers region loading code path', async () => {
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonWithFR) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonWithFR)),
|
||||
);
|
||||
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/regions/geo', () => HttpResponse.json({ features: [] })),
|
||||
@@ -1636,13 +1546,9 @@ describe('AtlasPage', () => {
|
||||
{ type: 'Feature', properties: { ISO_A2: 'IT', ADM0_A3: 'ITA', ISO_A3: 'ITA', NAME: 'Italy', ADMIN: 'Italy' }, geometry: null },
|
||||
],
|
||||
};
|
||||
vi.spyOn(global, 'fetch').mockImplementation((url) => {
|
||||
const urlStr = String(url);
|
||||
if (urlStr.includes('geojson') || urlStr.includes('githubusercontent')) {
|
||||
return Promise.resolve({ ok: true, json: () => Promise.resolve(geoJsonFRandIT) } as Response);
|
||||
}
|
||||
return Promise.reject(new Error(`Unmocked fetch: ${urlStr}`));
|
||||
});
|
||||
server.use(
|
||||
http.get('/api/addons/atlas/countries/geo', () => HttpResponse.json(geoJsonFRandIT)),
|
||||
);
|
||||
|
||||
render(<AtlasPage />);
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ function ListsContainer({ tripId, packingItems, todoItems }: { tripId: number; p
|
||||
const [saveTemplateSignal, setSaveTemplateSignal] = useState(0)
|
||||
const [addTodoSignal, setAddTodoSignal] = useState(0)
|
||||
const { t } = useTranslation()
|
||||
const isAdmin = useAuthStore(s => s.user?.role === 'admin')
|
||||
|
||||
const tabs = [
|
||||
{ id: 'packing' as const, label: t('todo.subtab.packing'), icon: PackageCheck, count: packingItems.length },
|
||||
@@ -121,7 +122,7 @@ function ListsContainer({ tripId, packingItems, todoItems }: { tripId: number; p
|
||||
className={`${sharedBtnClass} bg-accent text-accent-text`}
|
||||
style={sharedBtnStyle}
|
||||
/>
|
||||
{packingItems.length > 0 && (
|
||||
{isAdmin && packingItems.length > 0 && (
|
||||
<button onClick={() => setSaveTemplateSignal(s => s + 1)}
|
||||
className={`${sharedBtnClass} bg-accent text-accent-text`}
|
||||
style={sharedBtnStyle}
|
||||
|
||||
@@ -132,18 +132,19 @@ export function useAtlas() {
|
||||
}).catch(() => setLoading(false))
|
||||
}, [])
|
||||
|
||||
// Load GeoJSON world data (direct GeoJSON, no conversion needed)
|
||||
// Load country-border GeoJSON from our API (geoBoundaries, served server-side —
|
||||
// no third-party fetch from the browser).
|
||||
useEffect(() => {
|
||||
fetch('https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_50m_admin_0_countries.geojson')
|
||||
.then(r => r.json())
|
||||
.then(geo => {
|
||||
apiClient.get('/addons/atlas/countries/geo')
|
||||
.then(res => {
|
||||
const geo = res.data
|
||||
// Dynamically build A2→A3 mapping from GeoJSON
|
||||
for (const f of geo.features) {
|
||||
const a2 = f.properties?.ISO_A2
|
||||
const a3 = f.properties?.ADM0_A3 || f.properties?.ISO_A3
|
||||
// Only real 2-letter ISO codes: natural-earth uses subdivision-style
|
||||
// values like "CN-TW" for Taiwan, which would otherwise overwrite the
|
||||
// legitimate TWN->TW reverse mapping and break the country (#1049).
|
||||
// Only accept clean 2-letter ISO codes and never overwrite an existing
|
||||
// mapping: some datasets carry subdivision-style values like "CN-TW" for
|
||||
// Taiwan, which would clobber the legitimate TWN->TW entry (#1049).
|
||||
if (a2 && a3 && a2.length === 2 && a2 !== '-99' && a3 !== '-99' && !A2_TO_A3[a2]) {
|
||||
A2_TO_A3[a2] = a3
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ interface Addon {
|
||||
|
||||
interface AddonState {
|
||||
addons: Addon[]
|
||||
bagTracking: boolean
|
||||
loaded: boolean
|
||||
loadAddons: () => Promise<void>
|
||||
isEnabled: (id: string) => boolean
|
||||
@@ -31,12 +32,13 @@ interface AddonState {
|
||||
|
||||
export const useAddonStore = create<AddonState>((set, get) => ({
|
||||
addons: [],
|
||||
bagTracking: false,
|
||||
loaded: false,
|
||||
|
||||
loadAddons: async () => {
|
||||
try {
|
||||
const data = await addonsApi.enabled()
|
||||
set({ addons: data.addons || [], loaded: true })
|
||||
set({ addons: data.addons || [], bagTracking: !!data.bagTracking, loaded: true })
|
||||
} catch {
|
||||
set({ loaded: true })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user