Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

Health endpoint, file types config, budget rename, UI fixes

Maurice785e8264cdc3
diff --git a/client/src/api/client.js b/client/src/api/client.js
index 72f1673ac..e793772f1 100644
--- a/client/src/api/client.js
+++ b/client/src/api/client.js
@@ -194,6 +194,24 @@ export const dayNotesApi = {
delete: (tripId, dayId, id) => apiClient.delete(`/trips/${tripId}/days/${dayId}/notes/${id}`).then(r => r.data),
}
+export const collabApi = {
+ // Notes
+ getNotes: (tripId) => apiClient.get(`/trips/${tripId}/collab/notes`).then(r => r.data),
+ createNote: (tripId, data) => apiClient.post(`/trips/${tripId}/collab/notes`, data).then(r => r.data),
+ updateNote: (tripId, id, data) => apiClient.put(`/trips/${tripId}/collab/notes/${id}`, data).then(r => r.data),
+ deleteNote: (tripId, id) => apiClient.delete(`/trips/${tripId}/collab/notes/${id}`).then(r => r.data),
+ // Polls
+ getPolls: (tripId) => apiClient.get(`/trips/${tripId}/collab/polls`).then(r => r.data),
+ createPoll: (tripId, data) => apiClient.post(`/trips/${tripId}/collab/polls`, data).then(r => r.data),
+ votePoll: (tripId, id, optionIndex) => apiClient.post(`/trips/${tripId}/collab/polls/${id}/vote`, { option_index: optionIndex }).then(r => r.data),
+ closePoll: (tripId, id) => apiClient.put(`/trips/${tripId}/collab/polls/${id}/close`).then(r => r.data),
+ deletePoll: (tripId, id) => apiClient.delete(`/trips/${tripId}/collab/polls/${id}`).then(r => r.data),
+ // Chat
+ getMessages: (tripId, before) => apiClient.get(`/trips/${tripId}/collab/messages${before ? `?before=${before}` : ''}`).then(r => r.data),
+ sendMessage: (tripId, data) => apiClient.post(`/trips/${tripId}/collab/messages`, data).then(r => r.data),
+ deleteMessage: (tripId, id) => apiClient.delete(`/trips/${tripId}/collab/messages/${id}`).then(r => r.data),
+}
+
export const backupApi = {
list: () => apiClient.get('/backup/list').then(r => r.data),
create: () => apiClient.post('/backup/create').then(r => r.data),
diff --git a/client/src/components/Admin/AddonManager.jsx b/client/src/components/Admin/AddonManager.jsx
index 30bba764f..3f9144839 100644
--- a/client/src/components/Admin/AddonManager.jsx
+++ b/client/src/components/Admin/AddonManager.jsx
@@ -118,8 +118,9 @@ export default function AddonManager() {
}
function AddonRow({ addon, onToggle, t }) {
+ const isComingSoon = addon.id === 'collab'
return (
- <div className="flex items-center gap-4 px-6 py-4 border-b transition-colors hover:opacity-95" style={{ borderColor: 'var(--border-secondary)' }}>
+ <div className="flex items-center gap-4 px-6 py-4 border-b transition-colors hover:opacity-95" style={{ borderColor: 'var(--border-secondary)', opacity: isComingSoon ? 0.5 : 1, pointerEvents: isComingSoon ? 'none' : 'auto' }}>
{/* Icon */}
<div className="w-10 h-10 rounded-xl flex items-center justify-center shrink-0" style={{ background: 'var(--bg-secondary)', color: 'var(--text-primary)' }}>
<AddonIcon name={addon.icon} size={20} />
@@ -129,6 +130,11 @@ function AddonRow({ addon, onToggle, t }) {
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="text-sm font-semibold" style={{ color: 'var(--text-primary)' }}>{addon.name}</span>
+ {isComingSoon && (
+ <span className="text-[9px] font-semibold px-2 py-0.5 rounded-full" style={{ background: 'var(--bg-tertiary)', color: 'var(--text-faint)' }}>
+ Coming Soon
+ </span>
+ )}
<span className="text-[10px] font-medium px-1.5 py-0.5 rounded-full" style={{
background: addon.type === 'global' ? 'var(--bg-secondary)' : 'var(--bg-secondary)',
color: 'var(--text-muted)',
@@ -141,19 +147,20 @@ function AddonRow({ addon, onToggle, t }) {
{/* Toggle */}
<div className="flex items-center gap-2 shrink-0">
- <span className="text-xs font-medium" style={{ color: addon.enabled ? 'var(--text-primary)' : 'var(--text-faint)' }}>
- {addon.enabled ? t('admin.addons.enabled') : t('admin.addons.disabled')}
+ <span className="text-xs font-medium" style={{ color: (addon.enabled && !isComingSoon) ? 'var(--text-primary)' : 'var(--text-faint)' }}>
+ {isComingSoon ? t('admin.addons.disabled') : addon.enabled ? t('admin.addons.enabled') : t('admin.addons.disabled')}
</span>
<button
- onClick={() => onToggle(addon)}
+ onClick={() => !isComingSoon && onToggle(addon)}
+ disabled={isComingSoon}
className="relative inline-flex h-6 w-11 items-center rounded-full transition-colors"
- style={{ background: addon.enabled ? 'var(--text-primary)' : 'var(--border-primary)' }}
+ style={{ background: (addon.enabled && !isComingSoon) ? 'var(--text-primary)' : 'var(--border-primary)', cursor: isComingSoon ? 'not-allowed' : 'pointer' }}
>
<span
className="inline-block h-4 w-4 transform rounded-full transition-transform"
style={{
- background: addon.enabled ? 'var(--bg-card)' : 'var(--bg-card)',
- transform: addon.enabled ? 'translateX(22px)' : 'translateX(4px)',
+ background: 'var(--bg-card)',
+ transform: (addon.enabled && !isComingSoon) ? 'translateX(22px)' : 'translateX(4px)',
}}
/>
</button>
diff --git a/client/src/components/Collab/CollabChat.jsx b/client/src/components/Collab/CollabChat.jsx
new file mode 100644
index 000000000..78b22e9ee
--- /dev/null
+++ b/client/src/components/Collab/CollabChat.jsx
@@ -0,0 +1,615 @@
+import React, { useState, useEffect, useRef, useCallback } from 'react'
+import { Send, Trash2, Reply, ChevronUp, MessageCircle } from 'lucide-react'
+import { collabApi } from '../../api/client'
+import { addListener, removeListener } from '../../api/websocket'
+import { useTranslation } from '../../i18n'
+
+/* ───────── relative timestamp ───────── */
+function formatRelativeTime(isoString, t) {
+ const now = Date.now()
+ const then = new Date(isoString).getTime()
+ const diff = now - then
+
+ const seconds = Math.floor(diff / 1000)
+ const minutes = Math.floor(seconds / 60)
+ const hours = Math.floor(minutes / 60)
+
+ if (seconds < 60) return t('collab.chat.justNow')
+ if (minutes < 60) return t('collab.chat.minutesAgo', { n: minutes })
+ if (hours < 24) return t('collab.chat.hoursAgo', { n: hours })
+
+ const d = new Date(isoString)
+ const today = new Date()
+ const yesterday = new Date()
+ yesterday.setDate(today.getDate() - 1)
+
+ if (
+ d.getDate() === yesterday.getDate() &&
+ d.getMonth() === yesterday.getMonth() &&
+ d.getFullYear() === yesterday.getFullYear()
+ ) {
+ const hh = String(d.getHours()).padStart(2, '0')
+ const mm = String(d.getMinutes()).padStart(2, '0')
+ return `yesterday ${hh}:${mm}`
+ }
+
+ const monthNames = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
+ return `${monthNames[d.getMonth()]} ${d.getDate()}`
+}
+
+/* ─────────────────────────────────────── */
+/* Component */
+/* ─────────────────────────────────────── */
+export default function CollabChat({ tripId, currentUser }) {
+ const { t } = useTranslation()
+
+ const [messages, setMessages] = useState([])
+ const [loading, setLoading] = useState(true)
+ const [hasMore, setHasMore] = useState(false)
+ const [loadingMore, setLoadingMore] = useState(false)
+ const [text, setText] = useState('')
+ const [replyTo, setReplyTo] = useState(null)
+ const [hoveredId, setHoveredId] = useState(null)
+ const [sending, setSending] = useState(false)
+
+ const scrollRef = useRef(null)
+ const textareaRef = useRef(null)
+ const isAtBottom = useRef(true)
+
+ /* ── scroll helpers ── */
+ const scrollToBottom = useCallback((behavior = 'auto') => {
+ const el = scrollRef.current
+ if (!el) return
+ requestAnimationFrame(() => {
+ el.scrollTo({ top: el.scrollHeight, behavior })
+ })
+ }, [])
+
+ const checkAtBottom = useCallback(() => {
+ const el = scrollRef.current
+ if (!el) return
+ isAtBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 48
+ }, [])
+
+ /* ── load messages ── */
+ useEffect(() => {
+ let cancelled = false
+ setLoading(true)
+
+ collabApi.getMessages(tripId).then(data => {
+ if (cancelled) return
+ const msgs = Array.isArray(data) ? data : data.messages || []
+ setMessages(msgs)
+ setHasMore(msgs.length >= 100)
+ setLoading(false)
+ setTimeout(() => scrollToBottom(), 30)
+ }).catch(() => {
+ if (!cancelled) setLoading(false)
+ })
+
+ return () => { cancelled = true }
+ }, [tripId, scrollToBottom])
+
+ /* ── load more (older messages) ── */
+ const handleLoadMore = useCallback(async () => {
+ if (loadingMore || messages.length === 0) return
+ setLoadingMore(true)
+ const el = scrollRef.current
+ const prevHeight = el ? el.scrollHeight : 0
+
+ try {
+ const oldestId = messages[0]?.id
+ const data = await collabApi.getMessages(tripId, oldestId)
+ const older = Array.isArray(data) ? data : data.messages || []
+
+ if (older.length === 0) {
+ setHasMore(false)
+ } else {
+ setMessages(prev => [...older, ...prev])
+ setHasMore(older.length >= 100)
+ requestAnimationFrame(() => {
+ if (el) el.scrollTop = el.scrollHeight - prevHeight
+ })
+ }
+ } catch {
+ // silently ignore
+ } finally {
+ setLoadingMore(false)
+ }
+ }, [tripId, loadingMore, messages])
+
+ /* ── websocket ── */
+ useEffect(() => {
+ const handler = (event) => {
+ if (event.type === 'collab:message:created' && String(event.tripId) === String(tripId)) {
+ setMessages(prev => {
+ if (prev.some(m => m.id === event.message.id)) return prev
+ return [...prev, event.message]
+ })
+ if (isAtBottom.current) {
+ setTimeout(() => scrollToBottom('smooth'), 30)
+ }
+ }
+ if (event.type === 'collab:message:deleted' && String(event.tripId) === String(tripId)) {
+ setMessages(prev => prev.filter(m => m.id !== event.messageId))
+ }
+ }
+
+ addListener(handler)
+ return () => removeListener(handler)
+ }, [tripId, scrollToBottom])
+
+ /* ── auto-resize textarea ── */
+ const handleTextChange = useCallback((e) => {
+ setText(e.target.value)
+ const ta = textareaRef.current
+ if (ta) {
+ ta.style.height = 'auto'
+ ta.style.height = Math.min(ta.scrollHeight, 3 * 20 + 18) + 'px'
+ }
+ }, [])
+
+ /* ── send ── */
+ const handleSend = useCallback(async () => {
+ const body = text.trim()
+ if (!body || sending) return
+
+ setSending(true)
+ try {
+ const payload = { text: body }
+ if (replyTo) payload.reply_to = replyTo.id
+ const data = await collabApi.sendMessage(tripId, payload)
+ if (data?.message) {
+ setMessages(prev => {
+ if (prev.some(m => m.id === data.message.id)) return prev
+ return [...prev, data.message]
+ })
+ }
+ setText('')
+ setReplyTo(null)
+ if (textareaRef.current) {
+ textareaRef.current.style.height = 'auto'
+ }
+ scrollToBottom('smooth')
+ } catch {
+ // keep text on failure so user can retry
+ } finally {
+ setSending(false)
+ }
+ }, [text, sending, replyTo, tripId, scrollToBottom])
+
+ /* ── keyboard ── */
+ const handleKeyDown = useCallback((e) => {
+ if (e.key === 'Enter' && !e.shiftKey) {
+ e.preventDefault()
+ handleSend()
+ }
+ }, [handleSend])
+
+ /* ── delete ── */
+ const handleDelete = useCallback(async (msgId) => {
+ try {
+ await collabApi.deleteMessage(tripId, msgId)
+ } catch {
+ // ignore
+ }
+ }, [tripId])
+
+ /* ── find a replied-to message ── */
+ const findMessage = useCallback((id) => messages.find(m => m.id === id), [messages])
+
+ /* ── helpers ── */
+ const isOwn = (msg) => String(msg.user_id) === String(currentUser.id)
+
+ const font = "-apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif"
+
+ /* ───────── render: loading ───────── */
+ if (loading) {
+ return (
+ <div style={{
+ display: 'flex',
+ flexDirection: 'column',
+ flex: 1,
+ fontFamily: font,
+ position: 'relative',
+ overflow: 'hidden',
+ }}>
+ <div style={{
+ flex: 1,
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ justifyContent: 'center',
+ gap: 10,
+ color: 'var(--text-faint)',
+ userSelect: 'none',
+ padding: 32,
+ }}>
+ <div style={{
+ width: 24,
+ height: 24,
+ border: '2px solid var(--border-faint)',
+ borderTopColor: 'var(--accent)',
+ borderRadius: '50%',
+ animation: 'spin .7s linear infinite',
+ }} />
+ <style>{`@keyframes spin { to { transform: rotate(360deg) } }`}</style>
+ </div>
+ </div>
+ )
+ }
+
+ /* ───────── render: main ───────── */
+ return (
+ <div style={{
+ display: 'flex',
+ flexDirection: 'column',
+ flex: 1,
+ fontFamily: font,
+ position: 'relative',
+ overflow: 'hidden',
+ }}>
+ {/* ── messages area ── */}
+ {messages.length === 0 ? (
+ <div style={{
+ flex: 1,
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ justifyContent: 'center',
+ gap: 10,
+ color: 'var(--text-faint)',
+ userSelect: 'none',
+ padding: 32,
+ }}>
+ <MessageCircle size={36} strokeWidth={1.3} style={{ opacity: 0.5 }} />
+ <span style={{ fontSize: 14, fontWeight: 600, color: 'var(--text-faint)' }}>
+ {t('collab.chat.empty')}
+ </span>
+ <span style={{ fontSize: 12, color: 'var(--text-faint)', opacity: 0.7 }}>
+ {t('collab.chat.emptyDesc') || ''}
+ </span>
+ </div>
+ ) : (
+ <div
+ ref={scrollRef}
+ style={{
+ flex: 1,
+ overflowY: 'auto',
+ overflowX: 'hidden',
+ padding: '12px 16px 8px',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 4,
+ }}
+ onScroll={checkAtBottom}
+ >
+ {/* load more */}
+ {hasMore && (
+ <div style={{
+ display: 'flex',
+ justifyContent: 'center',
+ padding: '4px 0 8px',
+ }}>
+ <button
+ style={{
+ display: 'inline-flex',
+ alignItems: 'center',
+ gap: 4,
+ fontSize: 11,
+ fontWeight: 600,
+ color: 'var(--text-muted)',
+ background: 'var(--bg-secondary)',
+ border: '1px solid var(--border-faint)',
+ borderRadius: 99,
+ padding: '5px 14px',
+ cursor: 'pointer',
+ fontFamily: font,
+ textTransform: 'uppercase',
+ letterSpacing: 0.3,
+ }}
+ onClick={handleLoadMore}
+ disabled={loadingMore}
+ >
+ <ChevronUp size={13} />
+ {loadingMore ? '...' : t('collab.chat.loadMore')}
+ </button>
+ </div>
+ )}
+
+ {messages.map((msg, idx) => {
+ const own = isOwn(msg)
+ const repliedMsg = msg.reply_to_id ? findMessage(msg.reply_to_id) : null
+ const prevMsg = messages[idx - 1]
+ const isNewGroup = idx === 0 || String(prevMsg?.user_id) !== String(msg.user_id)
+ const showHeader = !own && isNewGroup
+
+ return (
+ <div
+ key={msg.id}
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: own ? 'flex-end' : 'flex-start',
+ marginTop: isNewGroup ? 12 : 0,
+ }}
+ >
+ {/* username + avatar for others */}
+ {showHeader && (
+ <div style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 6,
+ marginBottom: 4,
+ paddingLeft: 2,
+ }}>
+ {msg.user_avatar ? (
+ <img
+ src={msg.user_avatar}
+ alt=""
+ style={{
+ width: 20,
+ height: 20,
+ borderRadius: '50%',
+ objectFit: 'cover',
+ flexShrink: 0,
+ }}
+ />
+ ) : (
+ <span style={{
+ width: 20,
+ height: 20,
+ borderRadius: '50%',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontSize: 9,
+ fontWeight: 700,
+ color: 'var(--text-primary)',
+ background: 'var(--bg-tertiary)',
+ flexShrink: 0,
+ lineHeight: 1,
+ }}>
+ {(msg.username || '?')[0].toUpperCase()}
+ </span>
+ )}
+ <span style={{
+ fontSize: 10,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ lineHeight: 1,
+ }}>
+ {msg.username}
+ </span>
+ </div>
+ )}
+
+ {/* reply quote */}
+ {repliedMsg && (
+ <div style={{
+ padding: '6px 10px',
+ borderLeft: '2px solid var(--accent)',
+ background: 'var(--bg-secondary)',
+ borderRadius: 6,
+ fontSize: 11,
+ lineHeight: 1.35,
+ marginBottom: 4,
+ maxWidth: '75%',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ color: 'var(--text-muted)',
+ alignSelf: own ? 'flex-end' : 'flex-start',
+ }}>
+ <strong style={{ fontWeight: 600 }}>{repliedMsg.username}: </strong>
+ {(repliedMsg.text || '').slice(0, 80)}
+ {(repliedMsg.text || '').length > 80 ? '...' : ''}
+ </div>
+ )}
+
+ {/* bubble with hover actions */}
+ <div
+ style={{ position: 'relative', maxWidth: '75%' }}
+ onMouseEnter={() => setHoveredId(msg.id)}
+ onMouseLeave={() => setHoveredId(null)}
+ >
+ <div style={{
+ background: own ? 'var(--accent)' : 'var(--bg-secondary)',
+ color: own ? 'var(--accent-text)' : 'var(--text-primary)',
+ borderRadius: own ? '14px 14px 4px 14px' : '14px 14px 14px 4px',
+ padding: '8px 12px',
+ fontSize: 13,
+ lineHeight: 1.45,
+ wordBreak: 'break-word',
+ whiteSpace: 'pre-wrap',
+ }}>
+ {msg.text}
+ </div>
+
+ {/* action buttons */}
+ <div style={{
+ position: 'absolute',
+ top: -10,
+ display: 'flex',
+ gap: 2,
+ opacity: hoveredId === msg.id ? 1 : 0,
+ pointerEvents: hoveredId === msg.id ? 'auto' : 'none',
+ transition: 'opacity .12s ease',
+ ...(own ? { right: 4 } : { left: 4 }),
+ }}>
+ <button
+ style={{
+ width: 22,
+ height: 22,
+ borderRadius: '50%',
+ border: '1px solid var(--border-faint)',
+ background: 'var(--bg-card)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ cursor: 'pointer',
+ color: 'var(--text-muted)',
+ padding: 0,
+ flexShrink: 0,
+ }}
+ title="Reply"
+ onClick={() => setReplyTo(msg)}
+ >
+ <Reply size={11} />
+ </button>
+ {own && (
+ <button
+ style={{
+ width: 22,
+ height: 22,
+ borderRadius: '50%',
+ border: '1px solid var(--border-faint)',
+ background: 'var(--bg-card)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ cursor: 'pointer',
+ color: 'var(--text-muted)',
+ padding: 0,
+ flexShrink: 0,
+ }}
+ title="Delete"
+ onClick={() => handleDelete(msg.id)}
+ >
+ <Trash2 size={11} />
+ </button>
+ )}
+ </div>
+ </div>
+
+ {/* timestamp */}
+ <span style={{
+ fontSize: 9,
+ color: 'var(--text-faint)',
+ marginTop: 2,
+ paddingLeft: 2,
+ paddingRight: 2,
+ lineHeight: 1,
+ }}>
+ {formatRelativeTime(msg.created_at, t)}
+ </span>
+ </div>
+ )
+ })}
+ </div>
+ )}
+
+ {/* ── composer ── */}
+ <div style={{
+ flexShrink: 0,
+ padding: 12,
+ borderTop: '1px solid var(--border-faint)',
+ background: 'var(--bg-card)',
+ }}>
+ {/* reply preview */}
+ {replyTo && (
+ <div style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 8,
+ marginBottom: 8,
+ padding: '6px 10px',
+ borderRadius: 6,
+ background: 'var(--bg-secondary)',
+ borderLeft: '2px solid var(--accent)',
+ fontSize: 12,
+ color: 'var(--text-muted)',
+ lineHeight: 1.3,
+ }}>
+ <Reply size={13} style={{ flexShrink: 0, opacity: 0.6 }} />
+ <span style={{
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ }}>
+ <strong>{replyTo.username}</strong>: {(replyTo.text || '').slice(0, 60)}
+ {(replyTo.text || '').length > 60 ? '...' : ''}
+ </span>
+ <span
+ style={{
+ marginLeft: 'auto',
+ cursor: 'pointer',
+ color: 'var(--text-faint)',
+ fontSize: 16,
+ fontWeight: 400,
+ lineHeight: 1,
+ padding: '0 2px',
+ flexShrink: 0,
+ }}
+ onClick={() => setReplyTo(null)}
+ >
+ &times;
+ </span>
+ </div>
+ )}
+
+ <div style={{
+ display: 'flex',
+ alignItems: 'flex-end',
+ gap: 8,
+ }}>
+ <textarea
+ ref={textareaRef}
+ rows={1}
+ style={{
+ flex: 1,
+ resize: 'none',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ lineHeight: 1.4,
+ fontFamily: font,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ outline: 'none',
+ maxHeight: 3 * 20 + 18,
+ overflow: 'auto',
+ transition: 'border-color .15s ease',
+ }}
+ placeholder={t('collab.chat.placeholder')}
+ value={text}
+ onChange={handleTextChange}
+ onKeyDown={handleKeyDown}
+ onFocus={() => {
+ if (textareaRef.current) {
+ textareaRef.current.style.borderColor = 'var(--accent)'
+ }
+ }}
+ onBlur={() => {
+ if (textareaRef.current) {
+ textareaRef.current.style.borderColor = 'var(--border-primary)'
+ }
+ }}
+ />
+ <button
+ style={{
+ width: 32,
+ height: 32,
+ borderRadius: '50%',
+ border: 'none',
+ background: 'var(--accent)',
+ color: 'var(--accent-text)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ cursor: (!text.trim() || sending) ? 'default' : 'pointer',
+ flexShrink: 0,
+ opacity: (!text.trim() || sending) ? 0.4 : 1,
+ transition: 'opacity .15s ease',
+ }}
+ onClick={handleSend}
+ disabled={!text.trim() || sending}
+ >
+ <Send size={14} style={{ marginLeft: 1 }} />
+ </button>
+ </div>
+ </div>
+ </div>
+ )
+}
diff --git a/client/src/components/Collab/CollabNotes.jsx b/client/src/components/Collab/CollabNotes.jsx
new file mode 100644
index 000000000..2169aa2f1
--- /dev/null
+++ b/client/src/components/Collab/CollabNotes.jsx
@@ -0,0 +1,1024 @@
+import React, { useState, useEffect, useCallback } from 'react'
+import ReactDOM from 'react-dom'
+import { Plus, Trash2, Pin, PinOff, Pencil, X, Check } from 'lucide-react'
+import { collabApi } from '../../api/client'
+import { addListener, removeListener } from '../../api/websocket'
+import { useTranslation } from '../../i18n'
+
+const FONT = "-apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif"
+
+const NOTE_COLORS = [
+ { value: '#6366f1', label: 'Indigo' },
+ { value: '#ef4444', label: 'Red' },
+ { value: '#f59e0b', label: 'Amber' },
+ { value: '#10b981', label: 'Emerald' },
+ { value: '#3b82f6', label: 'Blue' },
+ { value: '#8b5cf6', label: 'Violet' },
+]
+
+const formatTimestamp = (ts) => {
+ if (!ts) return ''
+ const d = new Date(ts)
+ const now = new Date()
+ const diffMs = now - d
+ const diffMins = Math.floor(diffMs / 60000)
+ if (diffMins < 1) return 'just now'
+ if (diffMins < 60) return `${diffMins}m ago`
+ const diffHrs = Math.floor(diffMins / 60)
+ if (diffHrs < 24) return `${diffHrs}h ago`
+ const diffDays = Math.floor(diffHrs / 24)
+ if (diffDays < 7) return `${diffDays}d ago`
+ return d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' })
+}
+
+// ── Avatar ──────────────────────────────────────────────────────────────────
+function UserAvatar({ user, size = 14 }) {
+ if (!user) return null
+ if (user.avatar) {
+ return (
+ <img
+ src={user.avatar}
+ alt={user.username}
+ style={{
+ width: size,
+ height: size,
+ borderRadius: '50%',
+ objectFit: 'cover',
+ flexShrink: 0,
+ background: 'var(--bg-tertiary)',
+ }}
+ />
+ )
+ }
+ const initials = (user.username || '?').slice(0, 1)
+ return (
+ <div style={{
+ width: size,
+ height: size,
+ borderRadius: '50%',
+ background: 'var(--bg-tertiary)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontSize: size * 0.45,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ flexShrink: 0,
+ textTransform: 'uppercase',
+ fontFamily: FONT,
+ }}>
+ {initials}
+ </div>
+ )
+}
+
+// ── New Note Modal (portal to body) ─────────────────────────────────────────
+function NewNoteModal({ onClose, onSubmit, existingCategories, t }) {
+ const [title, setTitle] = useState('')
+ const [content, setContent] = useState('')
+ const [category, setCategory] = useState('')
+ const [customCategory, setCustomCategory] = useState('')
+ const [color, setColor] = useState(NOTE_COLORS[0].value)
+ const [submitting, setSubmitting] = useState(false)
+
+ const isCustom = category === '__custom__'
+ const finalCategory = isCustom ? customCategory.trim() : category
+
+ const handleSubmit = async (e) => {
+ e.preventDefault()
+ if (!title.trim()) return
+ setSubmitting(true)
+ try {
+ await onSubmit({
+ title: title.trim(),
+ content: content.trim(),
+ category: finalCategory || null,
+ color,
+ })
+ onClose()
+ } catch {
+ // error handled upstream
+ } finally {
+ setSubmitting(false)
+ }
+ }
+
+ const canSubmit = title.trim() && !submitting
+
+ return ReactDOM.createPortal(
+ <div
+ style={{
+ position: 'fixed',
+ inset: 0,
+ background: 'var(--overlay-bg, rgba(0,0,0,0.35))',
+ backdropFilter: 'blur(6px)',
+ WebkitBackdropFilter: 'blur(6px)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ zIndex: 9999,
+ padding: 16,
+ fontFamily: FONT,
+ }}
+ onClick={onClose}
+ >
+ <form
+ style={{
+ background: 'var(--bg-card)',
+ borderRadius: 16,
+ width: '100%',
+ maxWidth: 400,
+ maxHeight: '90vh',
+ overflow: 'auto',
+ border: '1px solid var(--border-faint)',
+ }}
+ onClick={e => e.stopPropagation()}
+ onSubmit={handleSubmit}
+ >
+ {/* Modal header */}
+ <div style={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ padding: '14px 16px 12px',
+ borderBottom: '1px solid var(--border-faint)',
+ }}>
+ <h3 style={{
+ fontSize: 14,
+ fontWeight: 700,
+ color: 'var(--text-primary)',
+ margin: 0,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.new')}
+ </h3>
+ <button
+ type="button"
+ onClick={onClose}
+ style={{
+ background: 'none',
+ border: 'none',
+ cursor: 'pointer',
+ color: 'var(--text-faint)',
+ padding: 2,
+ borderRadius: 6,
+ display: 'flex',
+ }}
+ >
+ <X size={16} />
+ </button>
+ </div>
+
+ {/* Modal body */}
+ <div style={{
+ padding: '14px 16px 16px',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 12,
+ }}>
+ {/* Title */}
+ <div>
+ <div style={{
+ fontSize: 9,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ textTransform: 'uppercase',
+ letterSpacing: '0.05em',
+ marginBottom: 4,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.title')}
+ </div>
+ <input
+ autoFocus
+ value={title}
+ onChange={e => setTitle(e.target.value)}
+ placeholder={t('collab.notes.titlePlaceholder')}
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ }}
+ />
+ </div>
+
+ {/* Content */}
+ <div>
+ <div style={{
+ fontSize: 9,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ textTransform: 'uppercase',
+ letterSpacing: '0.05em',
+ marginBottom: 4,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.contentPlaceholder')}
+ </div>
+ <textarea
+ value={content}
+ onChange={e => setContent(e.target.value)}
+ placeholder={t('collab.notes.contentPlaceholder')}
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ resize: 'vertical',
+ minHeight: 90,
+ lineHeight: 1.5,
+ }}
+ />
+ </div>
+
+ {/* Category */}
+ <div>
+ <div style={{
+ fontSize: 9,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ textTransform: 'uppercase',
+ letterSpacing: '0.05em',
+ marginBottom: 4,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.category')}
+ </div>
+ <select
+ value={category}
+ onChange={e => setCategory(e.target.value)}
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ cursor: 'pointer',
+ appearance: 'none',
+ }}
+ >
+ <option value="">{t('collab.notes.noCategory')}</option>
+ {existingCategories.map(cat => (
+ <option key={cat} value={cat}>{cat}</option>
+ ))}
+ <option value="__custom__">{t('collab.notes.newCategory')}</option>
+ </select>
+ {isCustom && (
+ <input
+ value={customCategory}
+ onChange={e => setCustomCategory(e.target.value)}
+ placeholder={t('collab.notes.categoryPlaceholder')}
+ autoFocus
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ marginTop: 8,
+ }}
+ />
+ )}
+ </div>
+
+ {/* Color picker */}
+ <div>
+ <div style={{
+ fontSize: 9,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ textTransform: 'uppercase',
+ letterSpacing: '0.05em',
+ marginBottom: 4,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.color')}
+ </div>
+ <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
+ {NOTE_COLORS.map(c => (
+ <button
+ key={c.value}
+ type="button"
+ onClick={() => setColor(c.value)}
+ title={c.label}
+ aria-label={c.label}
+ style={{
+ width: 26,
+ height: 26,
+ borderRadius: 8,
+ background: c.value,
+ border: color === c.value
+ ? '2px solid var(--text-primary)'
+ : '2px solid transparent',
+ cursor: 'pointer',
+ transition: 'transform 0.15s',
+ transform: color === c.value ? 'scale(1.15)' : 'scale(1)',
+ padding: 0,
+ }}
+ />
+ ))}
+ </div>
+ </div>
+
+ {/* Submit */}
+ <button
+ type="submit"
+ disabled={!canSubmit}
+ style={{
+ width: '100%',
+ borderRadius: 99,
+ padding: '7px 14px',
+ background: canSubmit ? 'var(--accent)' : 'var(--border-primary)',
+ color: canSubmit ? 'var(--accent-text)' : 'var(--text-faint)',
+ fontSize: 12,
+ fontWeight: 600,
+ fontFamily: FONT,
+ border: 'none',
+ cursor: canSubmit ? 'pointer' : 'default',
+ marginTop: 4,
+ }}
+ >
+ {submitting ? '...' : t('collab.notes.create')}
+ </button>
+ </div>
+ </form>
+ </div>,
+ document.body
+ )
+}
+
+// ── Note Card ───────────────────────────────────────────────────────────────
+function NoteCard({ note, currentUser, onUpdate, onDelete, t }) {
+ const [hovered, setHovered] = useState(false)
+ const [editing, setEditing] = useState(false)
+ const [editTitle, setEditTitle] = useState(note.title)
+ const [editContent, setEditContent] = useState(note.content || '')
+ const [saving, setSaving] = useState(false)
+
+ const author = note.author || note.user || {}
+ const color = note.color || '#6366f1'
+
+ const handleStartEdit = useCallback(() => {
+ setEditTitle(note.title)
+ setEditContent(note.content || '')
+ setEditing(true)
+ }, [note.title, note.content])
+
+ const handleCancelEdit = useCallback(() => {
+ setEditing(false)
+ setEditTitle(note.title)
+ setEditContent(note.content || '')
+ }, [note.title, note.content])
+
+ const handleSaveEdit = useCallback(async () => {
+ if (!editTitle.trim()) return
+ setSaving(true)
+ try {
+ await onUpdate(note.id, {
+ title: editTitle.trim(),
+ content: editContent.trim(),
+ })
+ setEditing(false)
+ } catch {
+ // error handled upstream
+ } finally {
+ setSaving(false)
+ }
+ }, [note.id, editTitle, editContent, onUpdate])
+
+ const handleTogglePin = useCallback(() => {
+ onUpdate(note.id, { pinned: !note.pinned })
+ }, [note.id, note.pinned, onUpdate])
+
+ const handleDelete = useCallback(() => {
+ onDelete(note.id)
+ }, [note.id, onDelete])
+
+ useEffect(() => {
+ if (!editing) {
+ setEditTitle(note.title)
+ setEditContent(note.content || '')
+ }
+ }, [note.title, note.content, editing])
+
+ return (
+ <div
+ onMouseEnter={() => setHovered(true)}
+ onMouseLeave={() => setHovered(false)}
+ style={{
+ position: 'relative',
+ borderRadius: 10,
+ border: '1px solid var(--border-faint)',
+ overflow: 'hidden',
+ background: 'var(--bg-card)',
+ display: 'flex',
+ flexDirection: 'column',
+ fontFamily: FONT,
+ }}
+ >
+ {/* Color stripe */}
+ <div style={{ height: 3, background: color, flexShrink: 0 }} />
+
+ {/* Pin icon — top right */}
+ {!editing && (
+ <button
+ onClick={handleTogglePin}
+ title={note.pinned ? t('collab.notes.unpin') : t('collab.notes.pin')}
+ style={{
+ position: 'absolute',
+ top: 10,
+ right: 8,
+ background: 'none',
+ border: 'none',
+ cursor: 'pointer',
+ padding: 2,
+ borderRadius: 4,
+ display: 'flex',
+ color: 'var(--text-faint)',
+ opacity: note.pinned ? 1 : 0.5,
+ zIndex: 2,
+ }}
+ >
+ {note.pinned ? <Pin size={12} /> : <PinOff size={12} />}
+ </button>
+ )}
+
+ {/* Hover actions — edit + delete */}
+ <div style={{
+ position: 'absolute',
+ top: 10,
+ right: note.pinned ? 28 : 8,
+ display: 'flex',
+ gap: 2,
+ opacity: hovered && !editing ? 1 : 0,
+ pointerEvents: hovered && !editing ? 'auto' : 'none',
+ transition: 'opacity 0.15s',
+ zIndex: 3,
+ }}>
+ <button
+ onClick={handleStartEdit}
+ title={t('collab.notes.edit')}
+ style={{
+ width: 22,
+ height: 22,
+ borderRadius: 6,
+ border: 'none',
+ background: 'var(--bg-card)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ cursor: 'pointer',
+ color: 'var(--text-faint)',
+ }}
+ >
+ <Pencil size={11} />
+ </button>
+ <button
+ onClick={handleDelete}
+ title={t('collab.notes.delete')}
+ style={{
+ width: 22,
+ height: 22,
+ borderRadius: 6,
+ border: 'none',
+ background: 'var(--bg-card)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ cursor: 'pointer',
+ color: '#ef4444',
+ }}
+ >
+ <Trash2 size={11} />
+ </button>
+ </div>
+
+ {/* Card body */}
+ <div style={{
+ padding: '10px 12px',
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 4,
+ flex: 1,
+ }}>
+ {editing ? (
+ <>
+ <input
+ autoFocus
+ value={editTitle}
+ onChange={e => setEditTitle(e.target.value)}
+ placeholder={t('collab.notes.titlePlaceholder')}
+ onKeyDown={e => {
+ if (e.key === 'Escape') handleCancelEdit()
+ if (e.key === 'Enter' && e.metaKey) handleSaveEdit()
+ }}
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ }}
+ />
+ <textarea
+ value={editContent}
+ onChange={e => setEditContent(e.target.value)}
+ placeholder={t('collab.notes.contentPlaceholder')}
+ onKeyDown={e => {
+ if (e.key === 'Escape') handleCancelEdit()
+ if (e.key === 'Enter' && e.metaKey) handleSaveEdit()
+ }}
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ resize: 'vertical',
+ minHeight: 64,
+ lineHeight: 1.5,
+ }}
+ />
+ <div style={{
+ display: 'flex',
+ gap: 6,
+ justifyContent: 'flex-end',
+ marginTop: 4,
+ }}>
+ <button
+ type="button"
+ onClick={handleCancelEdit}
+ style={{
+ display: 'inline-flex',
+ alignItems: 'center',
+ gap: 3,
+ borderRadius: 99,
+ padding: '4px 10px',
+ border: '1px solid var(--border-primary)',
+ background: 'transparent',
+ color: 'var(--text-secondary)',
+ fontSize: 11,
+ fontWeight: 500,
+ fontFamily: FONT,
+ cursor: 'pointer',
+ }}
+ >
+ <X size={10} />
+ {t('collab.notes.cancel')}
+ </button>
+ <button
+ type="button"
+ onClick={handleSaveEdit}
+ disabled={!editTitle.trim() || saving}
+ style={{
+ display: 'inline-flex',
+ alignItems: 'center',
+ gap: 3,
+ borderRadius: 99,
+ padding: '4px 10px',
+ border: 'none',
+ background: 'var(--accent)',
+ color: 'var(--accent-text)',
+ fontSize: 11,
+ fontWeight: 600,
+ fontFamily: FONT,
+ cursor: 'pointer',
+ }}
+ >
+ <Check size={10} />
+ {saving ? '...' : t('collab.notes.save')}
+ </button>
+ </div>
+ </>
+ ) : (
+ <>
+ {/* Title */}
+ <div style={{
+ fontSize: 13,
+ fontWeight: 600,
+ color: 'var(--text-primary)',
+ lineHeight: 1.35,
+ paddingRight: 24,
+ wordBreak: 'break-word',
+ fontFamily: FONT,
+ }}>
+ {note.title}
+ </div>
+
+ {/* Content — 3 line clamp */}
+ {note.content && (
+ <p style={{
+ fontSize: 11,
+ color: 'var(--text-muted)',
+ lineHeight: 1.5,
+ margin: 0,
+ display: '-webkit-box',
+ WebkitLineClamp: 3,
+ WebkitBoxOrient: 'vertical',
+ overflow: 'hidden',
+ wordBreak: 'break-word',
+ fontFamily: FONT,
+ }}>
+ {note.content}
+ </p>
+ )}
+
+ {/* Category badge */}
+ {note.category && (
+ <div style={{ marginTop: 2 }}>
+ <span style={{
+ display: 'inline-block',
+ fontSize: 9,
+ padding: '1px 6px',
+ borderRadius: 4,
+ background: 'var(--bg-tertiary)',
+ color: 'var(--text-faint)',
+ fontWeight: 600,
+ fontFamily: FONT,
+ textTransform: 'uppercase',
+ letterSpacing: '0.03em',
+ }}>
+ {note.category}
+ </span>
+ </div>
+ )}
+
+ {/* Author row */}
+ <div style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 4,
+ marginTop: 6,
+ }}>
+ <UserAvatar user={author} size={14} />
+ <span style={{
+ fontSize: 9,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ }}>
+ {author.username || '?'}
+ </span>
+ <span style={{
+ fontSize: 9,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ marginLeft: 'auto',
+ flexShrink: 0,
+ }}>
+ {formatTimestamp(note.updated_at || note.created_at)}
+ </span>
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+ )
+}
+
+// ── Main Component ──────────────────────────────────────────────────────────
+export default function CollabNotes({ tripId, currentUser }) {
+ const { t } = useTranslation()
+ const [notes, setNotes] = useState([])
+ const [loading, setLoading] = useState(true)
+ const [showNewModal, setShowNewModal] = useState(false)
+ const [activeCategory, setActiveCategory] = useState(null)
+
+ // ── Load notes on mount ──
+ useEffect(() => {
+ if (!tripId) return
+ let cancelled = false
+ setLoading(true)
+ collabApi.getNotes(tripId)
+ .then(data => { if (!cancelled) setNotes(data?.notes || data || []) })
+ .catch(() => { if (!cancelled) setNotes([]) })
+ .finally(() => { if (!cancelled) setLoading(false) })
+ return () => { cancelled = true }
+ }, [tripId])
+
+ // ── WebSocket real-time sync ──
+ useEffect(() => {
+ if (!tripId) return
+
+ const handler = (msg) => {
+ if (msg.type === 'collab:note:created' && msg.note) {
+ setNotes(prev => {
+ if (prev.some(n => n.id === msg.note.id)) return prev
+ return [msg.note, ...prev]
+ })
+ }
+ if (msg.type === 'collab:note:updated' && msg.note) {
+ setNotes(prev =>
+ prev.map(n => (n.id === msg.note.id ? { ...n, ...msg.note } : n))
+ )
+ }
+ if (msg.type === 'collab:note:deleted') {
+ const deletedId = msg.noteId || msg.id
+ if (deletedId) {
+ setNotes(prev => prev.filter(n => n.id !== deletedId))
+ }
+ }
+ }
+
+ addListener(handler)
+ return () => removeListener(handler)
+ }, [tripId])
+
+ // ── Actions ──
+ const handleCreateNote = useCallback(async (data) => {
+ const created = await collabApi.createNote(tripId, data)
+ if (created) {
+ setNotes(prev => {
+ if (prev.some(n => n.id === created.id)) return prev
+ return [created, ...prev]
+ })
+ }
+ }, [tripId])
+
+ const handleUpdateNote = useCallback(async (noteId, data) => {
+ const updated = await collabApi.updateNote(tripId, noteId, data)
+ if (updated) {
+ setNotes(prev =>
+ prev.map(n => (n.id === noteId ? { ...n, ...updated } : n))
+ )
+ }
+ }, [tripId])
+
+ const handleDeleteNote = useCallback(async (noteId) => {
+ await collabApi.deleteNote(tripId, noteId)
+ setNotes(prev => prev.filter(n => n.id !== noteId))
+ }, [tripId])
+
+ // ── Derived data ──
+ const categories = [...new Set(notes.map(n => n.category).filter(Boolean))]
+
+ const sortedNotes = [...notes]
+ .filter(n => activeCategory === null || n.category === activeCategory)
+ .sort((a, b) => {
+ if (a.pinned && !b.pinned) return -1
+ if (!a.pinned && b.pinned) return 1
+ const tA = new Date(a.updated_at || a.created_at || 0).getTime()
+ const tB = new Date(b.updated_at || b.created_at || 0).getTime()
+ return tB - tA
+ })
+
+ // ── Loading state ──
+ if (loading) {
+ return (
+ <div style={{
+ height: '100%',
+ display: 'flex',
+ flexDirection: 'column',
+ fontFamily: FONT,
+ }}>
+ <div style={{
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--border-faint)',
+ }}>
+ <h3 style={{
+ fontSize: 14,
+ fontWeight: 700,
+ color: 'var(--text-primary)',
+ margin: 0,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.title')}
+ </h3>
+ </div>
+ <div style={{
+ flex: 1,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ }}>
+ <div style={{
+ width: 20,
+ height: 20,
+ border: '2px solid var(--border-primary)',
+ borderTopColor: 'var(--text-primary)',
+ borderRadius: '50%',
+ animation: 'collab-notes-spin 0.7s linear infinite',
+ }} />
+ <style>{`@keyframes collab-notes-spin { to { transform: rotate(360deg) } }`}</style>
+ </div>
+ </div>
+ )
+ }
+
+ return (
+ <div style={{
+ height: '100%',
+ display: 'flex',
+ flexDirection: 'column',
+ fontFamily: FONT,
+ }}>
+ {/* ── Header ── */}
+ <div style={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--border-faint)',
+ flexShrink: 0,
+ }}>
+ <h3 style={{
+ fontSize: 14,
+ fontWeight: 700,
+ color: 'var(--text-primary)',
+ margin: 0,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.title')}
+ </h3>
+ <button
+ onClick={() => setShowNewModal(true)}
+ style={{
+ display: 'inline-flex',
+ alignItems: 'center',
+ gap: 4,
+ borderRadius: 99,
+ padding: '7px 14px',
+ background: 'var(--accent)',
+ color: 'var(--accent-text)',
+ fontSize: 12,
+ fontWeight: 600,
+ fontFamily: FONT,
+ border: 'none',
+ cursor: 'pointer',
+ whiteSpace: 'nowrap',
+ }}
+ >
+ <Plus size={13} />
+ {t('collab.notes.new')}
+ </button>
+ </div>
+
+ {/* ── Category filter pills ── */}
+ {categories.length > 0 && (
+ <div style={{
+ display: 'flex',
+ gap: 4,
+ padding: '8px 12px 0',
+ overflowX: 'auto',
+ flexShrink: 0,
+ }}>
+ <button
+ onClick={() => setActiveCategory(null)}
+ style={{
+ flexShrink: 0,
+ borderRadius: 99,
+ padding: '3px 10px',
+ fontSize: 10,
+ fontWeight: 600,
+ fontFamily: FONT,
+ border: activeCategory === null
+ ? '1px solid var(--accent)'
+ : '1px solid var(--border-faint)',
+ background: activeCategory === null
+ ? 'var(--accent)'
+ : 'transparent',
+ color: activeCategory === null
+ ? 'var(--accent-text)'
+ : 'var(--text-secondary)',
+ cursor: 'pointer',
+ whiteSpace: 'nowrap',
+ textTransform: 'uppercase',
+ letterSpacing: '0.03em',
+ }}
+ >
+ {t('collab.notes.all')}
+ </button>
+ {categories.map(cat => (
+ <button
+ key={cat}
+ onClick={() => setActiveCategory(prev => prev === cat ? null : cat)}
+ style={{
+ flexShrink: 0,
+ borderRadius: 99,
+ padding: '3px 10px',
+ fontSize: 10,
+ fontWeight: 600,
+ fontFamily: FONT,
+ border: activeCategory === cat
+ ? '1px solid var(--accent)'
+ : '1px solid var(--border-faint)',
+ background: activeCategory === cat
+ ? 'var(--accent)'
+ : 'transparent',
+ color: activeCategory === cat
+ ? 'var(--accent-text)'
+ : 'var(--text-secondary)',
+ cursor: 'pointer',
+ whiteSpace: 'nowrap',
+ textTransform: 'uppercase',
+ letterSpacing: '0.03em',
+ }}
+ >
+ {cat}
+ </button>
+ ))}
+ </div>
+ )}
+
+ {/* ── Scrollable content ── */}
+ <div style={{
+ flex: 1,
+ overflowY: 'auto',
+ padding: 12,
+ }}>
+ {sortedNotes.length === 0 ? (
+ /* ── Empty state ── */
+ <div style={{
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ justifyContent: 'center',
+ padding: '48px 20px',
+ textAlign: 'center',
+ }}>
+ <Pencil size={36} color="var(--text-faint)" style={{ marginBottom: 12 }} />
+ <div style={{
+ fontSize: 14,
+ fontWeight: 600,
+ color: 'var(--text-secondary)',
+ marginBottom: 4,
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.empty')}
+ </div>
+ <div style={{
+ fontSize: 12,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ }}>
+ {t('collab.notes.emptyDesc') || 'Create a note to get started'}
+ </div>
+ </div>
+ ) : (
+ /* ── Notes list — single column ── */
+ <div style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 8,
+ }}>
+ {sortedNotes.map(note => (
+ <NoteCard
+ key={note.id}
+ note={note}
+ currentUser={currentUser}
+ onUpdate={handleUpdateNote}
+ onDelete={handleDeleteNote}
+ t={t}
+ />
+ ))}
+ </div>
+ )}
+ </div>
+
+ {/* ── New Note Modal ── */}
+ {showNewModal && (
+ <NewNoteModal
+ onClose={() => setShowNewModal(false)}
+ onSubmit={handleCreateNote}
+ existingCategories={categories}
+ t={t}
+ />
+ )}
+ </div>
+ )
+}
diff --git a/client/src/components/Collab/CollabPanel.jsx b/client/src/components/Collab/CollabPanel.jsx
new file mode 100644
index 000000000..42b67ff32
--- /dev/null
+++ b/client/src/components/Collab/CollabPanel.jsx
@@ -0,0 +1,34 @@
+import React from 'react'
+import { useAuthStore } from '../../store/authStore'
+import CollabChat from './CollabChat'
+import CollabNotes from './CollabNotes'
+import CollabPolls from './CollabPolls'
+
+export default function CollabPanel({ tripId }) {
+ const { user } = useAuthStore()
+
+ return (
+ <div style={{ height: '100%', overflowY: 'auto', overscrollBehavior: 'contain', fontFamily: "-apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif" }}>
+ <div style={{ maxWidth: 1400, margin: '0 auto', padding: '16px' }}>
+ <div className="grid grid-cols-1 lg:grid-cols-3 gap-4" style={{ alignItems: 'start' }}>
+
+ {/* Chat — takes 1 column, full height */}
+ <div style={{ background: 'var(--bg-card)', borderRadius: 16, border: '1px solid var(--border-faint)', overflow: 'hidden', height: 500 }}>
+ <CollabChat tripId={tripId} currentUser={user} />
+ </div>
+
+ {/* Notes — takes 1 column */}
+ <div style={{ background: 'var(--bg-card)', borderRadius: 16, border: '1px solid var(--border-faint)', overflow: 'hidden', maxHeight: 500, display: 'flex', flexDirection: 'column' }}>
+ <CollabNotes tripId={tripId} currentUser={user} />
+ </div>
+
+ {/* Polls — takes 1 column */}
+ <div style={{ background: 'var(--bg-card)', borderRadius: 16, border: '1px solid var(--border-faint)', overflow: 'hidden', maxHeight: 500, display: 'flex', flexDirection: 'column' }}>
+ <CollabPolls tripId={tripId} currentUser={user} />
+ </div>
+
+ </div>
+ </div>
+ </div>
+ )
+}
diff --git a/client/src/components/Collab/CollabPolls.jsx b/client/src/components/Collab/CollabPolls.jsx
new file mode 100644
index 000000000..d2ece2eea
--- /dev/null
+++ b/client/src/components/Collab/CollabPolls.jsx
@@ -0,0 +1,1046 @@
+import React, { useState, useEffect, useCallback } from 'react'
+import { Plus, Trash2, X, Check, BarChart3, Lock, Clock } from 'lucide-react'
+import { collabApi } from '../../api/client'
+import { addListener, removeListener } from '../../api/websocket'
+import { useTranslation } from '../../i18n'
+
+// ── Constants ────────────────────────────────────────────────────────────────
+
+const FONT = "-apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif"
+
+// ── Helpers ──────────────────────────────────────────────────────────────────
+
+function timeRemaining(deadline) {
+ if (!deadline) return null
+ const diff = new Date(deadline).getTime() - Date.now()
+ if (diff <= 0) return null
+ const mins = Math.floor(diff / 60000)
+ const hrs = Math.floor(mins / 60)
+ const days = Math.floor(hrs / 24)
+ if (days > 0) return `${days}d ${hrs % 24}h`
+ if (hrs > 0) return `${hrs}h ${mins % 60}m`
+ return `${mins}m`
+}
+
+function isExpired(deadline) {
+ if (!deadline) return false
+ return new Date(deadline).getTime() <= Date.now()
+}
+
+function totalVotes(poll) {
+ if (!poll.options) return 0
+ return poll.options.reduce((s, o) => s + (o.voters?.length || 0), 0)
+}
+
+// ── Voter Avatars ────────────────────────────────────────────────────────────
+
+function VoterAvatars({ voters = [] }) {
+ const MAX = 4
+ const shown = voters.slice(0, MAX)
+ const extra = voters.length - MAX
+
+ if (!voters.length) return null
+
+ return (
+ <div style={{ display: 'flex', alignItems: 'center', marginTop: 3, minHeight: 14 }}>
+ {shown.map((v, i) => (
+ <div
+ key={v.id || i}
+ title={v.username}
+ style={{
+ width: 14,
+ height: 14,
+ borderRadius: '50%',
+ border: '1.5px solid var(--bg-primary)',
+ marginLeft: i === 0 ? 0 : -4,
+ overflow: 'hidden',
+ background: 'var(--bg-tertiary)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontSize: 7,
+ fontWeight: 700,
+ fontFamily: FONT,
+ color: 'var(--text-secondary)',
+ flexShrink: 0,
+ zIndex: MAX - i,
+ position: 'relative',
+ }}
+ >
+ {v.avatar ? (
+ <img
+ src={v.avatar}
+ alt=""
+ style={{ width: '100%', height: '100%', objectFit: 'cover' }}
+ />
+ ) : (
+ (v.username || '?')[0].toUpperCase()
+ )}
+ </div>
+ ))}
+ {extra > 0 && (
+ <span
+ style={{
+ fontSize: 9,
+ fontFamily: FONT,
+ color: 'var(--text-faint)',
+ marginLeft: 3,
+ fontWeight: 600,
+ }}
+ >
+ +{extra}
+ </span>
+ )}
+ </div>
+ )
+}
+
+// ── Option Bar ───────────────────────────────────────────────────────────────
+
+function OptionBar({ option, index, poll, currentUser, onVote, isClosed }) {
+ const total = totalVotes(poll)
+ const count = option.voters?.length || 0
+ const pct = total > 0 ? Math.round((count / total) * 100) : 0
+ const voted = option.voters?.some((v) => v.id === currentUser.id)
+ const canVote = !isClosed && !poll.is_closed
+
+ return (
+ <div
+ onClick={() => canVote && onVote(poll.id, index)}
+ style={{
+ position: 'relative',
+ width: '100%',
+ padding: '8px 12px',
+ borderRadius: 8,
+ border: voted
+ ? '1px solid var(--accent)'
+ : '1px solid var(--border-faint)',
+ overflow: 'hidden',
+ cursor: canVote ? 'pointer' : 'default',
+ marginTop: 4,
+ boxSizing: 'border-box',
+ fontFamily: FONT,
+ }}
+ onMouseEnter={(e) => {
+ if (canVote) e.currentTarget.style.borderColor = 'var(--accent)'
+ }}
+ onMouseLeave={(e) => {
+ if (canVote && !voted)
+ e.currentTarget.style.borderColor = 'var(--border-faint)'
+ }}
+ >
+ {/* Vote fill bar */}
+ <div
+ style={{
+ position: 'absolute',
+ left: 0,
+ top: 0,
+ bottom: 0,
+ width: `${pct}%`,
+ background: 'var(--accent)',
+ opacity: voted ? 0.15 : 0.1,
+ transition: 'width 0.3s',
+ pointerEvents: 'none',
+ }}
+ />
+
+ {/* Content row */}
+ <div
+ style={{
+ position: 'relative',
+ zIndex: 1,
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ gap: 8,
+ }}
+ >
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6, flex: 1, minWidth: 0 }}>
+ {voted && (
+ <Check
+ size={12}
+ style={{ color: 'var(--accent)', flexShrink: 0 }}
+ strokeWidth={2.5}
+ />
+ )}
+ <span
+ style={{
+ fontSize: 12,
+ fontWeight: voted ? 600 : 400,
+ color: 'var(--text-primary)',
+ fontFamily: FONT,
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ }}
+ >
+ {option.text}
+ </span>
+ </div>
+
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0 }}>
+ <span
+ style={{
+ fontSize: 11,
+ color: 'var(--text-muted)',
+ fontFamily: FONT,
+ fontVariantNumeric: 'tabular-nums',
+ }}
+ >
+ {count}
+ </span>
+ <span
+ style={{
+ fontSize: 11,
+ fontWeight: 600,
+ color: 'var(--text-primary)',
+ fontFamily: FONT,
+ fontVariantNumeric: 'tabular-nums',
+ minWidth: 28,
+ textAlign: 'right',
+ }}
+ >
+ {pct}%
+ </span>
+ </div>
+ </div>
+
+ {/* Voter avatars */}
+ {option.voters?.length > 0 && (
+ <div style={{ position: 'relative', zIndex: 1 }}>
+ <VoterAvatars voters={option.voters} />
+ </div>
+ )}
+ </div>
+ )
+}
+
+// ── Create Poll Form ─────────────────────────────────────────────────────────
+
+function CreatePollForm({ onSubmit, onCancel, t }) {
+ const [question, setQuestion] = useState('')
+ const [options, setOptions] = useState(['', ''])
+ const [multipleChoice, setMultipleChoice] = useState(false)
+ const [deadline, setDeadline] = useState('')
+ const [submitting, setSubmitting] = useState(false)
+
+ const canSubmit =
+ question.trim().length > 0 &&
+ options.filter((o) => o.trim()).length >= 2 &&
+ !submitting
+
+ const addOption = () => setOptions((prev) => [...prev, ''])
+
+ const removeOption = (i) => {
+ if (options.length <= 2) return
+ setOptions((prev) => prev.filter((_, idx) => idx !== i))
+ }
+
+ const updateOption = (i, val) =>
+ setOptions((prev) => prev.map((o, idx) => (idx === i ? val : o)))
+
+ const handleSubmit = async (e) => {
+ e.preventDefault()
+ if (!canSubmit) return
+ setSubmitting(true)
+ try {
+ await onSubmit({
+ question: question.trim(),
+ options: options.filter((o) => o.trim()).map((o) => o.trim()),
+ multiple_choice: multipleChoice,
+ deadline: deadline || undefined,
+ })
+ setQuestion('')
+ setOptions(['', ''])
+ setMultipleChoice(false)
+ setDeadline('')
+ } finally {
+ setSubmitting(false)
+ }
+ }
+
+ return (
+ <form
+ onSubmit={handleSubmit}
+ style={{
+ background: 'var(--bg-secondary)',
+ borderRadius: 10,
+ padding: 12,
+ marginBottom: 8,
+ fontFamily: FONT,
+ }}
+ >
+ {/* Question */}
+ <input
+ type="text"
+ value={question}
+ onChange={(e) => setQuestion(e.target.value)}
+ placeholder={t('collab.polls.question')}
+ style={{
+ width: '100%',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ }}
+ onFocus={(e) => (e.target.style.borderColor = 'var(--accent)')}
+ onBlur={(e) => (e.target.style.borderColor = 'var(--border-primary)')}
+ autoFocus
+ />
+
+ {/* Options */}
+ <div style={{ marginTop: 8, display: 'flex', flexDirection: 'column', gap: 4 }}>
+ {options.map((opt, i) => (
+ <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
+ <input
+ type="text"
+ value={opt}
+ onChange={(e) => updateOption(i, e.target.value)}
+ placeholder={`${t('collab.polls.addOption').replace('+', '').trim()} ${i + 1}`}
+ style={{
+ flex: 1,
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ boxSizing: 'border-box',
+ }}
+ onFocus={(e) => (e.target.style.borderColor = 'var(--accent)')}
+ onBlur={(e) => (e.target.style.borderColor = 'var(--border-primary)')}
+ />
+ {options.length > 2 && (
+ <button
+ type="button"
+ onClick={() => removeOption(i)}
+ style={{
+ background: 'none',
+ border: 'none',
+ cursor: 'pointer',
+ padding: 4,
+ color: 'var(--text-faint)',
+ display: 'flex',
+ alignItems: 'center',
+ fontFamily: FONT,
+ }}
+ onMouseEnter={(e) => (e.currentTarget.style.color = 'var(--danger, #ef4444)')}
+ onMouseLeave={(e) => (e.currentTarget.style.color = 'var(--text-faint)')}
+ >
+ <X size={13} />
+ </button>
+ )}
+ </div>
+ ))}
+ </div>
+
+ {/* + Add option link */}
+ <div
+ onClick={addOption}
+ style={{
+ fontSize: 11,
+ color: 'var(--text-muted)',
+ cursor: 'pointer',
+ fontFamily: FONT,
+ padding: '6px 0 2px',
+ display: 'flex',
+ alignItems: 'center',
+ gap: 3,
+ }}
+ >
+ <Plus size={11} />
+ {t('collab.polls.addOption')}
+ </div>
+
+ {/* Settings row */}
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 16,
+ marginTop: 10,
+ flexWrap: 'wrap',
+ }}
+ >
+ {/* Multiple choice toggle */}
+ <label
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 6,
+ fontSize: 12,
+ color: 'var(--text-secondary)',
+ cursor: 'pointer',
+ userSelect: 'none',
+ fontFamily: FONT,
+ }}
+ >
+ <div
+ onClick={() => setMultipleChoice(!multipleChoice)}
+ style={{
+ width: 14,
+ height: 14,
+ borderRadius: 4,
+ border: multipleChoice
+ ? '1px solid var(--accent)'
+ : '1px solid var(--border-primary)',
+ background: multipleChoice ? 'var(--accent)' : 'transparent',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ cursor: 'pointer',
+ flexShrink: 0,
+ }}
+ >
+ {multipleChoice && <Check size={9} style={{ color: '#fff' }} strokeWidth={3} />}
+ </div>
+ {t('collab.polls.multipleChoice')}
+ </label>
+
+ {/* Deadline */}
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
+ <Clock size={12} style={{ color: 'var(--text-faint)' }} />
+ <input
+ type="datetime-local"
+ value={deadline}
+ onChange={(e) => setDeadline(e.target.value)}
+ style={{
+ border: '1px solid var(--border-primary)',
+ borderRadius: 10,
+ padding: '8px 12px',
+ fontSize: 13,
+ background: 'var(--bg-input)',
+ color: 'var(--text-primary)',
+ fontFamily: 'inherit',
+ outline: 'none',
+ }}
+ />
+ </div>
+ </div>
+
+ {/* Actions */}
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'flex-end',
+ gap: 8,
+ marginTop: 12,
+ }}
+ >
+ <button
+ type="button"
+ onClick={onCancel}
+ style={{
+ background: 'none',
+ border: '1px solid var(--border-primary)',
+ borderRadius: 99,
+ padding: '5px 14px',
+ fontSize: 12,
+ fontWeight: 500,
+ color: 'var(--text-secondary)',
+ cursor: 'pointer',
+ fontFamily: FONT,
+ }}
+ onMouseEnter={(e) => (e.currentTarget.style.background = 'var(--bg-tertiary)')}
+ onMouseLeave={(e) => (e.currentTarget.style.background = 'none')}
+ >
+ {t('common.cancel', 'Cancel')}
+ </button>
+ <button
+ type="submit"
+ disabled={!canSubmit}
+ style={{
+ background: canSubmit ? 'var(--accent)' : 'var(--bg-tertiary)',
+ border: 'none',
+ borderRadius: 99,
+ padding: '5px 14px',
+ fontSize: 12,
+ fontWeight: 600,
+ color: canSubmit ? '#fff' : 'var(--text-faint)',
+ cursor: canSubmit ? 'pointer' : 'not-allowed',
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 4,
+ }}
+ onMouseEnter={(e) => {
+ if (canSubmit) e.currentTarget.style.opacity = '0.85'
+ }}
+ onMouseLeave={(e) => {
+ e.currentTarget.style.opacity = '1'
+ }}
+ >
+ <BarChart3 size={12} />
+ {t('collab.polls.create')}
+ </button>
+ </div>
+ </form>
+ )
+}
+
+// ── Poll Card ────────────────────────────────────────────────────────────────
+
+function PollCard({ poll, currentUser, onVote, onClose, onDelete, t }) {
+ const isCreator = poll.created_by?.id === currentUser.id
+ const isClosed = poll.is_closed || isExpired(poll.deadline)
+ const remaining = timeRemaining(poll.deadline)
+ const total = totalVotes(poll)
+
+ return (
+ <div
+ style={{
+ borderRadius: 10,
+ border: '1px solid var(--border-faint)',
+ padding: 12,
+ background: 'var(--bg-card)',
+ opacity: isClosed ? 0.6 : 1,
+ fontFamily: FONT,
+ }}
+ >
+ {/* Header row */}
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'flex-start',
+ justifyContent: 'space-between',
+ gap: 8,
+ marginBottom: 8,
+ }}
+ >
+ <div style={{ flex: 1, minWidth: 0 }}>
+ {/* Question */}
+ <div
+ style={{
+ fontSize: 13,
+ fontWeight: 600,
+ color: 'var(--text-primary)',
+ fontFamily: FONT,
+ lineHeight: 1.35,
+ wordBreak: 'break-word',
+ margin: 0,
+ }}
+ >
+ {poll.question}
+ </div>
+
+ {/* Meta line */}
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 8,
+ marginTop: 3,
+ flexWrap: 'wrap',
+ }}
+ >
+ {/* by username */}
+ <span
+ style={{
+ fontSize: 10,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ }}
+ >
+ by {poll.created_by?.username || '?'}
+ </span>
+
+ {/* Vote count */}
+ <span
+ style={{
+ fontSize: 10,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 3,
+ }}
+ >
+ <BarChart3 size={9} />
+ {total} {t('collab.polls.votes')}
+ </span>
+
+ {/* Multiple choice badge */}
+ {poll.multiple_choice && (
+ <span
+ style={{
+ fontSize: 9,
+ fontWeight: 600,
+ color: 'var(--accent)',
+ padding: '1px 6px',
+ borderRadius: 4,
+ background: 'var(--bg-tertiary)',
+ textTransform: 'uppercase',
+ letterSpacing: 0.3,
+ fontFamily: FONT,
+ }}
+ >
+ {t('collab.polls.multipleChoice')}
+ </span>
+ )}
+
+ {/* Closed badge */}
+ {isClosed && (
+ <span
+ style={{
+ fontSize: 9,
+ padding: '1px 6px',
+ borderRadius: 4,
+ background: 'var(--bg-tertiary)',
+ color: 'var(--text-faint)',
+ fontWeight: 600,
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 3,
+ textTransform: 'uppercase',
+ letterSpacing: 0.3,
+ }}
+ >
+ <Lock size={8} />
+ {t('collab.polls.closed')}
+ </span>
+ )}
+
+ {/* Deadline countdown */}
+ {!isClosed && remaining && (
+ <span
+ style={{
+ fontSize: 10,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 3,
+ }}
+ >
+ <Clock size={9} />
+ {remaining}
+ </span>
+ )}
+ </div>
+ </div>
+
+ {/* Creator actions: close / delete */}
+ {isCreator && (
+ <div style={{ display: 'flex', alignItems: 'center', gap: 2, flexShrink: 0 }}>
+ {!isClosed && (
+ <button
+ onClick={() => onClose(poll.id)}
+ title={t('collab.polls.close')}
+ style={{
+ background: 'none',
+ border: 'none',
+ cursor: 'pointer',
+ padding: 4,
+ color: 'var(--text-faint)',
+ fontSize: 10,
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ }}
+ onMouseEnter={(e) => (e.currentTarget.style.color = 'var(--text-primary)')}
+ onMouseLeave={(e) => (e.currentTarget.style.color = 'var(--text-faint)')}
+ >
+ <Lock size={12} />
+ </button>
+ )}
+ <button
+ onClick={() => onDelete(poll.id)}
+ title={t('common.delete', 'Delete')}
+ style={{
+ background: 'none',
+ border: 'none',
+ cursor: 'pointer',
+ padding: 4,
+ color: 'var(--text-faint)',
+ fontSize: 10,
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ }}
+ onMouseEnter={(e) => (e.currentTarget.style.color = 'var(--danger, #ef4444)')}
+ onMouseLeave={(e) => (e.currentTarget.style.color = 'var(--text-faint)')}
+ >
+ <Trash2 size={12} />
+ </button>
+ </div>
+ )}
+ </div>
+
+ {/* Options */}
+ <div>
+ {poll.options?.map((opt, i) => (
+ <OptionBar
+ key={i}
+ option={opt}
+ index={i}
+ poll={poll}
+ currentUser={currentUser}
+ onVote={onVote}
+ isClosed={isClosed}
+ />
+ ))}
+ </div>
+ </div>
+ )
+}
+
+// ── Main Component ───────────────────────────────────────────────────────────
+
+function CollabPolls({ tripId, currentUser }) {
+ const { t } = useTranslation()
+ const [polls, setPolls] = useState([])
+ const [loading, setLoading] = useState(true)
+ const [showForm, setShowForm] = useState(false)
+
+ // ── Load polls ──
+ const loadPolls = useCallback(async () => {
+ try {
+ const data = await collabApi.getPolls(tripId)
+ setPolls(Array.isArray(data) ? data : data.polls || [])
+ } catch (err) {
+ console.error('Failed to load polls:', err)
+ } finally {
+ setLoading(false)
+ }
+ }, [tripId])
+
+ useEffect(() => {
+ loadPolls()
+ }, [loadPolls])
+
+ // ── WebSocket ──
+ useEffect(() => {
+ const handler = (msg) => {
+ if (!msg || !msg.type) return
+
+ if (msg.type === 'collab:poll:created' && msg.poll) {
+ setPolls((prev) => {
+ if (prev.some((p) => p.id === msg.poll.id)) return prev
+ return [msg.poll, ...prev]
+ })
+ }
+
+ if (msg.type === 'collab:poll:voted' && msg.poll) {
+ setPolls((prev) =>
+ prev.map((p) => (p.id === msg.poll.id ? msg.poll : p))
+ )
+ }
+
+ if (msg.type === 'collab:poll:closed' && msg.poll) {
+ setPolls((prev) =>
+ prev.map((p) => (p.id === msg.poll.id ? { ...p, ...msg.poll, is_closed: true } : p))
+ )
+ }
+
+ if (msg.type === 'collab:poll:deleted') {
+ const deletedId = msg.pollId || msg.poll?.id || msg.id
+ if (deletedId) {
+ setPolls((prev) => prev.filter((p) => p.id !== deletedId))
+ }
+ }
+ }
+
+ addListener(handler)
+ return () => removeListener(handler)
+ }, [])
+
+ // ── Actions ──
+ const handleCreate = useCallback(
+ async (data) => {
+ const result = await collabApi.createPoll(tripId, data)
+ const created = result.poll || result
+ setPolls((prev) => {
+ if (prev.some((p) => p.id === created.id)) return prev
+ return [created, ...prev]
+ })
+ setShowForm(false)
+ },
+ [tripId]
+ )
+
+ const handleVote = useCallback(
+ async (pollId, optionIndex) => {
+ try {
+ const result = await collabApi.votePoll(tripId, pollId, optionIndex)
+ const updated = result.poll || result
+ setPolls((prev) =>
+ prev.map((p) => (p.id === updated.id ? updated : p))
+ )
+ } catch (err) {
+ console.error('Vote failed:', err)
+ }
+ },
+ [tripId]
+ )
+
+ const handleClose = useCallback(
+ async (pollId) => {
+ try {
+ await collabApi.closePoll(tripId, pollId)
+ setPolls((prev) =>
+ prev.map((p) => (p.id === pollId ? { ...p, is_closed: true } : p))
+ )
+ } catch (err) {
+ console.error('Close poll failed:', err)
+ }
+ },
+ [tripId]
+ )
+
+ const handleDelete = useCallback(
+ async (pollId) => {
+ try {
+ await collabApi.deletePoll(tripId, pollId)
+ setPolls((prev) => prev.filter((p) => p.id !== pollId))
+ } catch (err) {
+ console.error('Delete poll failed:', err)
+ }
+ },
+ [tripId]
+ )
+
+ // ── Separate active / closed ──
+ const activePolls = polls.filter(
+ (p) => !p.is_closed && !isExpired(p.deadline)
+ )
+ const closedPolls = polls.filter(
+ (p) => p.is_closed || isExpired(p.deadline)
+ )
+
+ // ── Deadline countdown ticker ──
+ const [, setTick] = useState(0)
+ useEffect(() => {
+ const hasDeadlines = polls.some((p) => p.deadline && !p.is_closed)
+ if (!hasDeadlines) return
+ const iv = setInterval(() => setTick((t) => t + 1), 30000)
+ return () => clearInterval(iv)
+ }, [polls])
+
+ // ── Render ──
+ return (
+ <div
+ style={{
+ height: '100%',
+ display: 'flex',
+ flexDirection: 'column',
+ fontFamily: FONT,
+ }}
+ >
+ {/* Header — fixed */}
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ padding: '12px 16px',
+ borderBottom: '1px solid var(--border-faint)',
+ flexShrink: 0,
+ }}
+ >
+ <h3
+ style={{
+ margin: 0,
+ fontSize: 14,
+ fontWeight: 700,
+ color: 'var(--text-primary)',
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 6,
+ }}
+ >
+ <BarChart3 size={14} style={{ color: 'var(--accent)' }} />
+ {t('collab.polls.title')}
+ </h3>
+ {!showForm && (
+ <button
+ onClick={() => setShowForm(true)}
+ style={{
+ background: 'var(--accent)',
+ border: 'none',
+ borderRadius: 99,
+ padding: '4px 12px',
+ fontSize: 11,
+ fontWeight: 600,
+ color: '#fff',
+ cursor: 'pointer',
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 3,
+ }}
+ onMouseEnter={(e) => (e.currentTarget.style.opacity = '0.85')}
+ onMouseLeave={(e) => (e.currentTarget.style.opacity = '1')}
+ >
+ <Plus size={11} />
+ {t('collab.polls.new')}
+ </button>
+ )}
+ </div>
+
+ {/* Content — scrollable */}
+ <div
+ style={{
+ flex: 1,
+ overflowY: 'auto',
+ padding: 12,
+ }}
+ >
+ {/* Create form */}
+ {showForm && (
+ <CreatePollForm
+ onSubmit={handleCreate}
+ onCancel={() => setShowForm(false)}
+ t={t}
+ />
+ )}
+
+ {/* Loading */}
+ {loading && (
+ <div
+ style={{
+ textAlign: 'center',
+ padding: '32px 0',
+ color: 'var(--text-faint)',
+ fontSize: 12,
+ fontFamily: FONT,
+ }}
+ >
+ ...
+ </div>
+ )}
+
+ {/* Empty state */}
+ {!loading && polls.length === 0 && !showForm && (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ justifyContent: 'center',
+ padding: '40px 16px',
+ textAlign: 'center',
+ }}
+ >
+ <BarChart3
+ size={36}
+ style={{
+ color: 'var(--text-faint)',
+ marginBottom: 10,
+ }}
+ />
+ <div
+ style={{
+ fontSize: 14,
+ fontWeight: 600,
+ color: 'var(--text-primary)',
+ fontFamily: FONT,
+ marginBottom: 4,
+ }}
+ >
+ {t('collab.polls.empty')}
+ </div>
+ <div
+ style={{
+ fontSize: 12,
+ color: 'var(--text-faint)',
+ fontFamily: FONT,
+ }}
+ >
+ {t('collab.polls.emptyDesc', 'Create a poll to get started')}
+ </div>
+ </div>
+ )}
+
+ {/* Active polls */}
+ {!loading && (
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
+ {activePolls.map((poll) => (
+ <PollCard
+ key={poll.id}
+ poll={poll}
+ currentUser={currentUser}
+ onVote={handleVote}
+ onClose={handleClose}
+ onDelete={handleDelete}
+ t={t}
+ />
+ ))}
+ </div>
+ )}
+
+ {/* Closed polls divider + section */}
+ {!loading && closedPolls.length > 0 && (
+ <>
+ {activePolls.length > 0 && (
+ <div
+ style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: 8,
+ margin: '12px 0 8px',
+ }}
+ >
+ <div
+ style={{
+ flex: 1,
+ height: 1,
+ background: 'var(--border-faint)',
+ }}
+ />
+ <span
+ style={{
+ fontSize: 9,
+ fontWeight: 600,
+ color: 'var(--text-faint)',
+ textTransform: 'uppercase',
+ letterSpacing: 0.5,
+ fontFamily: FONT,
+ display: 'flex',
+ alignItems: 'center',
+ gap: 4,
+ whiteSpace: 'nowrap',
+ }}
+ >
+ <Lock size={9} />
+ {t('collab.polls.closed')}
+ </span>
+ <div
+ style={{
+ flex: 1,
+ height: 1,
+ background: 'var(--border-faint)',
+ }}
+ />
+ </div>
+ )}
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
+ {closedPolls.map((poll) => (
+ <PollCard
+ key={poll.id}
+ poll={poll}
+ currentUser={currentUser}
+ onVote={handleVote}
+ onClose={handleClose}
+ onDelete={handleDelete}
+ t={t}
+ />
+ ))}
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+ )
+}
+
+export default CollabPolls
diff --git a/client/src/components/Planner/PlaceInspector.jsx b/client/src/components/Planner/PlaceInspector.jsx
index b91d1e83e..473966263 100644
--- a/client/src/components/Planner/PlaceInspector.jsx
+++ b/client/src/components/Planner/PlaceInspector.jsx
@@ -344,8 +344,8 @@ export default function PlaceInspector({
)
})()}
- {/* Opening hours + Files — side by side on desktop */}
- <div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
+ {/* Opening hours + Files — side by side on desktop only if both exist */}
+ <div className={`grid grid-cols-1 ${openingHours?.length > 0 ? 'sm:grid-cols-2' : ''} gap-2`}>
{openingHours && openingHours.length > 0 && (
<div style={{ background: 'var(--bg-hover)', borderRadius: 10, overflow: 'hidden' }}>
<button
diff --git a/client/src/i18n/translations/de.js b/client/src/i18n/translations/de.js
index fe795bde9..4af7de21c 100644
--- a/client/src/i18n/translations/de.js
+++ b/client/src/i18n/translations/de.js
@@ -929,6 +929,44 @@ const de = {
'day.confirmation': 'Bestätigung',
'day.editAccommodation': 'Unterkunft bearbeiten',
'day.reservations': 'Reservierungen',
+
+ // Collab Addon
+ 'collab.tabs.chat': 'Chat',
+ 'collab.tabs.notes': 'Notizen',
+ 'collab.tabs.polls': 'Umfragen',
+ 'collab.chat.send': 'Senden',
+ 'collab.chat.placeholder': 'Nachricht eingeben...',
+ 'collab.chat.empty': 'Starte die Unterhaltung',
+ 'collab.chat.emptyHint': 'Nachrichten werden mit allen Reiseteilnehmern geteilt',
+ 'collab.chat.loadMore': 'Ältere Nachrichten laden',
+ 'collab.chat.justNow': 'gerade eben',
+ 'collab.chat.minutesAgo': 'vor {n} Min.',
+ 'collab.chat.hoursAgo': 'vor {n} Std.',
+ 'collab.chat.yesterday': 'gestern',
+ 'collab.notes.title': 'Notizen',
+ 'collab.notes.new': 'Neue Notiz',
+ 'collab.notes.empty': 'Noch keine Notizen',
+ 'collab.notes.emptyHint': 'Halte Ideen und Pläne fest',
+ 'collab.notes.all': 'Alle',
+ 'collab.notes.titlePlaceholder': 'Notiztitel',
+ 'collab.notes.contentPlaceholder': 'Schreibe etwas...',
+ 'collab.notes.categoryPlaceholder': 'Kategorie',
+ 'collab.notes.newCategory': 'Neue Kategorie...',
+ 'collab.polls.title': 'Umfragen',
+ 'collab.polls.new': 'Neue Umfrage',
+ 'collab.polls.empty': 'Noch keine Umfragen',
+ 'collab.polls.emptyHint': 'Frage die Gruppe und stimmt gemeinsam ab',
+ 'collab.polls.question': 'Frage',
+ 'collab.polls.questionPlaceholder': 'Was sollen wir machen?',
+ 'collab.polls.addOption': '+ Option hinzufügen',
+ 'collab.polls.optionPlaceholder': 'Option {n}',
+ 'collab.polls.create': 'Umfrage erstellen',
+ 'collab.polls.close': 'Schließen',
+ 'collab.polls.closed': 'Geschlossen',
+ 'collab.polls.votes': '{n} Stimmen',
+ 'collab.polls.vote': '{n} Stimme',
+ 'collab.polls.multipleChoice': 'Mehrfachauswahl',
+ 'collab.polls.deadline': 'Frist',
}
export default de
diff --git a/client/src/i18n/translations/en.js b/client/src/i18n/translations/en.js
index c6ae6191f..6df5c80a5 100644
--- a/client/src/i18n/translations/en.js
+++ b/client/src/i18n/translations/en.js
@@ -929,6 +929,44 @@ const en = {
'day.confirmation': 'Confirmation',
'day.editAccommodation': 'Edit accommodation',
'day.reservations': 'Reservations',
+
+ // Collab Addon
+ 'collab.tabs.chat': 'Chat',
+ 'collab.tabs.notes': 'Notes',
+ 'collab.tabs.polls': 'Polls',
+ 'collab.chat.send': 'Send',
+ 'collab.chat.placeholder': 'Type a message...',
+ 'collab.chat.empty': 'Start the conversation',
+ 'collab.chat.emptyHint': 'Messages are shared with all trip members',
+ 'collab.chat.loadMore': 'Load older messages',
+ 'collab.chat.justNow': 'just now',
+ 'collab.chat.minutesAgo': '{n}m ago',
+ 'collab.chat.hoursAgo': '{n}h ago',
+ 'collab.chat.yesterday': 'yesterday',
+ 'collab.notes.title': 'Notes',
+ 'collab.notes.new': 'New Note',
+ 'collab.notes.empty': 'No notes yet',
+ 'collab.notes.emptyHint': 'Start capturing ideas and plans',
+ 'collab.notes.all': 'All',
+ 'collab.notes.titlePlaceholder': 'Note title',
+ 'collab.notes.contentPlaceholder': 'Write something...',
+ 'collab.notes.categoryPlaceholder': 'Category',
+ 'collab.notes.newCategory': 'New category...',
+ 'collab.polls.title': 'Polls',
+ 'collab.polls.new': 'New Poll',
+ 'collab.polls.empty': 'No polls yet',
+ 'collab.polls.emptyHint': 'Ask the group and vote together',
+ 'collab.polls.question': 'Question',
+ 'collab.polls.questionPlaceholder': 'What should we do?',
+ 'collab.polls.addOption': '+ Add option',
+ 'collab.polls.optionPlaceholder': 'Option {n}',
+ 'collab.polls.create': 'Create Poll',
+ 'collab.polls.close': 'Close',
+ 'collab.polls.closed': 'Closed',
+ 'collab.polls.votes': '{n} votes',
+ 'collab.polls.vote': '{n} vote',
+ 'collab.polls.multipleChoice': 'Multiple choice',
+ 'collab.polls.deadline': 'Deadline',
}
export default en
diff --git a/client/src/pages/TripPlannerPage.jsx b/client/src/pages/TripPlannerPage.jsx
index 9acdc735d..0f73e704d 100644
--- a/client/src/pages/TripPlannerPage.jsx
+++ b/client/src/pages/TripPlannerPage.jsx
@@ -16,6 +16,7 @@ import ReservationsPanel from '../components/Planner/ReservationsPanel'
import PackingListPanel from '../components/Packing/PackingListPanel'
import FileManager from '../components/Files/FileManager'
import BudgetPanel from '../components/Budget/BudgetPanel'
+import CollabPanel from '../components/Collab/CollabPanel'
import Navbar from '../components/Layout/Navbar'
import { useToast } from '../components/shared/Toast'
import { Map, X, PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen } from 'lucide-react'
@@ -48,7 +49,7 @@ export default function TripPlannerPage() {
addonsApi.enabled().then(data => {
const map = {}
data.addons.forEach(a => { map[a.id] = true })
- setEnabledAddons({ packing: !!map.packing, budget: !!map.budget, documents: !!map.documents })
+ setEnabledAddons({ packing: !!map.packing, budget: !!map.budget, documents: !!map.documents, collab: !!map.collab })
}).catch(() => {})
authApi.getAppConfig().then(config => {
if (config.allowed_file_types) setAllowedFileTypes(config.allowed_file_types)
@@ -61,6 +62,7 @@ export default function TripPlannerPage() {
...(enabledAddons.packing ? [{ id: 'packliste', label: t('trip.tabs.packing'), shortLabel: t('trip.tabs.packingShort') }] : []),
...(enabledAddons.budget ? [{ id: 'finanzplan', label: t('trip.tabs.budget') }] : []),
...(enabledAddons.documents ? [{ id: 'dateien', label: t('trip.tabs.files') }] : []),
+ ...(enabledAddons.collab ? [{ id: 'collab', label: 'Collab' }] : []),
]
const [activeTab, setActiveTab] = useState('plan')
@@ -673,6 +675,12 @@ export default function TripPlannerPage() {
/>
</div>
)}
+
+ {activeTab === 'collab' && (
+ <div style={{ height: '100%', overflow: 'hidden', overscrollBehavior: 'contain' }}>
+ <CollabPanel tripId={tripId} />
+ </div>
+ )}
</div>
<PlaceFormModal isOpen={showPlaceForm} onClose={() => { setShowPlaceForm(false); setEditingPlace(null) }} onSave={handleSavePlace} place={editingPlace} tripId={tripId} categories={categories} onCategoryCreated={cat => tripStore.addCategory?.(cat)} />
diff --git a/docker-compose.yml b/docker-compose.yml
index 820e85fb4..1374f2947 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -14,7 +14,7 @@ services:
- ./uploads:/app/uploads
restart: unless-stopped
healthcheck:
- test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/auth/me"]
+ test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/health"]
interval: 30s
timeout: 10s
retries: 3
diff --git a/server/src/db/database.js b/server/src/db/database.js
index 9cf801741..f3005fea3 100644
--- a/server/src/db/database.js
+++ b/server/src/db/database.js
@@ -316,6 +316,54 @@ function initDb() {
notes TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
+
+ -- Collab addon tables
+ CREATE TABLE IF NOT EXISTS collab_notes (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ category TEXT DEFAULT 'General',
+ title TEXT NOT NULL,
+ content TEXT,
+ color TEXT DEFAULT '#6366f1',
+ pinned INTEGER DEFAULT 0,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ );
+
+ CREATE TABLE IF NOT EXISTS collab_polls (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ question TEXT NOT NULL,
+ options TEXT NOT NULL,
+ multiple INTEGER DEFAULT 0,
+ closed INTEGER DEFAULT 0,
+ deadline TEXT,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ );
+
+ CREATE TABLE IF NOT EXISTS collab_poll_votes (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ poll_id INTEGER NOT NULL REFERENCES collab_polls(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ option_index INTEGER NOT NULL,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ UNIQUE(poll_id, user_id, option_index)
+ );
+
+ CREATE TABLE IF NOT EXISTS collab_messages (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ text TEXT NOT NULL,
+ reply_to INTEGER REFERENCES collab_messages(id) ON DELETE SET NULL,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ );
+
+ CREATE INDEX IF NOT EXISTS idx_collab_notes_trip ON collab_notes(trip_id);
+ CREATE INDEX IF NOT EXISTS idx_collab_polls_trip ON collab_polls(trip_id);
+ CREATE INDEX IF NOT EXISTS idx_collab_messages_trip ON collab_messages(trip_id);
`);
// Create indexes for performance
@@ -457,6 +505,57 @@ function initDb() {
)
`);
},
+ // 25: Collab addon tables
+ () => {
+ _db.exec(`
+ CREATE TABLE IF NOT EXISTS collab_notes (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ category TEXT DEFAULT 'General',
+ title TEXT NOT NULL,
+ content TEXT,
+ color TEXT DEFAULT '#6366f1',
+ pinned INTEGER DEFAULT 0,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ );
+ CREATE TABLE IF NOT EXISTS collab_polls (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ question TEXT NOT NULL,
+ options TEXT NOT NULL,
+ multiple INTEGER DEFAULT 0,
+ closed INTEGER DEFAULT 0,
+ deadline TEXT,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ );
+ CREATE TABLE IF NOT EXISTS collab_poll_votes (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ poll_id INTEGER NOT NULL REFERENCES collab_polls(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ option_index INTEGER NOT NULL,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ UNIQUE(poll_id, user_id, option_index)
+ );
+ CREATE TABLE IF NOT EXISTS collab_messages (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ trip_id INTEGER NOT NULL REFERENCES trips(id) ON DELETE CASCADE,
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ text TEXT NOT NULL,
+ reply_to INTEGER REFERENCES collab_messages(id) ON DELETE SET NULL,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+ );
+ CREATE INDEX IF NOT EXISTS idx_collab_notes_trip ON collab_notes(trip_id);
+ CREATE INDEX IF NOT EXISTS idx_collab_polls_trip ON collab_polls(trip_id);
+ CREATE INDEX IF NOT EXISTS idx_collab_messages_trip ON collab_messages(trip_id);
+ `);
+ // Ensure collab addon exists for existing installations
+ try {
+ _db.prepare("INSERT OR IGNORE INTO addons (id, name, description, type, icon, enabled, sort_order) VALUES ('collab', 'Collab', 'Notes, polls, and live chat for trip collaboration', 'trip', 'Users', 0, 6)").run();
+ } catch {}
+ },
// Future migrations go here (append only, never reorder)
];
@@ -505,6 +604,7 @@ function initDb() {
{ id: 'documents', name: 'Documents', description: 'Store and manage travel documents', type: 'trip', icon: 'FileText', sort_order: 2 },
{ id: 'vacay', name: 'Vacay', description: 'Personal vacation day planner with calendar view', type: 'global', icon: 'CalendarDays', sort_order: 10 },
{ id: 'atlas', name: 'Atlas', description: 'World map of your visited countries with travel stats', type: 'global', icon: 'Globe', sort_order: 11 },
+ { id: 'collab', name: 'Collab', description: 'Notes, polls, and live chat for trip collaboration', type: 'trip', icon: 'Users', sort_order: 6 },
];
const insertAddon = _db.prepare('INSERT INTO addons (id, name, description, type, icon, enabled, sort_order) VALUES (?, ?, ?, ?, ?, 1, ?)');
for (const a of defaultAddons) insertAddon.run(a.id, a.name, a.description, a.type, a.icon, a.sort_order);
diff --git a/server/src/index.js b/server/src/index.js
index 6a503fd69..5a1751ab8 100644
--- a/server/src/index.js
+++ b/server/src/index.js
@@ -71,6 +71,7 @@ const dayNotesRoutes = require('./routes/dayNotes');
const weatherRoutes = require('./routes/weather');
const settingsRoutes = require('./routes/settings');
const budgetRoutes = require('./routes/budget');
+const collabRoutes = require('./routes/collab');
const backupRoutes = require('./routes/backup');
const oidcRoutes = require('./routes/oidc');
@@ -83,8 +84,10 @@ app.use('/api/trips/:tripId/places', placesRoutes);
app.use('/api/trips/:tripId/packing', packingRoutes);
app.use('/api/trips/:tripId/files', filesRoutes);
app.use('/api/trips/:tripId/budget', budgetRoutes);
+app.use('/api/trips/:tripId/collab', collabRoutes);
app.use('/api/trips/:tripId/reservations', reservationsRoutes);
app.use('/api/trips/:tripId/days/:dayId/notes', dayNotesRoutes);
+app.get('/api/health', (req, res) => res.json({ status: 'ok' }));
app.use('/api', assignmentsRoutes);
app.use('/api/tags', tagsRoutes);
app.use('/api/categories', categoriesRoutes);
diff --git a/server/src/routes/collab.js b/server/src/routes/collab.js
new file mode 100644
index 000000000..350ff576c
--- /dev/null
+++ b/server/src/routes/collab.js
@@ -0,0 +1,365 @@
+const express = require('express');
+const { db, canAccessTrip } = require('../db/database');
+const { authenticate } = require('../middleware/auth');
+const { broadcast } = require('../websocket');
+
+const router = express.Router({ mergeParams: true });
+
+function verifyTripAccess(tripId, userId) {
+ return canAccessTrip(tripId, userId);
+}
+
+// ─── NOTES ───────────────────────────────────────────────────────────────────
+
+// GET /notes - list all notes for trip
+router.get('/notes', authenticate, (req, res) => {
+ const { tripId } = req.params;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const notes = db.prepare(`
+ SELECT n.*, u.username, u.avatar
+ FROM collab_notes n
+ JOIN users u ON n.user_id = u.id
+ WHERE n.trip_id = ?
+ ORDER BY n.pinned DESC, n.updated_at DESC
+ `).all(tripId);
+
+ res.json({ notes });
+});
+
+// POST /notes - create note
+router.post('/notes', authenticate, (req, res) => {
+ const { tripId } = req.params;
+ const { title, content, category, color } = req.body;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ if (!title) return res.status(400).json({ error: 'Title is required' });
+
+ const result = db.prepare(`
+ INSERT INTO collab_notes (trip_id, user_id, title, content, category, color)
+ VALUES (?, ?, ?, ?, ?, ?)
+ `).run(tripId, req.user.id, title, content || null, category || 'General', color || '#6366f1');
+
+ const note = db.prepare(`
+ SELECT n.*, u.username, u.avatar
+ FROM collab_notes n
+ JOIN users u ON n.user_id = u.id
+ WHERE n.id = ?
+ `).get(result.lastInsertRowid);
+
+ res.status(201).json({ note });
+ broadcast(tripId, 'collab:note:created', { note }, req.headers['x-socket-id']);
+});
+
+// PUT /notes/:id - update note
+router.put('/notes/:id', authenticate, (req, res) => {
+ const { tripId, id } = req.params;
+ const { title, content, category, color, pinned } = req.body;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const existing = db.prepare('SELECT * FROM collab_notes WHERE id = ? AND trip_id = ?').get(id, tripId);
+ if (!existing) return res.status(404).json({ error: 'Note not found' });
+
+ db.prepare(`
+ UPDATE collab_notes SET
+ title = COALESCE(?, title),
+ content = CASE WHEN ? THEN ? ELSE content END,
+ category = COALESCE(?, category),
+ color = COALESCE(?, color),
+ pinned = CASE WHEN ? IS NOT NULL THEN ? ELSE pinned END,
+ updated_at = CURRENT_TIMESTAMP
+ WHERE id = ?
+ `).run(
+ title || null,
+ content !== undefined ? 1 : 0, content !== undefined ? content : null,
+ category || null,
+ color || null,
+ pinned !== undefined ? 1 : null, pinned ? 1 : 0,
+ id
+ );
+
+ const note = db.prepare(`
+ SELECT n.*, u.username, u.avatar
+ FROM collab_notes n
+ JOIN users u ON n.user_id = u.id
+ WHERE n.id = ?
+ `).get(id);
+
+ res.json({ note });
+ broadcast(tripId, 'collab:note:updated', { note }, req.headers['x-socket-id']);
+});
+
+// DELETE /notes/:id - delete note
+router.delete('/notes/:id', authenticate, (req, res) => {
+ const { tripId, id } = req.params;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const existing = db.prepare('SELECT id FROM collab_notes WHERE id = ? AND trip_id = ?').get(id, tripId);
+ if (!existing) return res.status(404).json({ error: 'Note not found' });
+
+ db.prepare('DELETE FROM collab_notes WHERE id = ?').run(id);
+ res.json({ success: true });
+ broadcast(tripId, 'collab:note:deleted', { noteId: Number(id) }, req.headers['x-socket-id']);
+});
+
+// ─── POLLS ───────────────────────────────────────────────────────────────────
+
+// Helper: fetch a poll with aggregated votes
+function getPollWithVotes(pollId) {
+ const poll = db.prepare(`
+ SELECT p.*, u.username, u.avatar
+ FROM collab_polls p
+ JOIN users u ON p.user_id = u.id
+ WHERE p.id = ?
+ `).get(pollId);
+
+ if (!poll) return null;
+
+ poll.options = JSON.parse(poll.options);
+
+ const votes = db.prepare(`
+ SELECT v.option_index, v.user_id, u.username, u.avatar
+ FROM collab_poll_votes v
+ JOIN users u ON v.user_id = u.id
+ WHERE v.poll_id = ?
+ `).all(pollId);
+
+ poll.votes = votes;
+ return poll;
+}
+
+// GET /polls - list all polls with votes
+router.get('/polls', authenticate, (req, res) => {
+ const { tripId } = req.params;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const rows = db.prepare(`
+ SELECT p.*, u.username, u.avatar
+ FROM collab_polls p
+ JOIN users u ON p.user_id = u.id
+ WHERE p.trip_id = ?
+ ORDER BY p.created_at DESC
+ `).all(tripId);
+
+ const polls = rows.map(poll => {
+ poll.options = JSON.parse(poll.options);
+
+ const votes = db.prepare(`
+ SELECT v.option_index, v.user_id, u.username, u.avatar
+ FROM collab_poll_votes v
+ JOIN users u ON v.user_id = u.id
+ WHERE v.poll_id = ?
+ `).all(poll.id);
+
+ poll.votes = votes;
+ return poll;
+ });
+
+ res.json({ polls });
+});
+
+// POST /polls - create poll
+router.post('/polls', authenticate, (req, res) => {
+ const { tripId } = req.params;
+ const { question, options, multiple, deadline } = req.body;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ if (!question) return res.status(400).json({ error: 'Question is required' });
+ if (!Array.isArray(options) || options.length < 2) {
+ return res.status(400).json({ error: 'At least 2 options are required' });
+ }
+
+ const result = db.prepare(`
+ INSERT INTO collab_polls (trip_id, user_id, question, options, multiple, deadline)
+ VALUES (?, ?, ?, ?, ?, ?)
+ `).run(tripId, req.user.id, question, JSON.stringify(options), multiple ? 1 : 0, deadline || null);
+
+ const poll = getPollWithVotes(result.lastInsertRowid);
+
+ res.status(201).json({ poll });
+ broadcast(tripId, 'collab:poll:created', { poll }, req.headers['x-socket-id']);
+});
+
+// POST /polls/:id/vote - toggle vote on poll
+router.post('/polls/:id/vote', authenticate, (req, res) => {
+ const { tripId, id } = req.params;
+ const { option_index } = req.body;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const poll = db.prepare('SELECT * FROM collab_polls WHERE id = ? AND trip_id = ?').get(id, tripId);
+ if (!poll) return res.status(404).json({ error: 'Poll not found' });
+ if (poll.closed) return res.status(400).json({ error: 'Poll is closed' });
+
+ const options = JSON.parse(poll.options);
+ if (option_index < 0 || option_index >= options.length) {
+ return res.status(400).json({ error: 'Invalid option index' });
+ }
+
+ // Toggle: if vote exists, remove it; otherwise add it
+ const existingVote = db.prepare(
+ 'SELECT id FROM collab_poll_votes WHERE poll_id = ? AND user_id = ? AND option_index = ?'
+ ).get(id, req.user.id, option_index);
+
+ if (existingVote) {
+ db.prepare('DELETE FROM collab_poll_votes WHERE id = ?').run(existingVote.id);
+ } else {
+ // If not multiple choice, remove any existing votes by this user first
+ if (!poll.multiple) {
+ db.prepare('DELETE FROM collab_poll_votes WHERE poll_id = ? AND user_id = ?').run(id, req.user.id);
+ }
+ db.prepare(
+ 'INSERT INTO collab_poll_votes (poll_id, user_id, option_index) VALUES (?, ?, ?)'
+ ).run(id, req.user.id, option_index);
+ }
+
+ const updatedPoll = getPollWithVotes(id);
+
+ res.json({ poll: updatedPoll });
+ broadcast(tripId, 'collab:poll:voted', { poll: updatedPoll }, req.headers['x-socket-id']);
+});
+
+// PUT /polls/:id/close - close poll
+router.put('/polls/:id/close', authenticate, (req, res) => {
+ const { tripId, id } = req.params;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const poll = db.prepare('SELECT * FROM collab_polls WHERE id = ? AND trip_id = ?').get(id, tripId);
+ if (!poll) return res.status(404).json({ error: 'Poll not found' });
+
+ db.prepare('UPDATE collab_polls SET closed = 1 WHERE id = ?').run(id);
+
+ const updatedPoll = getPollWithVotes(id);
+
+ res.json({ poll: updatedPoll });
+ broadcast(tripId, 'collab:poll:closed', { poll: updatedPoll }, req.headers['x-socket-id']);
+});
+
+// DELETE /polls/:id - delete poll
+router.delete('/polls/:id', authenticate, (req, res) => {
+ const { tripId, id } = req.params;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const poll = db.prepare('SELECT id FROM collab_polls WHERE id = ? AND trip_id = ?').get(id, tripId);
+ if (!poll) return res.status(404).json({ error: 'Poll not found' });
+
+ db.prepare('DELETE FROM collab_polls WHERE id = ?').run(id);
+ res.json({ success: true });
+ broadcast(tripId, 'collab:poll:deleted', { pollId: Number(id) }, req.headers['x-socket-id']);
+});
+
+// ─── MESSAGES (CHAT) ────────────────────────────────────────────────────────
+
+// GET /messages - list messages (last 100, with pagination via ?before=id)
+router.get('/messages', authenticate, (req, res) => {
+ const { tripId } = req.params;
+ const { before } = req.query;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ let messages;
+ if (before) {
+ messages = db.prepare(`
+ SELECT m.*, u.username, u.avatar,
+ rm.text AS reply_text, ru.username AS reply_username
+ FROM collab_messages m
+ JOIN users u ON m.user_id = u.id
+ LEFT JOIN collab_messages rm ON m.reply_to = rm.id
+ LEFT JOIN users ru ON rm.user_id = ru.id
+ WHERE m.trip_id = ? AND m.id < ?
+ ORDER BY m.id DESC
+ LIMIT 100
+ `).all(tripId, before);
+ } else {
+ messages = db.prepare(`
+ SELECT m.*, u.username, u.avatar,
+ rm.text AS reply_text, ru.username AS reply_username
+ FROM collab_messages m
+ JOIN users u ON m.user_id = u.id
+ LEFT JOIN collab_messages rm ON m.reply_to = rm.id
+ LEFT JOIN users ru ON rm.user_id = ru.id
+ WHERE m.trip_id = ?
+ ORDER BY m.id DESC
+ LIMIT 100
+ `).all(tripId);
+ }
+
+ // Return in chronological order (oldest first)
+ messages.reverse();
+
+ res.json({ messages });
+});
+
+// POST /messages - send message
+router.post('/messages', authenticate, (req, res) => {
+ const { tripId } = req.params;
+ const { text, reply_to } = req.body;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ if (!text || !text.trim()) return res.status(400).json({ error: 'Message text is required' });
+
+ // Validate reply_to if provided
+ if (reply_to) {
+ const replyMsg = db.prepare('SELECT id FROM collab_messages WHERE id = ? AND trip_id = ?').get(reply_to, tripId);
+ if (!replyMsg) return res.status(400).json({ error: 'Reply target message not found' });
+ }
+
+ const result = db.prepare(`
+ INSERT INTO collab_messages (trip_id, user_id, text, reply_to)
+ VALUES (?, ?, ?, ?)
+ `).run(tripId, req.user.id, text.trim(), reply_to || null);
+
+ const message = db.prepare(`
+ SELECT m.*, u.username, u.avatar,
+ rm.text AS reply_text, ru.username AS reply_username
+ FROM collab_messages m
+ JOIN users u ON m.user_id = u.id
+ LEFT JOIN collab_messages rm ON m.reply_to = rm.id
+ LEFT JOIN users ru ON rm.user_id = ru.id
+ WHERE m.id = ?
+ `).get(result.lastInsertRowid);
+
+ res.status(201).json({ message });
+ broadcast(tripId, 'collab:message:created', { message }, req.headers['x-socket-id']);
+});
+
+// DELETE /messages/:id - delete own message
+router.delete('/messages/:id', authenticate, (req, res) => {
+ const { tripId, id } = req.params;
+
+ const trip = verifyTripAccess(tripId, req.user.id);
+ if (!trip) return res.status(404).json({ error: 'Trip not found' });
+
+ const message = db.prepare('SELECT * FROM collab_messages WHERE id = ? AND trip_id = ?').get(id, tripId);
+ if (!message) return res.status(404).json({ error: 'Message not found' });
+
+ if (message.user_id !== req.user.id) {
+ return res.status(403).json({ error: 'You can only delete your own messages' });
+ }
+
+ db.prepare('DELETE FROM collab_messages WHERE id = ?').run(id);
+ res.json({ success: true });
+ broadcast(tripId, 'collab:message:deleted', { messageId: Number(id) }, req.headers['x-socket-id']);
+});
+
+module.exports = router;