Skip to content

Commit bbd10fc

Browse files
author
VishnuGadekar7
committed
github workflow issues resolved
1 parent 9c1f01b commit bbd10fc

12 files changed

Lines changed: 79 additions & 65 deletions

File tree

client/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import React, { useEffect, useState } from 'react';
66
import { useChat } from './context/ChatContext';
77
import { SetupOverlay } from './components/SetupOverlay/SetupOverlay';
88
import { ChatContainer } from './components/ChatContainer/ChatContainer';
9-
import { updateUrlHash } from './utils/callTimer';
9+
import { updateUrlHash } from './utils/urlHash';
1010
import './styles/global.css';
1111

1212
const AppContent: React.FC = () => {
13-
const { initializeChat, joinChannel, channelHash } = useChat();
13+
const { initializeChat, joinChannel } = useChat();
1414
const [showSetup, setShowSetup] = useState(true);
1515
const [error, setError] = useState<string>('');
1616

client/src/components/CallOverlay/CallOverlay.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import './CallOverlay.css';
1111

1212
export const CallOverlay: React.FC = () => {
1313
const { callActive, callStatus, endCall } = useChat();
14-
const { duration, formatDuration, startTimer } = useCallTimer();
14+
const { duration, formatDuration, startTimer, stopTimer } = useCallTimer();
1515

1616
useEffect(() => {
1717
if (callActive && callStatus === 'Connected') {
1818
startTimer();
19+
} else {
20+
stopTimer();
1921
}
20-
}, [callActive, callStatus, startTimer]);
22+
}, [callActive, callStatus, startTimer, stopTimer]);
2123

2224
if (!callActive) return null;
2325

client/src/components/ChatContainer/ChatContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ChatContainerProps {
1616

1717
export const ChatContainer: React.FC<ChatContainerProps> = ({ isHidden }) => {
1818
const { startCall } = useChat();
19-
const [isStartingCall, setIsStartingCall] = useState<boolean>(false);
19+
const [, setIsStartingCall] = useState<boolean>(false);
2020

2121
const handleStartCall = async () => {
2222
try {

client/src/components/ChatContainer/ChatFooter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const ChatFooter: React.FC = () => {
4747
placeholder="Type a secure message..."
4848
value={message}
4949
onChange={(e) => setMessage(e.target.value)}
50-
onKeyPress={handleKeyPress}
50+
onKeyDown={handleKeyPress}
5151
disabled={isSending}
5252
/>
5353
<Button

client/src/components/SetupOverlay/CreateHashView.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import './CreateHashView.css';
1010

1111
interface CreateHashViewProps {
1212
hash: string;
13-
onHashGenerated: (hash: string) => void;
1413
onCopyClick: () => void;
1514
onBack: () => void;
1615
onNext: () => void;
1716
}
1817

1918
export const CreateHashView: React.FC<CreateHashViewProps> = ({
2019
hash,
21-
onHashGenerated,
2220
onCopyClick,
2321
onBack,
2422
onNext,

client/src/components/SetupOverlay/SetupOverlay.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Main SetupOverlay component
33
*/
44

5-
import React, { useState, useEffect } from 'react';
5+
import React, { useState, useEffect, useCallback } from 'react';
66
import { useChat } from '../../context/ChatContext';
77
import { InitialActions } from './InitialActions';
88
import { CreateHashView } from './CreateHashView';
@@ -22,16 +22,10 @@ export const SetupOverlay: React.FC<SetupOverlayProps> = ({ onSetupComplete, isH
2222
const [generatedHash, setGeneratedHash] = useState<string>('');
2323
const [joinHash, setJoinHash] = useState<string>('');
2424
const [status, setStatus] = useState<string>('');
25-
const [isLoading, setIsLoading] = useState<boolean>(false);
25+
const [, setIsLoading] = useState<boolean>(false);
2626

2727
// Generate hash when entering create view
28-
useEffect(() => {
29-
if (view === 'create' && !generatedHash) {
30-
generateHash();
31-
}
32-
}, [view]); // eslint-disable-line react-hooks/exhaustive-deps
33-
34-
const generateHash = async () => {
28+
const generateHash = useCallback(async () => {
3529
try {
3630
setStatus('Generating secure hash...');
3731
const hash = await createNewChannel();
@@ -41,7 +35,13 @@ export const SetupOverlay: React.FC<SetupOverlayProps> = ({ onSetupComplete, isH
4135
setStatus('Failed to generate hash. Please try again.');
4236
console.error('Hash generation error:', err);
4337
}
44-
};
38+
}, [createNewChannel]);
39+
40+
useEffect(() => {
41+
if (view === 'create' && !generatedHash) {
42+
generateHash();
43+
}
44+
}, [view, generatedHash, generateHash]);
4545

4646
const handleCreateClick = () => {
4747
setView('create');
@@ -112,7 +112,6 @@ export const SetupOverlay: React.FC<SetupOverlayProps> = ({ onSetupComplete, isH
112112
{view === 'create' && (
113113
<CreateHashView
114114
hash={generatedHash}
115-
onHashGenerated={setGeneratedHash}
116115
onCopyClick={handleCopyHash}
117116
onBack={handleBack}
118117
onNext={handleCreateNext}

client/src/context/ChatContext.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
* No modifications to the service itself
44
*/
55

6-
import React, { createContext, useContext, ReactNode, useState, useEffect, useCallback } from 'react';
6+
import React, { createContext, useContext, ReactNode, useState, useCallback } from 'react';
77
import { createChatInstance, utils } from '@chat-e2ee/service';
8-
import { ChatContextType, ChatInstance, Message } from '../types/index';
8+
import type { IChatE2EE, IE2ECall } from '@chat-e2ee/service';
9+
import { ChatContextType, Message } from '../types/index';
910
import { createMessage } from '../utils/messageHandling';
1011
import { playBeep } from '../utils/audioNotification';
1112

1213
const ChatContext = createContext<ChatContextType | undefined>(undefined);
1314

1415
export const ChatProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
15-
const [chat, setChat] = useState<ChatInstance | null>(null);
16+
const [chat, setChat] = useState<IChatE2EE | null>(null);
1617
const [userId, setUserId] = useState<string>('');
1718
const [channelHash, setChannelHash] = useState<string>('');
1819
const [privateKey, setPrivateKey] = useState<string>('');
@@ -60,12 +61,13 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
6061
const newUserId = (utils as any).generateUUID();
6162
setUserId(newUserId);
6263

63-
await chat.setChannel(hash, newUserId);
64+
// setChannel returns void but has async operations inside
65+
chat.setChannel(hash, newUserId);
6466
setChannelHash(hash);
6567
setIsConnected(true);
6668

6769
// Setup listeners
68-
setupChatListeners(chat, newUserId);
70+
setupChatListeners(chat);
6971

7072
// Check for existing users
7173
await checkExistingUsers(chat);
@@ -84,7 +86,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
8486
try {
8587
const message = createMessage(userId, text, 'sent');
8688
addMessage(message);
87-
await chat.encrypt({ text }).send();
89+
await chat.encrypt({ text, image: '' }).send();
8890
} catch (err) {
8991
console.error('Failed to send message:', err);
9092
throw err;
@@ -108,17 +110,24 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
108110

109111
// End call
110112
const endCall = useCallback(async () => {
111-
setCallActive(false);
112-
setCallDuration(0);
113-
}, []);
113+
try {
114+
if (chat) {
115+
chat.endCall();
116+
}
117+
setCallActive(false);
118+
setCallDuration(0);
119+
} catch (err) {
120+
console.error('Failed to end call:', err);
121+
}
122+
}, [chat]);
114123

115124
// Add message to state
116125
const addMessage = useCallback((message: Message) => {
117126
setMessages((prev) => [...prev, message]);
118127
}, []);
119128

120129
// Setup chat listeners
121-
const setupChatListeners = (chatInstance: ChatInstance, currentUserId: string) => {
130+
const setupChatListeners = (chatInstance: IChatE2EE) => {
122131
chatInstance.on('on-alice-join', () => {
123132
playBeep();
124133
setIsConnected(true);
@@ -138,16 +147,17 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
138147
}
139148
});
140149

141-
chatInstance.on('call-added', (call: any) => {
150+
chatInstance.on('call-added', (call: IE2ECall) => {
142151
setCallActive(true);
143152
setCallStatus('Incoming Call...');
144153
setupCallListeners(call);
145154
});
146155
};
147156

148157
// Setup call listeners
149-
const setupCallListeners = (call: any) => {
150-
call.on('state-changed', (state: string) => {
158+
const setupCallListeners = (call: IE2ECall) => {
159+
call.on('state-changed', async () => {
160+
const state = call.state;
151161
setCallStatus(state.charAt(0).toUpperCase() + state.slice(1));
152162

153163
if (state === 'closed' || state === 'failed') {
@@ -159,7 +169,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
159169
};
160170

161171
// Check for existing users
162-
const checkExistingUsers = async (chatInstance: ChatInstance) => {
172+
const checkExistingUsers = async (chatInstance: IChatE2EE) => {
163173
try {
164174
const users = await chatInstance.getUsersInChannel();
165175
if (users && users.length > 1) {

client/src/hooks/useUrlHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import { useEffect, useState } from 'react';
6-
import { getUrlHash, updateUrlHash, hasValidHash } from '../utils/callTimer';
6+
import { getUrlHash, updateUrlHash, hasValidHash } from '../utils/urlHash';
77

88
export const useUrlHash = () => {
99
const [hash, setHash] = useState<string>('');

client/src/types/index.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22
* Type definitions for Chat E2EE application
33
*/
44

5-
// Chat instance type from @chat-e2ee/service
6-
export interface ChatInstance {
7-
init: () => Promise<void>;
8-
getKeyPair: () => { privateKey: string; publicKey: string };
9-
getLink: () => Promise<{ hash: string }>;
10-
setChannel: (hash: string, userId: string) => Promise<void>;
11-
getUsersInChannel: () => Promise<any[]>;
12-
startCall: () => Promise<Call>;
13-
on: (event: string, callback: Function) => void;
14-
encrypt: (data: { text: string }) => { send: () => Promise<void> };
15-
}
5+
import type { IChatE2EE } from '@chat-e2ee/service';
166

177
// Message type
188
export interface Message {
@@ -22,19 +12,12 @@ export interface Message {
2212
timestamp: Date;
2313
}
2414

25-
// Call type
26-
export interface Call {
27-
on: (event: string, callback: Function) => void;
28-
endCall: () => Promise<void>;
29-
state?: string;
30-
}
31-
3215
// Setup view states
3316
export type SetupView = 'initial' | 'create' | 'join';
3417

3518
// Chat app state
3619
export interface AppState {
37-
chat: ChatInstance | null;
20+
chat: IChatE2EE | null;
3821
userId: string;
3922
channelHash: string;
4023
privateKey: string;
@@ -47,7 +30,7 @@ export interface AppState {
4730
// Chat context type
4831
export interface ChatContextType {
4932
// State
50-
chat: ChatInstance | null;
33+
chat: IChatE2EE | null;
5134
userId: string;
5235
channelHash: string;
5336
privateKey: string;
@@ -69,16 +52,12 @@ export interface ChatContextType {
6952
}
7053

7154
// Common component props
72-
export interface ButtonProps {
55+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
7356
variant?: 'primary' | 'secondary' | 'danger';
74-
size?: 'small' | 'large';
75-
onClick: () => void;
76-
disabled?: boolean;
57+
size?: 'tiny' | 'small' | 'medium' | 'large';
7758
icon?: boolean;
7859
circle?: boolean;
7960
children: React.ReactNode;
80-
className?: string;
81-
title?: string;
8261
}
8362

8463
export interface InputProps {

client/src/utils/urlHash.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* URL hash handling utilities
3+
*/
4+
5+
/**
6+
* Extract hash from current URL
7+
*/
8+
export function getUrlHash(): string {
9+
return window.location.hash.replace('#', '');
10+
}
11+
12+
/**
13+
* Update URL with hash
14+
*/
15+
export function updateUrlHash(hash: string): void {
16+
if (hash) {
17+
window.location.hash = hash;
18+
}
19+
}
20+
21+
/**
22+
* Check if URL contains a valid hash
23+
*/
24+
export function hasValidHash(): boolean {
25+
const hash = getUrlHash();
26+
return hash.length > 5;
27+
}

0 commit comments

Comments
 (0)