Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python
12.8 KB
Raw Blame
<!-- Floating Dockable Chat Panel (design system v1, redesigned).
     States:
       - 'collapsed'  : FAB only (bottom-right of viewport)
       - 'floating'   : free-positioned 480×640 (default), draggable, resizable
       - 'dock-left'  : overlays the transcript column
       - 'dock-right' : overlays the right rail
       - 'dock-full'  : overlays both content columns (never under the
                       sidebar or bottom audio player)

     Header carries the dock targets (◧ left, ▢ full, ◨ right) plus a
     close button. A SE-corner resize handle is shown in floating mode.
-->
<Teleport to="body">
    <div v-if="currentView === 'detail' && selectedRecording" class="floating-chat-root">
        <!-- FAB (collapsed). Position is derived from the same
             #mainContentColumns rect that the floating/docked panel
             uses, so the FAB sits just inside the bottom-right of the
             content area regardless of where the audio player is
             docked (top vs bottom). chatLayoutTick is touched to make
             this style reactive to layout changes the ResizeObserver
             catches. -->
        <button v-if="chatPanelState === 'collapsed'"
                @click="openChatPanel"
                class="floating-chat-fab"
                :style="floatingChatFabStyle"
                :title="t('chat.chatWithTranscription')">
            <i class="fas fa-comments"></i>
            <span v-if="chatMessages && chatMessages.length > 0" class="floating-chat-fab-badge">
                ${chatMessages.length}
            </span>
        </button>

        <!-- Panel (any non-collapsed state) -->
        <div v-else
             class="floating-chat-panel"
             :class="[
                 'is-' + chatPanelState,
                 chatDragActive ? 'is-dragging' : '',
                 chatResizeActive ? 'is-resizing' : ''
             ]"
             :style="floatingChatPanelStyle">
            <!-- Header — drag handle + dock targets + close -->
            <div class="floating-chat-header"
                 @mousedown="startChatPanelDrag"
                 @touchstart.passive="startChatPanelDrag">
                <div class="floating-chat-header-title">
                    <i class="fas fa-comments"></i>
                    <span>${ t('chat.chatWithTranscription') }</span>
                    <span v-if="chatMessages && chatMessages.length > 0" class="tab__count">${chatMessages.length}</span>
                </div>
                <div class="floating-chat-header-actions" @mousedown.stop @touchstart.stop>
                    <button v-if="chatMessages.length > 0"
                            @click="downloadChat"
                            class="btn btn--icon btn--sm"
                            :title="t('buttons.downloadChat')">
                        <i class="fas fa-download"></i>
                    </button>
                    <button v-if="chatMessages.length > 0"
                            @click="clearChat"
                            class="btn btn--icon btn--sm"
                            style="color: var(--text-muted);"
                            :title="t('tooltips.clearChat')">
                        <i class="fas fa-eraser"></i>
                    </button>
                    <span class="floating-chat-dock-divider"></span>
                    <!-- Split dock button: main half toggles dock with
                         last-chosen target; caret opens dropdown to
                         pick a different target. Icons: a 2-cell
                         rectangle with the active half filled. -->
                    <div class="floating-chat-dock-split">
                        <button @click="toggleChatDockToLast"
                                class="btn btn--icon btn--sm floating-chat-dock-main"
                                :class="{ 'is-active': chatPanelState === ('dock-' + chatLastDock) }"
                                :title="chatPanelState === ('dock-' + chatLastDock) ? t('floatingChat.undock') : (chatLastDock === 'left' ? t('floatingChat.dockLeft') : chatLastDock === 'right' ? t('floatingChat.dockRight') : t('floatingChat.dockFull'))">
                            <!-- Dock-left icon (left half filled) -->
                            <svg v-if="chatLastDock === 'left'" width="14" height="10" viewBox="0 0 14 10" aria-hidden="true">
                                <rect x="0.5" y="0.5" width="6" height="9" fill="currentColor"/>
                                <rect x="7.5" y="0.5" width="6" height="9" fill="none" stroke="currentColor"/>
                            </svg>
                            <!-- Dock-right icon (right half filled) -->
                            <svg v-else-if="chatLastDock === 'right'" width="14" height="10" viewBox="0 0 14 10" aria-hidden="true">
                                <rect x="0.5" y="0.5" width="6" height="9" fill="none" stroke="currentColor"/>
                                <rect x="7.5" y="0.5" width="6" height="9" fill="currentColor"/>
                            </svg>
                            <!-- Dock-full icon (whole rect filled) -->
                            <svg v-else width="14" height="10" viewBox="0 0 14 10" aria-hidden="true">
                                <rect x="0.5" y="0.5" width="13" height="9" fill="currentColor"/>
                            </svg>
                        </button>
                        <button @click.stop="chatDockMenuOpen = !chatDockMenuOpen"
                                class="btn btn--icon btn--sm floating-chat-dock-caret"
                                :title="t('floatingChat.chooseDockTarget')">
                            <i class="fas fa-caret-down" style="font-size: 10px;"></i>
                        </button>
                        <div v-if="chatDockMenuOpen"
                             class="floating-chat-dock-menu surface-raised"
                             @click.stop>
                            <button @click="dockChatPanel('left')"
                                    class="floating-chat-dock-menu-item"
                                    :class="{ 'is-active': chatPanelState === 'dock-left' }">
                                <svg width="14" height="10" viewBox="0 0 14 10" aria-hidden="true">
                                    <rect x="0.5" y="0.5" width="6" height="9" fill="currentColor"/>
                                    <rect x="7.5" y="0.5" width="6" height="9" fill="none" stroke="currentColor"/>
                                </svg>
                                <span v-text="t('floatingChat.dockLeft')"></span>
                            </button>
                            <button @click="dockChatPanel('full')"
                                    class="floating-chat-dock-menu-item"
                                    :class="{ 'is-active': chatPanelState === 'dock-full' }">
                                <svg width="14" height="10" viewBox="0 0 14 10" aria-hidden="true">
                                    <rect x="0.5" y="0.5" width="13" height="9" fill="currentColor"/>
                                </svg>
                                <span v-text="t('floatingChat.dockFull')"></span>
                            </button>
                            <button @click="dockChatPanel('right')"
                                    class="floating-chat-dock-menu-item"
                                    :class="{ 'is-active': chatPanelState === 'dock-right' }">
                                <svg width="14" height="10" viewBox="0 0 14 10" aria-hidden="true">
                                    <rect x="0.5" y="0.5" width="6" height="9" fill="none" stroke="currentColor"/>
                                    <rect x="7.5" y="0.5" width="6" height="9" fill="currentColor"/>
                                </svg>
                                <span v-text="t('floatingChat.dockRight')"></span>
                            </button>
                        </div>
                    </div>
                    <span class="floating-chat-dock-divider"></span>
                    <button @click="collapseChatPanel"
                            class="btn btn--icon btn--sm"
                            :title="t('buttons.close')">
                        <i class="fas fa-times"></i>
                    </button>
                </div>
            </div>

            <!-- Messages -->
            <div ref="chatMessagesRef" class="floating-chat-messages" @click="handleChatBubbleClick">
                <div v-if="chatMessages.length === 0" class="empty">
                    <div class="empty__icon"><i class="fas fa-robot"></i></div>
                    <div class="empty__title" v-text="t('help.askAboutTranscription')"></div>
                    <div class="empty__body" v-text="t('chat.emptyHint')"></div>
                </div>

                <div v-for="(message, index) in chatMessages" :key="index"
                     :class="['message relative group',
                              message.role === 'user' ? 'user-message ml-auto' : 'ai-message',
                              message.role === 'assistant' ? 'pr-10' : '']">
                    <button v-if="message.role === 'assistant'"
                            @click="copyMessage(message.content, $event)"
                            class="btn btn--icon btn--sm absolute"
                            style="top: var(--sp-2); right: var(--sp-2);"
                            :title="t('buttons.copyMessage')">
                        <i class="fas fa-copy"></i>
                    </button>
                    <div v-if="message.thinking && message.role === 'assistant'" class="mb-2">
                        <button @click="message.thinkingExpanded = !message.thinkingExpanded"
                                class="text-xs text-[var(--text-muted)] hover:text-[var(--text-secondary)] flex items-center gap-1">
                            <i :class="['fas', message.thinkingExpanded ? 'fa-chevron-down' : 'fa-chevron-right']"></i>
                            <span v-text="t('help.modelReasoning')"></span>
                            <span class="text-[var(--text-muted)]" v-text="'(' + t('help.lines', { count: message.thinking.split('\n').length }) + ')'"></span>
                        </button>
                        <div v-if="message.thinkingExpanded"
                             class="mt-2 p-3 bg-[var(--bg-tertiary)] border border-[var(--border-primary)] rounded-md text-xs text-[var(--text-muted)] max-h-64 overflow-y-auto">
                            <pre class="whitespace-pre-wrap font-mono">${message.thinking}</pre>
                        </div>
                    </div>
                    <div v-if="message.html" class="bidi-auto" v-html="message.html"></div>
                    <div v-else class="whitespace-pre-wrap bidi-auto">${message.content}</div>
                </div>

                <div v-if="isChatLoading" class="ai-message flex items-center gap-2">
                    <div class="spinner"></div>
                    <span v-text="t('chat.thinking')"></span>
                </div>
            </div>

            <!-- Input -->
            <div class="floating-chat-input">
                <div class="flex gap-2 items-end">
                    <textarea v-model="chatInput"
                              ref="chatInputRef"
                              @keydown="handleChatKeydown"
                              :disabled="selectedRecording.status !== 'COMPLETED' || processedTranscription.isError"
                              :placeholder="t('chat.placeholderWithHint')"
                              class="field"
                              style="resize: none;"
                              rows="2"></textarea>
                    <button @click="sendChatMessage"
                            :disabled="!chatInput.trim() || isChatLoading || selectedRecording.status !== 'COMPLETED' || processedTranscription.isError"
                            class="btn btn--primary btn--icon btn--lg"
                            :title="t('buttons.send') || 'Send'">
                        <i class="fas fa-paper-plane"></i>
                    </button>
                </div>
                <div v-if="processedTranscription.isError" class="t-meta mt-2 flex items-center gap-1.5">
                    <i class="fas fa-info-circle"></i>
                    <span v-text="t('chat.cannotChatTranscriptionFailed')"></span>
                </div>
                <div v-else-if="selectedRecording.status !== 'COMPLETED'" class="t-meta mt-2">
                    <span v-text="t('chat.availableAfterTranscription')"></span>
                </div>
            </div>

            <!-- Resize handle (floating mode only) -->
            <div v-if="chatPanelState === 'floating'"
                 class="floating-chat-resize-handle"
                 @mousedown="startChatPanelResize"
                 @touchstart.passive="startChatPanelResize"
                 :title="t('tooltips.dragToResize')">
            </div>
        </div>
    </div>
</Teleport>