Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rooms fixed #310

Closed
wants to merge 18 commits into from
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
congifKey.ts



# Logs
Expand Down Expand Up @@ -43,3 +43,5 @@ firebase-debug.log
firebase-debug.log*
./firestore.indexes.json
firestore.rules

src/controllers/db/configKey.ts
14 changes: 13 additions & 1 deletion firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ service cloud.firestore {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null;
}

match /rooms/{roomId=**}{
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null;
}
match /participants/{participantId=**}{
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null;
}
match /roomsSettings/{roomSettingsId=**}{
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null;
}

match /timers-rooms/{timerIdx=**}{
allow read: if request.auth.uid != null;
allow write: if request.auth.uid != null;
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@dagrejs/dagre": "^1.0.4",
"@reduxjs/toolkit": "^1.9.5",
"delib-npm": "^1.3.35",
"delib-npm": "^1.3.44",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-sonarjs": "^1.0.3",
"firebase": "^10.0.0",
Expand Down
Binary file added src/assets/images/roomImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 0 additions & 35 deletions src/controllers/db/configKey.ts

This file was deleted.

96 changes: 42 additions & 54 deletions src/controllers/db/rooms/getRooms.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,80 @@
import {
Collections,
Participant,
Statement,
StatementSchema,
StatementType,
ParticipantInRoom,
RoomSettings,
Statement
} from 'delib-npm';
import {
and,
collection,
doc,
onSnapshot,
or,
query,
where,
} from 'firebase/firestore';
import { DB } from '../config';
import { setRoomRequests } from '@/model/rooms/roomsSlice';
import { deleteRoom, setRoom, setRooms, setRoomSettings } from '@/model/rooms/roomsSlice';
import { Unsubscribe } from 'firebase/auth';
import { AppDispatch } from '@/model/store';
import { store } from '@/model/store';

export function listenToAllRoomsRequest(

export function listenToParticipants(
statement: Statement,
dispatch: AppDispatch
): Unsubscribe {
try {
const requestRef = collection(DB, Collections.statementRoomsAsked);
const q = query(requestRef, where('parentId', '==', statement.statementId));
const dispatch = store.dispatch;
const requestRef = collection(DB, Collections.participants);
const q = query(requestRef, where('statement.parentId', '==', statement.statementId));

return onSnapshot(q, (requestsDB) => {
return onSnapshot(q, (roomsDB) => {
try {
const requests = requestsDB.docs.map(
(requestDB) => requestDB.data() as Participant
);
roomsDB.docChanges().forEach((change) => {

const room = change.doc.data() as ParticipantInRoom;

switch (change.type) {
case 'added':
dispatch(setRoom(room));
break;
case 'modified':
dispatch(setRoom(room));
break;
case 'removed':
dispatch(deleteRoom(room));
break;
default:
break;
}
});

dispatch(setRoomRequests(requests));
} catch (error) {
console.error(error);
dispatch(setRoomRequests([]));
dispatch(setRooms([]));
}
});
} catch (error) {
console.error(error);

// eslint-disable-next-line @typescript-eslint/no-empty-function
return () => {};
return () => { };
}
}

// TODO: this function is not used. Delete it?
export function listenToRoomSolutions(
statementId: string,
cb: (rooms: Statement | null) => void
) {
try {
const statementSolutionsRef = collection(DB, Collections.statements);
const q = query(
statementSolutionsRef,
and(
where('parentId', '==', statementId),
or(
where('statementType', '==', StatementType.option),
where('statementType', '==', StatementType.result)
)
)
);

return onSnapshot(q, (roomSolutionsDB) => {
try {
roomSolutionsDB.forEach((roomSolutionDB) => {
try {
const roomSolution = roomSolutionDB.data() as Statement;
const { success } = StatementSchema.safeParse(roomSolution);

if (!success)
throw new Error(
'roomSolution is not valid in listenToRoomSolutions()'
);
export function listenToRoomsSettings(statementId: string): Unsubscribe {
try {
const roomSettingRef = doc(DB, Collections.roomsSettings, statementId);

cb(roomSolution);
} catch (error) {
console.error(error);
}
});
} catch (error) {
console.error(error);
cb(null);
}
return onSnapshot(roomSettingRef, (doc) => {
if (!doc.exists()) return;
const roomSettings = doc.data() as RoomSettings;
store.dispatch(setRoomSettings(roomSettings));
});
} catch (error) {
console.error(error);

// eslint-disable-next-line @typescript-eslint/no-empty-function
return () => { };
}
}
Loading
Loading