55import React , { useState } from 'react' ;
66import { useChat } from '../../context/ChatContext' ;
77import { Button } from '../common/Button' ;
8- import { CopyIcon , ShareIcon , PhoneIcon } from '../common/icons' ;
8+ import { CopyIcon , ShareIcon , PhoneIcon , TrashIcon } from '../common/icons' ;
99import './ChatHeader.css' ;
1010
1111interface ChatHeaderProps {
1212 onStartCall : ( ) => void ;
1313}
1414
1515export const ChatHeader : React . FC < ChatHeaderProps > = ( { onStartCall } ) => {
16- const { isConnected, channelHash } = useChat ( ) ;
16+ const { isConnected, channelHash, deleteChannel } = useChat ( ) ;
1717 const [ hashCopied , setHashCopied ] = useState ( false ) ;
1818
1919 const handleCopyHash = ( ) => {
@@ -36,6 +36,18 @@ export const ChatHeader: React.FC<ChatHeaderProps> = ({ onStartCall }) => {
3636 }
3737 } ;
3838
39+ const handleDelete = async ( ) => {
40+ if ( ! window . confirm ( 'Are you sure you want to delete this secure channel? This cannot be undone.' ) ) return ;
41+
42+ try {
43+ await deleteChannel ( ) ;
44+ window . location . hash = '' ; // Clear URL hash
45+ } catch ( err ) {
46+ console . error ( 'Failed to delete channel:' , err ) ;
47+ alert ( ( err as any ) . message || 'Failed to delete channel' ) ;
48+ }
49+ } ;
50+
3951 return (
4052 < header className = { `chat-header glass ${ isConnected ? 'active' : '' } ` } >
4153 < div className = "header-info" >
@@ -81,6 +93,15 @@ export const ChatHeader: React.FC<ChatHeaderProps> = ({ onStartCall }) => {
8193 >
8294 < PhoneIcon size = { 20 } />
8395 </ Button >
96+ < Button
97+ className = "btn--icon"
98+ variant = "danger"
99+ onClick = { handleDelete }
100+ title = "Delete Chat"
101+ disabled = { ! channelHash }
102+ >
103+ < TrashIcon size = { 20 } />
104+ </ Button >
84105 </ div >
85106 </ header >
86107 ) ;
0 commit comments