Skip to content

Commit ec69c69

Browse files
committed
hotfix
1 parent e18110a commit ec69c69

File tree

15 files changed

+232
-78
lines changed

15 files changed

+232
-78
lines changed

client/package-lock.json

Lines changed: 26 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/hooks/tasks/useTaskFilters.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { useMemo } from "react";
22
import { useTasks } from "./useTasks";
33
import { useLists } from "@/hooks/useLists";
44

5-
export function useTaskFilters() {
5+
type ListMode = "owned" | "shared" | "all";
6+
7+
export function useTaskFilters(listMode: ListMode = "all") {
68
const {
79
accessibleTasks,
810
filteredTasks,
@@ -15,19 +17,31 @@ export function useTaskFilters() {
1517
toggleSort,
1618
sorting,
1719
} = useTasks();
18-
const { accessibleLists } = useLists();
20+
const { accessibleLists, ownedLists, sharedLists } = useLists();
21+
22+
const listsToUse = useMemo(() => {
23+
switch (listMode) {
24+
case "owned":
25+
return ownedLists;
26+
case "shared":
27+
return sharedLists;
28+
case "all":
29+
default:
30+
return accessibleLists;
31+
}
32+
}, [listMode, ownedLists, sharedLists, accessibleLists]);
1933

2034
const selectedListId = filters.listId;
2135
const listTaskCounts = useMemo(
2236
() =>
23-
accessibleLists.map((list) => ({
37+
listsToUse.map((list) => ({
2438
id: list.id,
2539
name: list.name,
2640
count: accessibleTasks.filter((task) => task.listId === list.id).length,
2741
description: list.description,
2842
owner: list.owner,
2943
})),
30-
[accessibleLists, accessibleTasks],
44+
[listsToUse, accessibleTasks],
3145
);
3246

3347
const handleListFilter = (listId: string | null) => {
@@ -46,6 +60,6 @@ export function useTaskFilters() {
4660
sortBy,
4761
toggleSort,
4862
sorting,
49-
accessibleLists,
63+
accessibleLists: listsToUse,
5064
};
5165
}

client/src/hooks/useSocket.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
taskAdded,
66
taskUpdated,
77
taskDeleted,
8+
tasksDeletedByList,
89
} from "../store/slices/tasksSlice";
910
import {
1011
listUpdated,
@@ -39,6 +40,14 @@ export const useSocket = () => {
3940
dispatch(taskDeleted(taskId));
4041
});
4142

43+
socket.on("task:shared", (task: Task) => {
44+
dispatch(taskAdded(task));
45+
});
46+
47+
socket.on("task:unshared", (taskId: string) => {
48+
dispatch(taskDeleted(taskId));
49+
});
50+
4251
socket.on("list:updated", (list: List) => {
4352
dispatch(listUpdated(list));
4453
});
@@ -53,9 +62,15 @@ export const useSocket = () => {
5362

5463
socket.on("list:shared", (list: List) => {
5564
dispatch(listCreated(list));
65+
if (list.tasks && Array.isArray(list.tasks)) {
66+
for (const task of list.tasks) {
67+
dispatch(taskAdded(task));
68+
}
69+
}
5670
});
5771

5872
socket.on("list:unshared", (listId: string) => {
73+
dispatch(tasksDeletedByList(listId));
5974
dispatch(listDeleted(listId));
6075
});
6176

@@ -69,6 +84,8 @@ export const useSocket = () => {
6984
socket.off("task:created");
7085
socket.off("task:updated");
7186
socket.off("task:deleted");
87+
socket.off("task:shared");
88+
socket.off("task:unshared");
7289
socket.off("list:updated");
7390
socket.off("list:created");
7491
socket.off("list:deleted");

client/src/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@
313313
"sharedBy": "Shared by: {{name}} ({{email}})",
314314
"errorShareTask": "Error sharing the task. Check the email.",
315315
"errorShareList": "Error sharing the list. Check the email.",
316+
"leaveConfirmation": "Are you sure you want to leave the task \"{{name}}\"? You will no longer have access to it.",
317+
"leaveListConfirmation": "Are you sure you want to leave this list? You will no longer have access to it or its tasks.",
316318
"removeCollaborator": {
317319
"title": "Are you sure?",
318320
"descriptionTask": "This action will remove the collaborator from the task.",
@@ -412,4 +414,4 @@
412414
"share": "Share",
413415
"leave": "Leave"
414416
}
415-
}
417+
}

client/src/locales/es.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@
313313
"sharedBy": "Compartido por: {{name}} ({{email}})",
314314
"errorShareTask": "Error al compartir la tarea. Verifica el email.",
315315
"errorShareList": "Error al compartir la lista. Verifica el email.",
316+
"leaveConfirmation": "¿Estás seguro de que quieres salir de la tarea \"{{name}}\"? Ya no tendrás acceso a ella.",
317+
"leaveListConfirmation": "¿Estás seguro de que quieres salir de esta lista? Ya no tendrás acceso a ella ni a sus tareas.",
316318
"removeCollaborator": {
317319
"title": "¿Estás seguro?",
318320
"descriptionTask": "Esta acción eliminará al colaborador de la tarea.",
@@ -415,4 +417,4 @@
415417
"accessibility": {
416418
"close": "Cerrar"
417419
}
418-
}
420+
}

client/src/pages/authenticated/sharedPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function SharedPage() {
2222
sortBy,
2323
toggleSort,
2424
sorting,
25-
} = useTaskFilters();
25+
} = useTaskFilters("shared");
2626

2727
const { fetchSharedTasks, isLoading } = useTasks();
2828
const {

client/src/pages/authenticated/tasksPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function TasksPage() {
2323
sortBy,
2424
toggleSort,
2525
sorting,
26-
} = useTaskFilters();
26+
} = useTaskFilters("owned");
2727

2828
const { fetchAllTasks, isLoading } = useTasks();
2929
const { fetchAllLists, isLoading: isLoadingLists } = useLists();

0 commit comments

Comments
 (0)