Skip to content

Commit

Permalink
Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Jun 11, 2024
1 parent 5d872dc commit 0e242c5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface SocketCommunication {
disconnect: ConnectionType;
}

const socket = io(SERVER_URL);
const socket = io(SERVER_URL, { autoConnect: false });
const OPERATION_DELAY = 100;
const operationEmitter = new OperationEmitter(socket, OPERATION_DELAY);

Expand Down
9 changes: 3 additions & 6 deletions code/client/src/ui/contexts/auth/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function AuthProvider({ children }: AuthProviderProps) {
try {
return await action();
} catch (e) {
console.log(e);
publishError(e as Error);
}
};
Expand All @@ -67,11 +66,9 @@ export function AuthProvider({ children }: AuthProviderProps) {

const login = (email: string, password: string) =>
handleAsyncAction(async () => {
return signInWithEmailAndPassword(auth, email, password)
.catch(() => {
throw new Error('Invalid credentials');
})
.then(console.log);
return signInWithEmailAndPassword(auth, email, password).catch(() => {
throw new Error('Invalid credentials');
});
});

const logout = () => handleAsyncAction(() => signOut(auth));
Expand Down
2 changes: 2 additions & 0 deletions code/client/src/ui/contexts/workspace/WorkspaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ export function WorkspaceProvider({ children }: { children: React.ReactNode }) {
setWorkspace(workspace);
setResources(resources);
}
socket.connect();
socket.emit('joinWorkspace', wid);
fetchWorkspace().catch(publishError);
return () => {
socket.emit('leaveWorkspace');
socket.disconnect();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [wid, services, socket, publishError]);
Expand Down
7 changes: 1 addition & 6 deletions code/client/src/ui/pages/auth/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function Login() {

useEffect(() => {
if (currentUser) {
console.log('currentUser', currentUser);
navigate('/');
}
}, [currentUser, navigate]);
Expand All @@ -35,12 +34,8 @@ function Login() {
const data = new FormData(e.currentTarget);
const email = data.get('email') as string;
const password = data.get('password') as string;
console.log('login', email, password);
const result = await login(email, password);
console.log('result', result);
// navigate('/');
await login(email, password);
} catch (e) {
console.error(e);
publishError(Error('Failed to login'));
}

Expand Down
4 changes: 2 additions & 2 deletions code/client/src/ui/pages/auth/signup/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ function Signup() {

try {
const data = new FormData(e.currentTarget);
const username = data.get('username') as string;
const email = data.get('email') as string;
const password = data.get('password') as string;
const confirmPassword = data.get('confirmPassword') as string;
if (password !== confirmPassword) {
publishError(Error('Passwords do not match'));
return;
}
const result = await signup(email, password);
console.log('result', result);
await signup(username, email, password);
navigate('/login');
} catch (e) {
console.error(e);
Expand Down
8 changes: 7 additions & 1 deletion code/client/src/ui/pages/workspaces/Workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ import { MdDelete } from 'react-icons/md';
import { useEffect, useState } from 'react';
import { sortWorkspaces } from '@domain/workspaces/utils';
import './Workspaces.scss';
import { useCommunication } from '@ui/contexts/communication/useCommunication';

function Workspaces() {
const { workspaces, operations } = useWorkspaces();
const { publishError } = useError();
const [selected, setSelected] = useState<string[]>([]);
const [rows, setRows] = useState(workspaces);
const { socket } = useCommunication();

useEffect(() => {
socket.connect();
setRows(workspaces);
}, [workspaces]);
return () => {
socket.disconnect();
};
}, [socket, workspaces]);

return (
<div className="workspaces">
Expand Down
8 changes: 4 additions & 4 deletions code/server/src/databases/postgres/PostgresUsersDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { NotFoundError } from '@domain/errors/errors';

export class PostgresUsersDB implements UsersRepository {
async createUser(id: string, data: UserData): Promise<void> {
await sql`insert into users ${sql({ id, ...data })}`;
await sql`insert into "user" ${sql({ id, ...data })}`;
}

async getUser(id: string): Promise<UserData> {
const results: UserData[] = await sql`select * from users where id = ${id}`;
const results: UserData[] = await sql`select * from "user" where id = ${id}`;
if (isEmpty(results)) throw new NotFoundError('User not found');
return results[0];
}

async updateUser(id: string, newProps: Partial<UserData>): Promise<void> {
const results = await sql`
update users
update "user"
set ${sql(newProps)}
where id = ${id}
returning id
Expand All @@ -27,7 +27,7 @@ export class PostgresUsersDB implements UsersRepository {

async deleteUser(id: string): Promise<void> {
const results = await sql`
delete from users
delete from "user"
where id = ${id}
returning id
`;
Expand Down

0 comments on commit 0e242c5

Please sign in to comment.