refactored modals, added unread messages when user is not on page,

This commit is contained in:
slawk0
2025-01-07 18:30:09 +01:00
parent 1f7aedb0ca
commit dc1e5c1748
15 changed files with 715 additions and 318 deletions

382
client/package-lock.json generated
View File

@@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"@radix-ui/react-alert-dialog": "^1.1.2", "@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-context-menu": "^2.2.3", "@radix-ui/react-context-menu": "^2.2.3",
"@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.4", "@radix-ui/react-tooltip": "^1.1.4",
@@ -1152,6 +1152,67 @@
} }
} }
}, },
"node_modules/@radix-ui/react-alert-dialog/node_modules/@radix-ui/react-dialog": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.2.tgz",
"integrity": "sha512-Yj4dZtqa2o+kG61fzB0H2qUvmwBA2oyQroGLyNtBj1beo1khoQ3q1a2AO8rrQYjd8256CO9+N8L9tvsS+bnIyA==",
"license": "MIT",
"dependencies": {
"@radix-ui/primitive": "1.1.0",
"@radix-ui/react-compose-refs": "1.1.0",
"@radix-ui/react-context": "1.1.1",
"@radix-ui/react-dismissable-layer": "1.1.1",
"@radix-ui/react-focus-guards": "1.1.1",
"@radix-ui/react-focus-scope": "1.1.0",
"@radix-ui/react-id": "1.1.0",
"@radix-ui/react-portal": "1.1.2",
"@radix-ui/react-presence": "1.1.1",
"@radix-ui/react-primitive": "2.0.0",
"@radix-ui/react-slot": "1.1.0",
"@radix-ui/react-use-controllable-state": "1.1.0",
"aria-hidden": "^1.1.1",
"react-remove-scroll": "2.6.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-alert-dialog/node_modules/@radix-ui/react-focus-scope": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.0.tgz",
"integrity": "sha512-200UD8zylvEyL8Bx+z76RJnASR2gRMuxlgFCPAe/Q/679a/r0eK3MBVYMb7vZODZcffZBdob1EGnky78xmVvcA==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.0",
"@radix-ui/react-primitive": "2.0.0",
"@radix-ui/react-use-callback-ref": "1.1.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-arrow": { "node_modules/@radix-ui/react-arrow": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.1.0.tgz",
@@ -1378,25 +1439,25 @@
} }
}, },
"node_modules/@radix-ui/react-dialog": { "node_modules/@radix-ui/react-dialog": {
"version": "1.1.2", "version": "1.1.4",
"resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.2.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-dialog/-/react-dialog-1.1.4.tgz",
"integrity": "sha512-Yj4dZtqa2o+kG61fzB0H2qUvmwBA2oyQroGLyNtBj1beo1khoQ3q1a2AO8rrQYjd8256CO9+N8L9tvsS+bnIyA==", "integrity": "sha512-Ur7EV1IwQGCyaAuyDRiOLA5JIUZxELJljF+MbM/2NC0BYwfuRrbpS30BiQBJrVruscgUkieKkqXYDOoByaxIoA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@radix-ui/primitive": "1.1.0", "@radix-ui/primitive": "1.1.1",
"@radix-ui/react-compose-refs": "1.1.0", "@radix-ui/react-compose-refs": "1.1.1",
"@radix-ui/react-context": "1.1.1", "@radix-ui/react-context": "1.1.1",
"@radix-ui/react-dismissable-layer": "1.1.1", "@radix-ui/react-dismissable-layer": "1.1.3",
"@radix-ui/react-focus-guards": "1.1.1", "@radix-ui/react-focus-guards": "1.1.1",
"@radix-ui/react-focus-scope": "1.1.0", "@radix-ui/react-focus-scope": "1.1.1",
"@radix-ui/react-id": "1.1.0", "@radix-ui/react-id": "1.1.0",
"@radix-ui/react-portal": "1.1.2", "@radix-ui/react-portal": "1.1.3",
"@radix-ui/react-presence": "1.1.1", "@radix-ui/react-presence": "1.1.2",
"@radix-ui/react-primitive": "2.0.0", "@radix-ui/react-primitive": "2.0.1",
"@radix-ui/react-slot": "1.1.0", "@radix-ui/react-slot": "1.1.1",
"@radix-ui/react-use-controllable-state": "1.1.0", "@radix-ui/react-use-controllable-state": "1.1.0",
"aria-hidden": "^1.1.1", "aria-hidden": "^1.1.1",
"react-remove-scroll": "2.6.0" "react-remove-scroll": "^2.6.1"
}, },
"peerDependencies": { "peerDependencies": {
"@types/react": "*", "@types/react": "*",
@@ -1413,6 +1474,168 @@
} }
} }
}, },
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/primitive": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.1.tgz",
"integrity": "sha512-SJ31y+Q/zAyShtXJc8x83i9TYdbAfHZ++tUZnvjJJqFjzsdUnKsxPL6IEtBlxKkU7yzer//GQtZSV4GbldL3YA==",
"license": "MIT"
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-compose-refs": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.1.tgz",
"integrity": "sha512-Y9VzoRDSJtgFMUCoiZBDVo084VQ5hfpXxVE+NgkdNsjiDBByiImMZKKhxMwCbdHvhlENG6a833CbFkOQvTricw==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-dismissable-layer": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-dismissable-layer/-/react-dismissable-layer-1.1.3.tgz",
"integrity": "sha512-onrWn/72lQoEucDmJnr8uczSNTujT0vJnA/X5+3AkChVPowr8n1yvIKIabhWyMQeMvvmdpsvcyDqx3X1LEXCPg==",
"license": "MIT",
"dependencies": {
"@radix-ui/primitive": "1.1.1",
"@radix-ui/react-compose-refs": "1.1.1",
"@radix-ui/react-primitive": "2.0.1",
"@radix-ui/react-use-callback-ref": "1.1.0",
"@radix-ui/react-use-escape-keydown": "1.1.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-portal": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-portal/-/react-portal-1.1.3.tgz",
"integrity": "sha512-NciRqhXnGojhT93RPyDaMPfLH3ZSl4jjIFbZQ1b/vxvZEdHsBZ49wP9w8L3HzUQwep01LcWtkUvm0OVB5JAHTw==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-primitive": "2.0.1",
"@radix-ui/react-use-layout-effect": "1.1.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-presence": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.2.tgz",
"integrity": "sha512-18TFr80t5EVgL9x1SwF/YGtfG+l0BS0PRAlCWBDoBEiDQjeKgnNZRVJp/oVBl24sr3Gbfwc/Qpj4OcWTQMsAEg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.1",
"@radix-ui/react-use-layout-effect": "1.1.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.0.1.tgz",
"integrity": "sha512-sHCWTtxwNn3L3fH8qAfnF3WbUZycW93SM1j3NFDzXBiz8D6F5UTTy8G1+WFEaiCdvCVRJWj6N2R4Xq6HdiHmDg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-slot": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.1.1.tgz",
"integrity": "sha512-RApLLOcINYJA+dMVbOju7MYv1Mb2EBp2nH4HdDzXTSyaR5optlm6Otrz1euW3HbdOR8UmmFK06TD+A9frYWv+g==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-dialog/node_modules/react-remove-scroll": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.6.2.tgz",
"integrity": "sha512-KmONPx5fnlXYJQqC62Q+lwIeAk64ws/cUw6omIumRzMRPqgnYqhSSti99nbj0Ry13bv7dF+BKn7NB+OqkdZGTw==",
"license": "MIT",
"dependencies": {
"react-remove-scroll-bar": "^2.3.7",
"react-style-singleton": "^2.2.1",
"tslib": "^2.1.0",
"use-callback-ref": "^1.3.3",
"use-sidecar": "^1.1.2"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-direction": { "node_modules/@radix-ui/react-direction": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-direction/-/react-direction-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-direction/-/react-direction-1.1.0.tgz",
@@ -1471,13 +1694,13 @@
} }
}, },
"node_modules/@radix-ui/react-focus-scope": { "node_modules/@radix-ui/react-focus-scope": {
"version": "1.1.0", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.1.tgz",
"integrity": "sha512-200UD8zylvEyL8Bx+z76RJnASR2gRMuxlgFCPAe/Q/679a/r0eK3MBVYMb7vZODZcffZBdob1EGnky78xmVvcA==", "integrity": "sha512-01omzJAYRxXdG2/he/+xy+c8a8gCydoQ1yOxnWNcRhrrBW5W+RQJ22EK1SaO8tb3WoUsuEw7mJjBozPzihDFjA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@radix-ui/react-compose-refs": "1.1.0", "@radix-ui/react-compose-refs": "1.1.1",
"@radix-ui/react-primitive": "2.0.0", "@radix-ui/react-primitive": "2.0.1",
"@radix-ui/react-use-callback-ref": "1.1.0" "@radix-ui/react-use-callback-ref": "1.1.0"
}, },
"peerDependencies": { "peerDependencies": {
@@ -1495,6 +1718,62 @@
} }
} }
}, },
"node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-compose-refs": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.1.tgz",
"integrity": "sha512-Y9VzoRDSJtgFMUCoiZBDVo084VQ5hfpXxVE+NgkdNsjiDBByiImMZKKhxMwCbdHvhlENG6a833CbFkOQvTricw==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-primitive": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.0.1.tgz",
"integrity": "sha512-sHCWTtxwNn3L3fH8qAfnF3WbUZycW93SM1j3NFDzXBiz8D6F5UTTy8G1+WFEaiCdvCVRJWj6N2R4Xq6HdiHmDg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-slot": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-slot": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.1.1.tgz",
"integrity": "sha512-RApLLOcINYJA+dMVbOju7MYv1Mb2EBp2nH4HdDzXTSyaR5optlm6Otrz1euW3HbdOR8UmmFK06TD+A9frYWv+g==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-id": { "node_modules/@radix-ui/react-id": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-id/-/react-id-1.1.0.tgz",
@@ -1624,31 +1903,6 @@
} }
} }
}, },
"node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-focus-scope": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.1.tgz",
"integrity": "sha512-01omzJAYRxXdG2/he/+xy+c8a8gCydoQ1yOxnWNcRhrrBW5W+RQJ22EK1SaO8tb3WoUsuEw7mJjBozPzihDFjA==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.1",
"@radix-ui/react-primitive": "2.0.1",
"@radix-ui/react-use-callback-ref": "1.1.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-popper": { "node_modules/@radix-ui/react-menu/node_modules/@radix-ui/react-popper": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.1.tgz", "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.1.tgz",
@@ -4081,15 +4335,6 @@
"node": ">=0.8.19" "node": ">=0.8.19"
} }
}, },
"node_modules/invariant": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
"integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==",
"license": "MIT",
"dependencies": {
"loose-envify": "^1.0.0"
}
},
"node_modules/is-binary-path": { "node_modules/is-binary-path": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
@@ -4988,20 +5233,20 @@
} }
}, },
"node_modules/react-remove-scroll-bar": { "node_modules/react-remove-scroll-bar": {
"version": "2.3.6", "version": "2.3.8",
"resolved": "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.6.tgz", "resolved": "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.8.tgz",
"integrity": "sha512-DtSYaao4mBmX+HDo5YWYdBWQwYIQQshUV/dVxFxK+KM26Wjwp1gZ6rv6OC3oujI6Bfu6Xyg3TwK533AQutsn/g==", "integrity": "sha512-9r+yi9+mgU33AKcj6IbT9oRCO78WriSj6t/cF8DWBZJ9aOGPOTEDvdUDz1FwKim7QXWwmHqtdHnRJfhAxEG46Q==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"react-style-singleton": "^2.2.1", "react-style-singleton": "^2.2.2",
"tslib": "^2.0.0" "tslib": "^2.0.0"
}, },
"engines": { "engines": {
"node": ">=10" "node": ">=10"
}, },
"peerDependencies": { "peerDependencies": {
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0", "@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"@types/react": { "@types/react": {
@@ -5042,21 +5287,20 @@
} }
}, },
"node_modules/react-style-singleton": { "node_modules/react-style-singleton": {
"version": "2.2.1", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.1.tgz", "resolved": "https://registry.npmjs.org/react-style-singleton/-/react-style-singleton-2.2.3.tgz",
"integrity": "sha512-ZWj0fHEMyWkHzKYUr2Bs/4zU6XLmq9HsgBURm7g5pAVfyn49DgUiNgY2d4lXRlYSiCif9YBGpQleewkcqddc7g==", "integrity": "sha512-b6jSvxvVnyptAiLjbkWLE/lOnR4lfTtDAl+eUC7RZy+QQWc6wRzIV2CE6xBuMmDxc2qIihtDCZD5NPOFl7fRBQ==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"get-nonce": "^1.0.0", "get-nonce": "^1.0.0",
"invariant": "^2.2.4",
"tslib": "^2.0.0" "tslib": "^2.0.0"
}, },
"engines": { "engines": {
"node": ">=10" "node": ">=10"
}, },
"peerDependencies": { "peerDependencies": {
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0", "@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"@types/react": { "@types/react": {
@@ -5658,9 +5902,9 @@
} }
}, },
"node_modules/use-callback-ref": { "node_modules/use-callback-ref": {
"version": "1.3.2", "version": "1.3.3",
"resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.2.tgz", "resolved": "https://registry.npmjs.org/use-callback-ref/-/use-callback-ref-1.3.3.tgz",
"integrity": "sha512-elOQwe6Q8gqZgDA8mrh44qRTQqpIHDcZ3hXTLjBe1i4ph8XpNJnO+aQf3NaG+lriLopI4HMx9VjQLfPQ6vhnoA==", "integrity": "sha512-jQL3lRnocaFtu3V00JToYz/4QkNWswxijDaCVNZRiRTO3HQDLsdu1ZtmIUvV4yPp+rvWm5j0y0TG/S61cuijTg==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.0.0" "tslib": "^2.0.0"
@@ -5669,8 +5913,8 @@
"node": ">=10" "node": ">=10"
}, },
"peerDependencies": { "peerDependencies": {
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0", "@types/react": "*",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"@types/react": { "@types/react": {

View File

@@ -12,7 +12,7 @@
"dependencies": { "dependencies": {
"@radix-ui/react-alert-dialog": "^1.1.2", "@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-context-menu": "^2.2.3", "@radix-ui/react-context-menu": "^2.2.3",
"@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.4", "@radix-ui/react-tooltip": "^1.1.4",

View File

@@ -1,11 +1,12 @@
import { useContext, useEffect, useRef, useState } from 'react'; import { useContext, useEffect, useRef, useState } from 'react';
import { socket } from '@/socket/socket.ts'; import { socket } from '@/socket/socket.ts';
import { sendContact } from '@/api/contactsApi.tsx'; import { sendContact, setContactStatus } from '@/api/contactsApi.tsx';
import LoadingWheel from '../LoadingWheel.tsx'; import LoadingWheel from '../LoadingWheel.tsx';
import AnimatedMessage from '@/components/chat/chatArea/AnimatedMessage.tsx'; import AnimatedMessage from '@/components/chat/chatArea/AnimatedMessage.tsx';
import { ChatMessagesProps } from '@/types/types.ts'; import { ChatMessagesProps } from '@/types/types.ts';
import { useChat } from '@/context/chat/useChat.ts'; import { useChat } from '@/context/chat/useChat.ts';
import { AuthContext } from '@/utils/AuthProvider.tsx'; import { AuthContext } from '@/utils/AuthProvider.tsx';
import { useWindowFocus } from '@/hooks/useWindowFocus.tsx';
function MessagesArea() { function MessagesArea() {
const { const {
@@ -17,12 +18,15 @@ function MessagesArea() {
setContactsList, setContactsList,
errorMessage, errorMessage,
fetchPreviousMessages, fetchPreviousMessages,
setCurrentContact,
} = useChat(); } = useChat();
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const { user } = useContext(AuthContext); const { user } = useContext(AuthContext);
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
const [shouldScrollToBottom, setShouldScrollToBottom] = useState(true); const [shouldScrollToBottom, setShouldScrollToBottom] = useState(true);
const previousMessagesLength = useRef(messages.length); const previousMessagesLength = useRef(messages.length);
const isFocused = useWindowFocus();
const previousTitle = useRef(document.title);
const scrollToBottom = () => { const scrollToBottom = () => {
const container = containerRef.current; const container = containerRef.current;
@@ -80,7 +84,6 @@ function MessagesArea() {
useEffect(() => { useEffect(() => {
if (!socket) return; if (!socket) return;
const currentContainer = containerRef.current; const currentContainer = containerRef.current;
if (currentContainer) { if (currentContainer) {
currentContainer.addEventListener('scroll', handleScroll); currentContainer.addEventListener('scroll', handleScroll);
@@ -88,12 +91,27 @@ function MessagesArea() {
socket.on('chat message', (msg: ChatMessagesProps) => { socket.on('chat message', (msg: ChatMessagesProps) => {
console.log('Received message: ', msg); console.log('Received message: ', msg);
if (
msg.conversation_id !== currentContact?.conversation_id && const isFromCurrentConversation =
msg.sender !== user?.username msg.conversation_id === currentContact?.conversation_id;
) { const isFromCurrentUser = msg.sender === user?.username;
setContactsList((prevContacts) => {
// Find if contact already exists1 if (isFromCurrentConversation) {
messageHandler(msg);
if (!isFocused) {
updateContactStatus(msg.conversation_id, false);
setCurrentContact({ ...currentContact, read: false });
document.title = 'New message ❗';
}
}
// Handle contact list updates
setContactsList((prevContacts) => {
// If message is from another conversation
if (!isFromCurrentConversation && !isFromCurrentUser) {
setContactStatus(msg.conversation_id, false);
// Check if contact exists
const existingContact = prevContacts.find( const existingContact = prevContacts.find(
(c) => c.conversation_id === msg.conversation_id, (c) => c.conversation_id === msg.conversation_id,
); );
@@ -116,65 +134,23 @@ function MessagesArea() {
last_message_time: new Date().toString(), last_message_time: new Date().toString(),
}, },
]; ];
} else {
return prevContacts.map((contact) =>
contact.conversation_id === msg.conversation_id
? {
...contact,
last_active: new Date().toString(),
last_message: msg.message,
last_message_sender: msg.sender,
last_message_time: new Date().toString(),
}
: contact,
);
} }
});
// Update contact status...
} else {
if (msg.conversation_id == currentContact?.conversation_id) {
messageHandler(msg);
setContactsList((prevContacts) => {
const existingContact = prevContacts.find(
(c) => c.conversation_id === msg.conversation_id,
);
if (!existingContact) {
sendContact(msg.sender);
return [
...prevContacts,
{
username: msg.sender,
read: false,
id: msg.message_id,
user_id: msg.sender_id,
conversation_id: msg.conversation_id,
type: 'direct',
last_active: new Date().toString(),
last_message: msg.message,
last_message_id: msg.message_id,
last_message_sender: msg.sender,
last_message_time: new Date().toString(),
},
];
} else {
return prevContacts.map((contact) =>
contact.conversation_id === msg.conversation_id
? {
...contact,
last_active: new Date().toString(),
last_message: msg.message,
last_message_sender: msg.sender,
last_message_time: new Date().toString(),
}
: contact,
);
}
});
} }
}
// Update existing contact if found
return prevContacts.map((contact) =>
contact.conversation_id === msg.conversation_id
? {
...contact,
read: isFromCurrentConversation ? isFocused : false,
last_active: new Date().toString(),
last_message: msg.message,
last_message_sender: msg.sender,
last_message_time: new Date().toString(),
}
: contact,
);
});
}); });
socket.on( socket.on(
@@ -213,7 +189,40 @@ function MessagesArea() {
socket.off('chat message'); socket.off('chat message');
socket.off('delete message'); socket.off('delete message');
}; };
}, [currentContact, user?.username, setContactsList, updateContactStatus]); }, [
currentContact,
user?.username,
setContactsList,
updateContactStatus,
isFocused,
]);
useEffect(() => {
if (isFocused && currentContact?.read == true) {
return;
}
document.title = previousTitle.current;
if (currentContact?.conversation_id && currentContact?.read !== true) {
updateContactStatus(currentContact.conversation_id, true);
setCurrentContact({ ...currentContact, read: true });
}
const timeout = setTimeout(() => {
setContactsList((prevContacts) => {
return prevContacts.map((contact) =>
contact.conversation_id === currentContact?.conversation_id
? {
...contact,
read: true,
}
: contact,
);
});
}, 1000);
return () => clearTimeout(timeout);
}, [isFocused]);
useEffect(() => { useEffect(() => {
const hasNewMessages = messages.length > previousMessagesLength.current; const hasNewMessages = messages.length > previousMessagesLength.current;

View File

@@ -1,12 +1,20 @@
import LoadingWheel from '../LoadingWheel.tsx'; import LoadingWheel from '../LoadingWheel';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useState } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form'; import { SubmitHandler, useForm } from 'react-hook-form';
import { socket } from '@/socket/socket.ts'; import { socket } from '@/socket/socket';
import { UserRoundPlus } from 'lucide-react'; import { UserRoundPlus } from 'lucide-react';
import { Button } from '@/components/ui/button.tsx'; import { Button } from '@/components/ui/button';
import { useChat } from '@/context/chat/useChat.ts'; import { useChat } from '@/context/chat/useChat';
import { axiosClient } from '@/utils/axiosClient.ts'; import { axiosClient } from '@/utils/axiosClient';
import axios from 'axios'; import axios from 'axios';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
type Inputs = { type Inputs = {
username: string; username: string;
@@ -14,8 +22,8 @@ type Inputs = {
function AddGroupMember() { function AddGroupMember() {
const { currentContact } = useChat(); const { currentContact } = useChat();
const [open, setOpen] = useState(false);
const { register, handleSubmit, watch, reset } = useForm<Inputs>(); const { register, handleSubmit, watch, reset } = useForm<Inputs>();
const modalRef = useRef<HTMLDialogElement | null>(null);
const contactInput = watch('username'); const contactInput = watch('username');
const [suggestions, setSuggestions] = useState<string[]>([]); const [suggestions, setSuggestions] = useState<string[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
@@ -66,7 +74,7 @@ function AddGroupMember() {
return () => clearTimeout(delay); return () => clearTimeout(delay);
}, [contactInput]); }, [contactInput]);
if (!socket) return; if (!socket) return null;
const onSubmit: SubmitHandler<Inputs> = async (data) => { const onSubmit: SubmitHandler<Inputs> = async (data) => {
const contactToSubmit = const contactToSubmit =
@@ -86,9 +94,7 @@ function AddGroupMember() {
socket?.emit('added to group', { socket?.emit('added to group', {
group_id: currentContact?.conversation_id, group_id: currentContact?.conversation_id,
}); });
if (modalRef.current) { setOpen(false);
modalRef.current.close();
}
reset(); reset();
} catch (e) { } catch (e) {
if (axios.isAxiosError(e)) { if (axios.isAxiosError(e)) {
@@ -126,92 +132,82 @@ function AddGroupMember() {
}; };
return ( return (
<> <Dialog open={open} onOpenChange={setOpen}>
<div> <DialogTrigger asChild>
<button <button className="p-2 hover:bg-zinc-800 rounded-lg">
className="p-2 hover:bg-zinc-800 rounded-lg"
onClick={() =>
(
document.getElementById('addMemberModal') as HTMLDialogElement
).showModal()
}
>
<UserRoundPlus /> <UserRoundPlus />
</button> </button>
<dialog id="addMemberModal" className="modal" ref={modalRef}> </DialogTrigger>
<div className="modal-box bg-zinc-950 text-center relative p-1 border"> <DialogContent className="bg-zinc-950 text-white sm:max-w-md w-full border">
<div className="absolute right-2 top-2"> <DialogHeader>
<form method="dialog"> <DialogTitle className="text-center text-gray-200">
<button className=" btn btn-sm btn-circle btn-ghost"></button> Enter username
</form> </DialogTitle>
</div> </DialogHeader>
<div className="flex flex-col items-center justify-center space-y-4">
<div className="flex flex-col items-center justify-center pb-1 mt-6"> <form onSubmit={handleSubmit(onSubmit)} className="w-full space-y-2">
<h3 className="text-lg mb-4">Enter username</h3> <div className="relative p-3">
<div className="text-center"> <Input
<form onSubmit={handleSubmit(onSubmit)}> className="bg-gray-100 text-black pl-2 h-10 rounded-lg"
<input type="text"
className="text-black bg-green-50 pl-2 shadow-lg rounded-md h-10 mb-2 mt-2" onKeyDown={handleKeyDown}
type="text" {...register('username', {
onKeyDown={handleKeyDown} minLength: 4,
{...register('username', { maxLength: 20,
minLength: 4, })}
maxLength: 20, />
})} <div className="mt-1">
/> {suggestions?.length > 0 ? (
</form> <ul className="text-left p-2 bg-gray-900 shadow-md rounded-md w-full border">
<div className="m-1"> {suggestions.map((suggestion, index) => (
{suggestions?.length > 0 ? ( <li
<ul className="text-left p-2 bg-gray-900 shadow-md rounded-md w-full border"> key={suggestion}
{suggestions.map((suggestion, index) => ( className={`p-1 cursor-pointer rounded-md mt-1 mb-1 ${
<li index === selectedIndex
key={suggestion} ? 'bg-gray-500'
className={`p-1 cursor-pointer rounded-md mt-1 mb-1 ${ : 'hover:bg-gray-500'
index === selectedIndex }`}
? 'bg-gray-500' onClick={() => {
: 'hover:bg-gray-500' handleSubmit(() =>
}`} onSubmit({ username: suggestion }),
onClick={() => { )();
handleSubmit(() => setSuggestions([]);
onSubmit({ username: suggestion }), }}
)(); >
setSuggestions([]); {suggestion}
}} </li>
> ))}
{suggestion} </ul>
</li> ) : isLoading ? (
))} <div className="flex justify-center">
</ul>
) : isLoading ? (
<LoadingWheel /> <LoadingWheel />
) : null} </div>
{notFound ? ( ) : null}
<p className="p-1 bg-gray-800 shadow-md rounded-md w-full border text-gray-400"> {notFound && (
user not found <p className="p-1 bg-gray-800 shadow-md rounded-md w-full border text-gray-400">
</p> user not found
) : null} </p>
</div> )}
</div> </div>
{errorMessage && (
<p className="text-red-500 mt-2 p-1 bg-gray-800 rounded-md w-full">
{errorMessage}
</p>
)}
</div> </div>
{errorMessage && (
<div className="mt-4 flex justify-center"> <p className="text-red-500 mt-2 p-1 bg-gray-800 rounded-md w-full">
{errorMessage}
</p>
)}
<div className="flex justify-center pt-4">
<Button <Button
type="submit" type="submit"
onClick={handleSubmit(onSubmit)} className="w-24 bg-green-500 text-black hover:bg-green-600"
className="w-24 btn btn-sm bg-emerald-600 text-white hover:bg-green-500 border-black" disabled={isLoading}
> >
{isLoading ? <LoadingWheel /> : 'Add'} {isLoading ? <LoadingWheel /> : 'Add'}
</Button> </Button>
</div> </div>
</div> </form>
</dialog> </div>
</div> </DialogContent>
</> </Dialog>
); );
} }

View File

@@ -15,10 +15,7 @@ function ContactProfile() {
<img className="w-4 mr-2 invert" src={profile} alt="profile img" /> <img className="w-4 mr-2 invert" src={profile} alt="profile img" />
)} )}
<p> <p>{currentContact ? currentContact.username : null}</p>
{currentContact ? currentContact.username : null} user id:{' '}
{currentContact?.user_id} conv id: {currentContact?.conversation_id}
</p>
</div> </div>
<div className="flex-grow"></div> <div className="flex-grow"></div>

View File

@@ -1,8 +1,17 @@
import LoadingWheel from '../LoadingWheel.tsx'; import LoadingWheel from '../LoadingWheel';
import { useRef, useState } from 'react'; import { useState } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form'; import { SubmitHandler, useForm } from 'react-hook-form';
import { Plus } from 'lucide-react'; import { Plus } from 'lucide-react';
import { axiosClient } from '@/utils/axiosClient.ts'; import { axiosClient } from '@/utils/axiosClient';
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
type Inputs = { type Inputs = {
groupName: string; groupName: string;
@@ -10,7 +19,7 @@ type Inputs = {
function CreateGroupButton() { function CreateGroupButton() {
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
const modalRef = useRef<HTMLDialogElement | null>(null); const [open, setOpen] = useState(false);
const { const {
register, register,
@@ -26,9 +35,7 @@ function CreateGroupButton() {
console.log(response.data); console.log(response.data);
if (response.data.group_id) { if (response.data.group_id) {
setIsLoading(false); setIsLoading(false);
if (modalRef.current) { setOpen(false);
modalRef.current.close();
}
} }
reset(); reset();
} catch (e) { } catch (e) {
@@ -38,63 +45,48 @@ function CreateGroupButton() {
}; };
return ( return (
<> <Dialog open={open} onOpenChange={setOpen}>
<div> <DialogTrigger asChild>
<button <button className="p-2 hover:bg-zinc-800 rounded-lg">
className="p-2 hover:bg-zinc-800 rounded-lg"
onClick={() =>
(
document.getElementById('createGroupModal') as HTMLDialogElement
).showModal()
}
>
<Plus /> <Plus />
</button> </button>
<dialog id="createGroupModal" className="modal" ref={modalRef}> </DialogTrigger>
<div className="modal-box bg-gray-800 text-center relative p-1"> <DialogContent className="bg-zinc-950 text-white sm:max-w-md w-full">
<div className="absolute right-2 top-2"> <DialogHeader>
<form method="dialog"> <DialogTitle className="text-center text-gray-200">
<button className="btn btn-sm btn-circle btn-ghost"></button> Enter group name
</form> </DialogTitle>
</div> </DialogHeader>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="flex flex-col items-center justify-center pb-1 mt-6"> <div className="p-3">
<h3 className="text-lg mb-4">Enter group name</h3> <Input
<form {...register('groupName', {
onSubmit={handleSubmit(onSubmit)} required: true,
className="w-full max-w-xs relative" minLength: 4,
> maxLength: 20,
<input })}
className="input input-bordered bg-green-50 w-full h-10 text-black rounded-md text-center" className="bg-gray-100 text-black h-10 rounded-lg"
{...register('groupName', { aria-invalid={errors.groupName ? 'true' : 'false'}
required: true, />
minLength: 4, {errors.groupName?.type === 'minLength' && (
maxLength: 20, <p className="text-sm text-gray-300">Group name is too short</p>
})} )}
aria-invalid={errors.groupName ? 'true' : 'false'} {errors.groupName?.type === 'maxLength' && (
/> <p className="text-sm text-red-300 ">Group name is too long</p>
{errors.groupName?.type === 'minLength' && ( )}
<p className="text-gray-300">group name is too short</p>
)}
{errors.groupName?.type === 'maxLength' && (
<p className="text-gray-300">group name is too long</p>
)}
</form>
</div>
<div className="mt-4 flex justify-center">
<button
type="submit"
onClick={handleSubmit(onSubmit)}
className="btn btn-sm bg-green-500 text-black hover:bg-green-600"
>
{isLoading ? <LoadingWheel /> : 'Create'}
</button>
</div>
</div> </div>
</dialog> <div className="flex justify-center">
</div> <Button
</> type="submit"
className="bg-green-500 text-black hover:bg-green-600"
disabled={isLoading}
>
{isLoading ? <LoadingWheel /> : 'Create'}
</Button>
</div>
</form>
</DialogContent>
</Dialog>
); );
} }

View File

@@ -99,7 +99,7 @@ function ContactsList() {
className="m-1 flex p-2 hover:bg-zinc-900 cursor-pointer transition-colors rounded-lg justify-between items-start min-h-[40px]" className="m-1 flex p-2 hover:bg-zinc-900 cursor-pointer transition-colors rounded-lg justify-between items-start min-h-[40px]"
onClick={() => { onClick={() => {
initializeContact(contact); initializeContact(contact);
updateContactStatus(contact, true); updateContactStatus(contact.conversation_id, true);
}} }}
> >
<div className="flex flex-col w-full"> <div className="flex flex-col w-full">
@@ -114,7 +114,7 @@ function ContactsList() {
/> />
)} )}
<p className="text-center text-2xl text-red-300 leading-none"> <p className="text-center text-2xl text-red-300 leading-none">
{contact.read ? '' : '•'} {contact.read ? '' : '•'}
</p> </p>
</div> </div>
@@ -133,7 +133,7 @@ function ContactsList() {
<AlertDialogTitle className="text-white"> <AlertDialogTitle className="text-white">
Leave Group? Leave Group?
</AlertDialogTitle> </AlertDialogTitle>
<AlertDialogDescription className="text-white"> <AlertDialogDescription className="text-gray-200">
Are you sure you want to leave this group? Are you sure you want to leave this group?
</AlertDialogDescription> </AlertDialogDescription>
</AlertDialogHeader> </AlertDialogHeader>
@@ -164,12 +164,12 @@ function ContactsList() {
)} )}
</div> </div>
<div className="flex items-center justify-between text-sm text-gray-500"> <div className="flex items-center justify-between text-sm text-gray-500">
<div className="flex items-center"> <div className="flex items-center">
{contact.last_message?.length > 0 ? ( {(contact.last_message ?? '').length > 0 ? (
contact.last_message?.length > 16 ? ( (contact.last_message ?? '').length > 15 ? (
<div className="flex items-center"> <div className="flex items-center">
{contact.last_message?.substring(0, 16)} {contact.last_message?.substring(0, 15)}
<Ellipsis className="w-3 mt-2" /> <Ellipsis className="w-3 mt-2" />
</div> </div>
) : ( ) : (

View File

@@ -135,6 +135,10 @@ function ParticipantsBar() {
group_id: string; group_id: string;
isadmin: boolean; isadmin: boolean;
isowner: boolean; isowner: boolean;
last_message_id: number;
last_message: string | null;
last_message_time: string | null;
last_message_sender: string | null;
}) => { }) => {
const { group_id } = msg; const { group_id } = msg;
if ( if (
@@ -150,8 +154,9 @@ function ParticipantsBar() {
conversation_id: msg.group_id, conversation_id: msg.group_id,
last_active: new Date().toString(), last_active: new Date().toString(),
last_message: '', last_message: '',
last_message_sender: '', last_message_id: msg.last_message_id,
last_message_time: '', last_message_sender: msg.last_message_sender,
last_message_time: msg.last_message_time,
}); });
} }

View File

@@ -18,7 +18,7 @@ const buttonVariants = cva(
secondary: secondary:
'bg-gray-100 text-gray-900 shadow-sm hover:bg-gray-100/80 dark:bg-gray-800 dark:text-gray-50 dark:hover:bg-gray-800/80', 'bg-gray-100 text-gray-900 shadow-sm hover:bg-gray-100/80 dark:bg-gray-800 dark:text-gray-50 dark:hover:bg-gray-800/80',
ghost: ghost:
'hover:bg-gray-100 hover:text-gray-900 dark:hover:bg-gray-800 dark:hover:text-gray-50', 'hover:bg-zinc-800 dark:hover:bg-gray-800 dark:hover:text-gray-50',
link: 'text-gray-900 underline-offset-4 hover:underline dark:text-gray-50', link: 'text-gray-900 underline-offset-4 hover:underline dark:text-gray-50',
}, },
size: { size: {

View File

@@ -0,0 +1,120 @@
import * as React from 'react';
import * as DialogPrimitive from '@radix-ui/react-dialog';
import { X } from 'lucide-react';
import { cn } from '@/lib/utils';
const Dialog = DialogPrimitive.Root;
const DialogTrigger = DialogPrimitive.Trigger;
const DialogPortal = DialogPrimitive.Portal;
const DialogClose = DialogPrimitive.Close;
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
className,
)}
{...props}
/>
));
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-gray-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg dark:border-gray-800 dark:bg-gray-950',
className,
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-lg opacity-70 ring-offset-white transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-gray-950 focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-gray-100 data-[state=open]:text-gray-500 dark:ring-offset-gray-950 dark:focus:ring-gray-300 dark:data-[state=open]:bg-gray-800 dark:data-[state=open]:text-gray-400">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
));
DialogContent.displayName = DialogPrimitive.Content.displayName;
const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col space-y-1.5 text-center sm:text-left',
className,
)}
{...props}
/>
);
DialogHeader.displayName = 'DialogHeader';
const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
className,
)}
{...props}
/>
);
DialogFooter.displayName = 'DialogFooter';
const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
'text-lg font-semibold leading-none tracking-tight',
className,
)}
{...props}
/>
));
DialogTitle.displayName = DialogPrimitive.Title.displayName;
const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn('text-sm text-gray-500 dark:text-gray-400', className)}
{...props}
/>
));
DialogDescription.displayName = DialogPrimitive.Description.displayName;
export {
Dialog,
DialogPortal,
DialogOverlay,
DialogTrigger,
DialogClose,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
};

View File

@@ -88,15 +88,14 @@ export const ChatProvider = ({ children }: { children: ReactNode }) => {
}); });
} }
function updateContactStatus(contactObj: ContactsProps, read: boolean) { function updateContactStatus(conversation_id: string, read: boolean) {
console.log('Update contact status: ', contactObj); console.log('Update contact status: ', conversation_id);
setContactsList((prevContacts) => setContactsList((prevContacts) =>
prevContacts.map((contact) => { prevContacts.map((contact) => {
if (contact.conversation_id === contactObj.conversation_id) { if (contact.conversation_id === conversation_id) {
if (!contactObj.read) { setContactStatus(conversation_id, read);
setContactStatus(contactObj.conversation_id, read);
}
return { ...contact, read: read }; return { ...contact, read: read };
} else { } else {
return contact; return contact;

View File

@@ -0,0 +1,20 @@
import { useEffect, useState } from 'react';
export function useWindowFocus() {
const [isFocused, setIsFocused] = useState<boolean>(document.hasFocus());
useEffect(() => {
const onFocus = () => setIsFocused(true);
const onBlur = () => setIsFocused(false);
window.addEventListener('focus', onFocus);
window.addEventListener('blur', onBlur);
return () => {
window.removeEventListener('focus', onFocus);
window.removeEventListener('blur', onBlur);
};
}, []);
return isFocused;
}

View File

@@ -22,10 +22,10 @@ export type ContactsProps = {
type: 'direct' | 'group'; type: 'direct' | 'group';
conversation_id: string; conversation_id: string;
last_active: string; last_active: string;
last_message: string; last_message: string | null;
last_message_id: number; last_message_id: number | null;
last_message_time: string; last_message_time: string | null;
last_message_sender: string; last_message_sender: string | null;
}; };
export type ParticipantsProps = { export type ParticipantsProps = {
@@ -67,6 +67,6 @@ export type ChatContextType = {
initializeContact: (newContact: ContactsProps) => Promise<boolean>; initializeContact: (newContact: ContactsProps) => Promise<boolean>;
fetchMessages: (conversation_id: string) => Promise<void>; fetchMessages: (conversation_id: string) => Promise<void>;
messageHandler: (msg: ChatMessagesProps) => void; messageHandler: (msg: ChatMessagesProps) => void;
updateContactStatus: (contactObj: ContactsProps, read: boolean) => void; updateContactStatus: (conversation_id: string, read: boolean) => void;
fetchPreviousMessages: (contact: string | null) => Promise<void>; fetchPreviousMessages: (contact: string | null) => Promise<void>;
}; };

View File

@@ -643,7 +643,7 @@ async function insertContact(initiatorId, receiverId, contactUsername, read) {
conversation_id: contact.conversation_id, conversation_id: contact.conversation_id,
type: "direct", type: "direct",
read: contact.read, read: contact.read,
last_message_id: latestMessage.message_id, last_message_id: latestMessage.last_message_id,
last_message: latestMessage.last_message, last_message: latestMessage.last_message,
last_message_time: latestMessage.last_message_time, last_message_time: latestMessage.last_message_time,
last_message_sender: latestMessage.last_message_sender, last_message_sender: latestMessage.last_message_sender,
@@ -657,7 +657,7 @@ async function insertContact(initiatorId, receiverId, contactUsername, read) {
async function getLatestMessage(conversation_id) { async function getLatestMessage(conversation_id) {
const query = ` const query = `
SELECT DISTINCT ON (m.conversation_id) SELECT DISTINCT ON (m.conversation_id)
m.message_id, m.message_id AS last_message_id,
m.content AS last_message, m.content AS last_message,
m.sent_at AS last_message_time, m.sent_at AS last_message_time,
a.username AS last_message_sender a.username AS last_message_sender
@@ -672,7 +672,7 @@ async function getLatestMessage(conversation_id) {
const result = await client.query(query, [conversation_id]); const result = await client.query(query, [conversation_id]);
return { return {
message_id: result.rows[0]?.message_id || null, last_message_id: result.rows[0]?.last_message_id || null,
last_message: result.rows[0]?.last_message || null, last_message: result.rows[0]?.last_message || null,
last_message_time: result.rows[0]?.last_message_time || null, last_message_time: result.rows[0]?.last_message_time || null,
last_message_sender: result.rows[0]?.last_message_sender || null, last_message_sender: result.rows[0]?.last_message_sender || null,
@@ -872,7 +872,7 @@ async function updateContactStatus(user_id, conversation_id, read) {
`; `;
try { try {
await client.query(query, [read, user_id, conversation_id]); await client.query(query, [read, user_id, conversation_id]);
await updateContactLastActive(user_id, conversation_id); // await updateContactLastActive(user_id, conversation_id);
console.log( console.log(
`Successfully updated contact status, user_id: ${user_id}, conversation_id: ${conversation_id}, read: ${read}: `, `Successfully updated contact status, user_id: ${user_id}, conversation_id: ${conversation_id}, read: ${read}: `,
); );
@@ -1261,4 +1261,5 @@ module.exports = {
isAdmin, isAdmin,
addAdministrator, addAdministrator,
removeAdministrator, removeAdministrator,
getLatestMessage,
}; };

View File

@@ -44,6 +44,7 @@ const {
insertContactByUsername, insertContactByUsername,
isConversationMember, isConversationMember,
isAdmin, isAdmin,
getLatestMessage,
} = require("./db/db"); } = require("./db/db");
const { extname } = require("node:path"); const { extname } = require("node:path");
@@ -376,7 +377,10 @@ app.post("/api/chat/groups/create", authorizeUser, async (req, res) => {
} }
console.log("Successfully created group: ", groupname, "id: ", group_id); console.log("Successfully created group: ", groupname, "id: ", group_id);
console.log(`io.to: ${contact_user_id} added to group`); console.log(`io.to: ${contact_user_id} added to group`);
io.to(contact_user_id).emit("added to group", { group_id }); io.to(contact_user_id).emit("added to group", {
group_id,
username: groupname,
});
return res.status(200).json({ return res.status(200).json({
message: `Successfully created group: ${groupname}`, message: `Successfully created group: ${groupname}`,
group_id: group_id, group_id: group_id,
@@ -400,12 +404,22 @@ app.post("/api/chat/groups/addMember", authorizeUser, async (req, res) => {
} }
const result = await addMemberToGroupByUsername(group_id, username); const result = await addMemberToGroupByUsername(group_id, username);
const lastMessage = await getLatestMessage(group_id);
console.error("ADDED TO GROUP: ", {
username,
user_id: result,
group_id,
...lastMessage,
});
if (result !== null) { if (result !== null) {
io.to(result).to(group_id).emit("added to group", { io.to(result)
username, .to(group_id)
user_id: result, .emit("added to group", {
group_id, username,
}); user_id: result,
group_id,
...lastMessage,
});
console.log("added to group: ", result); console.log("added to group: ", result);
return res.status(200).json({ message: "Successfully added member" }); return res.status(200).json({ message: "Successfully added member" });
} }