Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: adding loading state for projects, sync ws when creating new tasks

Andrej3977931ae07d
diff --git a/apps/api/src/task/controllers/get-tasks.ts b/apps/api/src/task/controllers/get-tasks.ts
index 4a0991a9e..ac0683bf5 100644
--- a/apps/api/src/task/controllers/get-tasks.ts
+++ b/apps/api/src/task/controllers/get-tasks.ts
@@ -33,7 +33,7 @@ async function getTasks(projectId: string) {
assigneeEmail: userTable.email,
})
.from(taskTable)
- .leftJoin(userTable, eq(taskTable.userEmail, userTable.id))
+ .leftJoin(userTable, eq(taskTable.userEmail, userTable.email))
.where(eq(taskTable.projectId, projectId));
const columns = DEFAULT_COLUMNS.map((column) => ({
diff --git a/apps/api/src/task/controllers/update-task-status.ts b/apps/api/src/task/controllers/update-task-status.ts
index 365eded98..3fb5ba3ff 100644
--- a/apps/api/src/task/controllers/update-task-status.ts
+++ b/apps/api/src/task/controllers/update-task-status.ts
@@ -5,10 +5,11 @@ import { taskTable } from "../../database/schema";
async function updateTaskStatus({
id,
status,
-}: { id: string; status: string }) {
+ userEmail,
+}: { id: string; status: string; userEmail: string }) {
await db
.update(taskTable)
- .set({ status: status })
+ .set({ status, userEmail })
.where(eq(taskTable.id, id));
}
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index 791444556..df024c9a4 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -45,16 +45,18 @@ const task = new Elysia({ prefix: "/task" })
type: string;
id: string;
status: string;
+ userEmail: string;
},
) {
const projectId = ws.data.params.projectId;
- const { type, id, status } = message;
+ const { type, id, status, userEmail } = message;
if (type === "UPDATE_TASK") {
await updateTaskStatus({
id,
status,
+ userEmail,
});
const clients = connections.get(projectId);
diff --git a/apps/web/src/components/common/sidebar/sections/projects/index.tsx b/apps/web/src/components/common/sidebar/sections/projects/index.tsx
index 8a19387a0..02c733bd0 100644
--- a/apps/web/src/components/common/sidebar/sections/projects/index.tsx
+++ b/apps/web/src/components/common/sidebar/sections/projects/index.tsx
@@ -14,7 +14,7 @@ type ProjectsProps = {
function Projects({ workspaceId }: ProjectsProps) {
const { project: currentProject, setProject } = useProjectStore();
- const { data: projects } = useGetProjects({ workspaceId });
+ const { data: projects, isLoading } = useGetProjects({ workspaceId });
const [isCreateProjectOpen, setIsCreateProjectOpen] = useState(false);
const { isSidebarOpened } = useUserPreferencesStore();
const navigate = useNavigate();
@@ -32,6 +32,22 @@ function Projects({ workspaceId }: ProjectsProps) {
});
};
+ if (isLoading) {
+ return (
+ <div className="space-y-1 w-full">
+ {[1, 2, 3].map((i) => (
+ <div
+ key={i}
+ className="animate-pulse flex items-center px-4 py-1.5 rounded-md"
+ >
+ <div className="h-4 shrink-0 w-4 bg-zinc-200 dark:bg-zinc-800 rounded mr-2" />
+ <div className="h-4 w-full bg-zinc-200 dark:bg-zinc-800 rounded" />
+ </div>
+ ))}
+ </div>
+ );
+ }
+
return (
<div>
<div
diff --git a/apps/web/src/components/task/create-task-modal.tsx b/apps/web/src/components/task/create-task-modal.tsx
index d12975530..a73d75a54 100644
--- a/apps/web/src/components/task/create-task-modal.tsx
+++ b/apps/web/src/components/task/create-task-modal.tsx
@@ -10,6 +10,7 @@ import {
import { Input } from "@/components/ui/input";
import useCreateTask from "@/hooks/mutations/task/use-create-task";
import useGetWorkspaceUsers from "@/hooks/queries/workspace-users/use-get-workspace-users";
+import useBoardWebSocket from "@/hooks/use-board-websocket";
import useProjectStore from "@/store/project";
import useWorkspaceStore from "@/store/workspace";
import { zodResolver } from "@hookform/resolvers/zod";
@@ -45,6 +46,7 @@ export function CreateTaskModal({
const { data: users } = useGetWorkspaceUsers({
workspaceId: workspace?.id ?? "",
});
+ const { ws } = useBoardWebSocket();
const form = useForm<TaskFormValues>({
resolver: zodResolver(taskSchema),
@@ -60,6 +62,8 @@ export function CreateTaskModal({
const onSubmit = async (data: TaskFormValues) => {
if (!project?.id || !workspace?.id) return;
+ console.log(data?.email);
+
const newTask = await mutateAsync({
title: data.title.trim(),
description: data.description?.trim() || "",
@@ -80,6 +84,7 @@ export function CreateTaskModal({
});
setProject(updatedProject);
+ ws?.send(JSON.stringify({ type: "UPDATE_TASK", ...newTask }));
form.reset();
onClose();
diff --git a/apps/web/src/components/team/invite-team-member-modal.tsx b/apps/web/src/components/team/invite-team-member-modal.tsx
index a29d6ce32..4c73275f9 100644
--- a/apps/web/src/components/team/invite-team-member-modal.tsx
+++ b/apps/web/src/components/team/invite-team-member-modal.tsx
@@ -2,6 +2,7 @@ import useInviteWorkspaceUser from "@/hooks/mutations/workspace-user/use-invite-
import { Route } from "@/routes/dashboard/workspace/$workspaceId/team";
import { zodResolver } from "@hookform/resolvers/zod";
import * as Dialog from "@radix-ui/react-dialog";
+import { useQueryClient } from "@tanstack/react-query";
import { X } from "lucide-react";
import { useForm } from "react-hook-form";
import { z } from "zod";
@@ -29,6 +30,7 @@ type TeamMemberFormValues = z.infer<typeof teamMemberSchema>;
function InviteTeamMemberModal({ open, onClose }: Props) {
const { mutateAsync } = useInviteWorkspaceUser();
+ const queryClient = useQueryClient();
const { workspaceId } = Route.useParams();
const form = useForm<TeamMemberFormValues>({
@@ -40,6 +42,9 @@ function InviteTeamMemberModal({ open, onClose }: Props) {
const onSubmit = async ({ userEmail }: TeamMemberFormValues) => {
await mutateAsync({ userEmail, workspaceId });
+ await queryClient.refetchQueries({
+ queryKey: ["pending-workspace-users", workspaceId],
+ });
form.reset();
onClose();
diff --git a/apps/web/src/hooks/use-board-websocket.ts b/apps/web/src/hooks/use-board-websocket.ts
index 241e01c5b..403a3440c 100644
--- a/apps/web/src/hooks/use-board-websocket.ts
+++ b/apps/web/src/hooks/use-board-websocket.ts
@@ -1,4 +1,5 @@
import { API_URL } from "@/constants/urls";
+import { Route } from "@/routes/dashboard/workspace/$workspaceId/project/$projectId";
import useProjectStore from "@/store/project";
import { useEffect, useRef } from "react";
@@ -8,12 +9,13 @@ type WebSocketHook = {
function useBoardWebSocket(): WebSocketHook {
const wsRef = useRef<WebSocket | null>(null);
- const { project, setProject } = useProjectStore();
+ const { projectId } = Route.useParams();
+ const { setProject } = useProjectStore();
useEffect(() => {
- if (!project?.id) return;
+ if (!projectId) return;
- const socket = new WebSocket(`${API_URL}/task/ws/${project.id}`);
+ const socket = new WebSocket(`${API_URL}/task/ws/${projectId}`);
socket.onmessage = (event) => {
try {
@@ -30,7 +32,7 @@ function useBoardWebSocket(): WebSocketHook {
socket.close();
wsRef.current = null;
};
- }, [project?.id, setProject]);
+ }, [projectId, setProject]);
return {
ws: wsRef.current,
diff --git a/bun.lockb b/bun.lockb
index ef70ac30f..a4e57eeeb 100755
Binary files a/bun.lockb and b/bun.lockb differ