mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 06:37:33 +00:00
feat(collections): fusion sharing UI + dashboard widget + per-user toggle (#1081)
- ShareCollectionModal: the owner manages a list's members and invites users (available-users picker → invite, cancel pending); a member can leave a shared list. The incoming accept/decline surface stays in the lists rail. A Share button is added to the collections header for owners (and members, to reach Leave). - CollectionsWidget: a dashboard glass card after the currency widget showing the saved count and the most recent saved places, double-gated by the admin addon and a new per-user appearance flag. - Appearance: a 'collections' dashboard-widget flag (desktop + mobile defaults) wired into the appearance settings, surviving normalize. - Sharing + settings strings across all 22 locales (parity strict passes).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import { LayoutGrid, List as ListIcon, Map as MapIcon, Search, Bookmark, Plus, CheckSquare, X, Trash2, Copy } from 'lucide-react'
|
||||
import { LayoutGrid, List as ListIcon, Map as MapIcon, Search, Bookmark, Plus, CheckSquare, X, Trash2, Copy, Share2, Users } from 'lucide-react'
|
||||
import Navbar from '../components/Layout/Navbar'
|
||||
import Modal from '../components/shared/Modal'
|
||||
import ListsRail from '../components/Collections/ListsRail'
|
||||
@@ -7,6 +7,7 @@ import CollectionGrid from '../components/Collections/CollectionGrid'
|
||||
import CollectionList from '../components/Collections/CollectionList'
|
||||
import CollectionMap from '../components/Collections/CollectionMap'
|
||||
import CopyToTripModal from '../components/Collections/CopyToTripModal'
|
||||
import ShareCollectionModal from '../components/Collections/ShareCollectionModal'
|
||||
import PlaceInspector from '../components/Planner/PlaceInspector'
|
||||
import type { TranslationFn } from '../types'
|
||||
import type { CollectionView, StatusFilter } from '../store/collectionStore'
|
||||
@@ -199,6 +200,21 @@ export default function CollectionsPage(): React.ReactElement {
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<ViewSwitch view={c.view} onChange={c.setView} t={t} />
|
||||
{c.canShare && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => c.setShowShare(true)}
|
||||
className="relative inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-[12px] font-medium border bg-surface-card text-content-secondary border-edge hover:bg-surface-hover transition-colors"
|
||||
>
|
||||
{c.isOwner ? <Share2 size={14} /> : <Users size={14} />}
|
||||
<span className="hidden sm:inline">{c.isOwner ? t('collections.share.button') : t('collections.shared')}</span>
|
||||
{c.shareMemberCount > 0 && (
|
||||
<span className="inline-flex items-center justify-center min-w-[16px] h-4 px-1 rounded-full bg-accent text-accent-text text-[10px] font-semibold tabular-nums">
|
||||
{c.shareMemberCount}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
{showSelect && (
|
||||
<button
|
||||
type="button"
|
||||
@@ -314,6 +330,20 @@ export default function CollectionsPage(): React.ReactElement {
|
||||
t={t}
|
||||
/>
|
||||
|
||||
{/* Share / fusion */}
|
||||
{c.canShare && typeof c.activeId === 'number' && c.activeCollection && (
|
||||
<ShareCollectionModal
|
||||
isOpen={c.showShare}
|
||||
onClose={() => c.setShowShare(false)}
|
||||
collectionId={c.activeId}
|
||||
collectionName={c.activeCollection.name}
|
||||
isOwner={c.isOwner}
|
||||
members={c.members}
|
||||
onAfterLeave={c.handleAfterLeave}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* New list modal */}
|
||||
<Modal
|
||||
isOpen={c.showNewList}
|
||||
|
||||
@@ -19,9 +19,11 @@ import {
|
||||
LayoutGrid, List, Ticket, X, CalendarPlus,
|
||||
} from 'lucide-react'
|
||||
import { IcsSubscribeModal } from '../components/Planner/IcsSubscribeModal'
|
||||
import CollectionsWidget from '../components/Dashboard/CollectionsWidget'
|
||||
import { formatTime, splitReservationDateTime } from '../utils/formatters'
|
||||
import { convertDistance, getDistanceUnitLabel } from '../utils/units'
|
||||
import { useSettingsStore } from '../store/settingsStore'
|
||||
import { useAddonStore } from '../store/addonStore'
|
||||
import { normalizeAppearance } from '@trek/shared'
|
||||
import '../styles/dashboard.css'
|
||||
|
||||
@@ -119,8 +121,11 @@ export default function DashboardPage(): React.ReactElement {
|
||||
const showCurrency = sideWidgets.currency
|
||||
const showTimezones = sideWidgets.timezones
|
||||
const showUpcoming = sideWidgets.upcomingReservations
|
||||
// Collections is double-gated: the admin addon AND the per-user widget flag.
|
||||
const isAddonEnabled = useAddonStore(s => s.isEnabled)
|
||||
const showCollections = isAddonEnabled('collections') && sideWidgets.collections
|
||||
// Desktop has a master toggle for the whole right column; off → centered layout.
|
||||
const sidebarVisible = (isMobile || dashCfg.desktop.sidebar) && (showCurrency || showTimezones || showUpcoming)
|
||||
const sidebarVisible = (isMobile || dashCfg.desktop.sidebar) && (showCurrency || showCollections || showTimezones || showUpcoming)
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -226,6 +231,7 @@ export default function DashboardPage(): React.ReactElement {
|
||||
{sidebarVisible && (
|
||||
<aside className="page-sidebar">
|
||||
{showCurrency && <CurrencyTool />}
|
||||
{showCollections && <CollectionsWidget onOpen={() => navigate('/collections')} />}
|
||||
{showTimezones && <TimezoneTool locale={locale} />}
|
||||
{showUpcoming && <UpcomingTool items={upcoming} locale={locale} onOpen={(tripId) => navigate(`/trips/${tripId}`)} />}
|
||||
</aside>
|
||||
|
||||
@@ -48,6 +48,7 @@ export function useCollections() {
|
||||
const [confirmDeleteList, setConfirmDeleteList] = useState<number | null>(null)
|
||||
const [mobileRailOpen, setMobileRailOpen] = useState(false)
|
||||
const [creating, setCreating] = useState(false)
|
||||
const [showShare, setShowShare] = useState(false)
|
||||
// The place ids the Copy-to-trip modal is open for (null = closed). Single
|
||||
// place from the detail panel, or the select-mode set for a bulk copy.
|
||||
const [copyIds, setCopyIds] = useState<number[] | null>(null)
|
||||
@@ -97,6 +98,14 @@ export function useCollections() {
|
||||
const isAllSaved = activeId === ALL_SAVED
|
||||
const isOwner = activeCollection?.is_owner ?? false
|
||||
|
||||
// Sharing is offered on any real (non "All saved") list the user can see. The
|
||||
// badge counts everyone but the owner — accepted collaborators + pending invites.
|
||||
const canShare = typeof activeId === 'number' && activeCollection != null
|
||||
const shareMemberCount = useMemo(() => members.filter(m => !m.is_owner).length, [members])
|
||||
|
||||
// Close the share modal if the active list changes out from under it.
|
||||
useEffect(() => { setShowShare(false) }, [activeId])
|
||||
|
||||
const ownedLists = useMemo(() => collections.filter(c => c.is_owner !== false), [collections])
|
||||
const sharedLists = useMemo(() => collections.filter(c => c.is_owner === false), [collections])
|
||||
|
||||
@@ -210,6 +219,13 @@ export function useCollections() {
|
||||
}
|
||||
}, [declineInvite, toast, t])
|
||||
|
||||
// Member left the active shared list — the store already cleared it; bounce to
|
||||
// the rail and close the share modal. Errors are surfaced inside the modal.
|
||||
const handleAfterLeave = useCallback(() => {
|
||||
setShowShare(false)
|
||||
navigate('/collections')
|
||||
}, [navigate])
|
||||
|
||||
// ── Detail panel (re-pointed PlaceInspector in collection mode) ──────
|
||||
const selectedPlace = useMemo(
|
||||
() => places.find(p => p.id === selectedPlaceId) ?? null,
|
||||
@@ -263,6 +279,7 @@ export function useCollections() {
|
||||
t, language, dark, navigate,
|
||||
// store data
|
||||
collections, ownedLists, sharedLists, activeCollection, isAllSaved, isOwner,
|
||||
canShare, shareMemberCount,
|
||||
activeId, places, visiblePlaces, members, incomingInvites, counts,
|
||||
view, statusFilter, search, selectedPlaceId, selectMode, selectedIds,
|
||||
loading, placesLoading,
|
||||
@@ -273,6 +290,7 @@ export function useCollections() {
|
||||
editingListId, editingName, setEditingName,
|
||||
confirmDeleteList, setConfirmDeleteList,
|
||||
mobileRailOpen, setMobileRailOpen,
|
||||
showShare, setShowShare, handleAfterLeave,
|
||||
// detail panel + copy-to-trip
|
||||
selectedPlace, detailPlace, detailCategories, handleCloseDetail,
|
||||
handleDetailStatus, handleDetailRemove,
|
||||
|
||||
Reference in New Issue
Block a user