diff --git a/README.md b/README.md
index 1be79cb..af96042 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,6 @@
#### Opcionales
- Documentos públicos
-- Anidación de documentos
- Compartir bases de datos
### Presentación
@@ -24,10 +23,11 @@ Puede verla en el siguiente [link](https://www.canva.com/design/DAFSnStE99g/k9QG
Debe instalar:
-- Docker
-- Docker-compose
-- Python >= 3.10
-- Poetry
+- docker
+- docker-compose
+- python >= 3.10
+- poetry
+- npm
## Instalación
@@ -49,11 +49,13 @@ POSTGRES_HOST=localhost
POSTGRES_DB=bd2
POSTGRES_USER=root
POSTGRES_PASSWORD=password
+REDIS_HOST=localhost
+REDIS_PORT=6379
```
En un ambiente de testeo (como es el caso) puede simplemente copiar el archivo, pero, si se corriese en producción, se deberá cambiar dependiendo el caso de uso.
-Debe dejar los URLs de las bases de datos como se indicaron pues así se las configuró con docker. Por lo tanto, deberá dejar libres los puertos 5432, 27017 y 9200.
+Debe dejar los URLs de las bases de datos como se indicaron pues así se las configuró con docker. Por lo tanto, deberá dejar libres los puertos 5432, 27017, 9200 y 6379.
Ahora, para levantar las bases de datos (usando `docker-compose`) debe correr:
@@ -69,12 +71,18 @@ Luego, en otra terminal, debe configurar las bases de datos mediante el siguient
sh run.sh -c
```
-Por último, para correr la API + backend, debe hacerlo mediante:
+Además, para correr la API + backend (notando que la API correrá por defecto en el puerto 8000), debe hacerlo mediante:
```
sh run.sh -a
```
+Por último, debe levantar el frontend (usará el puerto 3000) mediante:
+
+```
+h run.sh -f
+```
+
## Documentación de la API
Puede ir a `http://localhost:8000/docs` para ver el `Swagger`. Notemos que se usó en todo momento `localhost` pues se supone un ambiente de testeo.
diff --git a/bsition/frontend/nextjs/.gitignore b/bsition/frontend/.gitignore
similarity index 100%
rename from bsition/frontend/nextjs/.gitignore
rename to bsition/frontend/.gitignore
diff --git a/bsition/frontend/nextjs/next-env.d.ts b/bsition/frontend/next-env.d.ts
similarity index 100%
rename from bsition/frontend/nextjs/next-env.d.ts
rename to bsition/frontend/next-env.d.ts
diff --git a/bsition/frontend/nextjs/src/components/Document.tsx b/bsition/frontend/nextjs/src/components/Document.tsx
deleted file mode 100644
index a7c9e92..0000000
--- a/bsition/frontend/nextjs/src/components/Document.tsx
+++ /dev/null
@@ -1,128 +0,0 @@
-import io from "socket.io-client";
-import { useState, useEffect } from "react";
-
-let socket;
-
-export default function Document() {
- const [username, setUsername] = useState("");
- const [chosenUsername, setChosenUsername] = useState("");
- const [text, setText] = useState("");
- const [token, setToken] = useState("");
-
- useEffect(() => {
- socketInitializer();
- }, [chosenUsername]);
-
- useEffect(() => {
- const data = new URLSearchParams();
- data.append("username", "user")
- data.append("password", "passtest")
-
- const fetchData = async (data) => {
- const res = await fetch("http://localhost:8000/api/token", { method: 'POST', body: data})
- const json = await res.json();
- setToken(() => json["access_token"])
- }
-
- fetchData(data)
- }, [])
-
- useEffect(() => {
- if (token) {
- const fetchData = async () => {
- const res = await fetch("http://localhost:8000/api/documents/63866c991b4175934db26981", {
- method: "GET",
- headers: {
- 'Authorization': `Bearer ${token}`
- }
- })
- const json = await res.json();
- setText(() => json["data"])
- }
-
- fetchData()
- }
- }, [token])
-
- useEffect(() => {
- const interval = setInterval(() => {
- fetch("http://localhost:8000/api/documents/63866c991b4175934db26981", {
- method: 'PUT',
- body: `{"data": "${text}"}`,
- headers: {
- 'Content-type': 'application/json',
- 'Authorization': `Bearer ${token}`
- }
- })
- }, 500);
-
- return () => clearInterval(interval);
- }, [token, text])
-
- const socketInitializer = async () => {
- await fetch("/api/socket");
-
- socket = io();
-
- socket.emit('create', chosenUsername);
- console.log(chosenUsername)
-
- socket.on("newIncomingText", (text) => {
- setText(() => text);
- console.log('text' + text);
- });
- };
-
- const sendText = async () => {
- socket.emit("createdText", text, chosenUsername);
- setText(() => text);
- };
-
- const handleKey = () => {
- if (text) {
- sendText();
- }
- };
-
- return (
-
-
- {!chosenUsername ? (
- <>
-
- doc_id?
-
- setUsername(e.target.value)}
- />
-
- >
- ) : (
- <>
-
- Your username: {username}
-
-
-
-
- );
-}
\ No newline at end of file
diff --git a/bsition/frontend/nextjs/package-lock.json b/bsition/frontend/package-lock.json
similarity index 99%
rename from bsition/frontend/nextjs/package-lock.json
rename to bsition/frontend/package-lock.json
index 636957a..eabfb7c 100644
--- a/bsition/frontend/nextjs/package-lock.json
+++ b/bsition/frontend/package-lock.json
@@ -1,11 +1,11 @@
{
- "name": "nextjs-tailwindcss-typescript-starter",
+ "name": "bsition",
"version": "0.1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
- "name": "nextjs-tailwindcss-typescript-starter",
+ "name": "bsition",
"version": "0.1.0",
"dependencies": {
"classnames": "^2.3.1",
diff --git a/bsition/frontend/nextjs/package.json b/bsition/frontend/package.json
similarity index 91%
rename from bsition/frontend/nextjs/package.json
rename to bsition/frontend/package.json
index 81ff3ab..e2cee29 100644
--- a/bsition/frontend/nextjs/package.json
+++ b/bsition/frontend/package.json
@@ -1,5 +1,5 @@
{
- "name": "nextjs-tailwindcss-typescript-starter",
+ "name": "bsition",
"version": "0.1.0",
"private": true,
"scripts": {
diff --git a/bsition/frontend/nextjs/postcss.config.js b/bsition/frontend/postcss.config.js
similarity index 100%
rename from bsition/frontend/nextjs/postcss.config.js
rename to bsition/frontend/postcss.config.js
diff --git a/bsition/frontend/nextjs/public/favicon.ico b/bsition/frontend/public/favicon.ico
similarity index 100%
rename from bsition/frontend/nextjs/public/favicon.ico
rename to bsition/frontend/public/favicon.ico
diff --git a/bsition/frontend/nextjs/src/components/Layout.tsx b/bsition/frontend/src/components/Layout.tsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/Layout.tsx
rename to bsition/frontend/src/components/Layout.tsx
diff --git a/bsition/frontend/nextjs/src/components/Sidebar.tsx b/bsition/frontend/src/components/Sidebar.tsx
similarity index 89%
rename from bsition/frontend/nextjs/src/components/Sidebar.tsx
rename to bsition/frontend/src/components/Sidebar.tsx
index 0710a13..ec97789 100644
--- a/bsition/frontend/nextjs/src/components/Sidebar.tsx
+++ b/bsition/frontend/src/components/Sidebar.tsx
@@ -59,14 +59,14 @@ const Sidebar = () => {
const router = useRouter();
- const activeMenu = useMemo(
+ let activeMenu = useMemo(
() => menuItems.find((menu) => {
if (!router.query.id || router.query.id === 'undefined') {
return menu.link === router.pathname
} else if (!(menu.id === 1 || menu.id === 2 || menu.id === 3)) {
return menu.id.toString() === router.query.id
}
- return true
+ return false
}),
[menuItems, router.query.id, router.pathname]
);
@@ -87,6 +87,19 @@ const Sidebar = () => {
);
const getNavItemClasses = (menu) => {
+ if (!activeMenu || !menu || menu === "undefined") {
+ if (!router.query || !router.query.id) {
+ return classNames("flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap");
+ }
+ else {
+ return classNames(
+ "flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap",
+ {
+ ["bg-light-lighter"]: router.query.id === menu.id,
+ }
+ );
+ }
+ }
return classNames(
"flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap",
{
diff --git a/bsition/frontend/nextjs/src/components/icons/ArticleIcon.jsx b/bsition/frontend/src/components/icons/ArticleIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/ArticleIcon.jsx
rename to bsition/frontend/src/components/icons/ArticleIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/CollapsIcon.jsx b/bsition/frontend/src/components/icons/CollapsIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/CollapsIcon.jsx
rename to bsition/frontend/src/components/icons/CollapsIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/CreateIcon.jsx b/bsition/frontend/src/components/icons/CreateIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/CreateIcon.jsx
rename to bsition/frontend/src/components/icons/CreateIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/DeleteIcon.jsx b/bsition/frontend/src/components/icons/DeleteIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/DeleteIcon.jsx
rename to bsition/frontend/src/components/icons/DeleteIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/HomeIcon.jsx b/bsition/frontend/src/components/icons/HomeIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/HomeIcon.jsx
rename to bsition/frontend/src/components/icons/HomeIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/LockIcon.jsx b/bsition/frontend/src/components/icons/LockIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/LockIcon.jsx
rename to bsition/frontend/src/components/icons/LockIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/Logo.jsx b/bsition/frontend/src/components/icons/Logo.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/Logo.jsx
rename to bsition/frontend/src/components/icons/Logo.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/LogoutIcon.jsx b/bsition/frontend/src/components/icons/LogoutIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/LogoutIcon.jsx
rename to bsition/frontend/src/components/icons/LogoutIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/ManageIcon.jsx b/bsition/frontend/src/components/icons/ManageIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/ManageIcon.jsx
rename to bsition/frontend/src/components/icons/ManageIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/OptionsIcon.jsx b/bsition/frontend/src/components/icons/OptionsIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/OptionsIcon.jsx
rename to bsition/frontend/src/components/icons/OptionsIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/PublicIcon.jsx b/bsition/frontend/src/components/icons/PublicIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/PublicIcon.jsx
rename to bsition/frontend/src/components/icons/PublicIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/SearchIcon.jsx b/bsition/frontend/src/components/icons/SearchIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/SearchIcon.jsx
rename to bsition/frontend/src/components/icons/SearchIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/ShareIcon.jsx b/bsition/frontend/src/components/icons/ShareIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/ShareIcon.jsx
rename to bsition/frontend/src/components/icons/ShareIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/UsersIcon.jsx b/bsition/frontend/src/components/icons/UsersIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/UsersIcon.jsx
rename to bsition/frontend/src/components/icons/UsersIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/VideosIcon.jsx b/bsition/frontend/src/components/icons/VideosIcon.jsx
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/VideosIcon.jsx
rename to bsition/frontend/src/components/icons/VideosIcon.jsx
diff --git a/bsition/frontend/nextjs/src/components/icons/index.js b/bsition/frontend/src/components/icons/index.js
similarity index 100%
rename from bsition/frontend/nextjs/src/components/icons/index.js
rename to bsition/frontend/src/components/icons/index.js
diff --git a/bsition/frontend/nextjs/src/pages/_app.tsx b/bsition/frontend/src/pages/_app.tsx
similarity index 100%
rename from bsition/frontend/nextjs/src/pages/_app.tsx
rename to bsition/frontend/src/pages/_app.tsx
diff --git a/bsition/frontend/nextjs/src/pages/api/socket.tsx b/bsition/frontend/src/pages/api/socket.tsx
similarity index 85%
rename from bsition/frontend/nextjs/src/pages/api/socket.tsx
rename to bsition/frontend/src/pages/api/socket.tsx
index 96b2611..739afcd 100644
--- a/bsition/frontend/nextjs/src/pages/api/socket.tsx
+++ b/bsition/frontend/src/pages/api/socket.tsx
@@ -3,7 +3,6 @@ import messageHandler from "../../utils/sockets/messageHandler";
export default function SocketHandler(req, res) {
if (res.socket.server.io) {
- console.log("Already set up");
res.end();
return;
}
@@ -17,6 +16,5 @@ export default function SocketHandler(req, res) {
io.on("connection", onConnection);
- console.log("Setting up socket");
res.end();
}
diff --git a/bsition/frontend/nextjs/src/pages/create-document.tsx b/bsition/frontend/src/pages/create-document.tsx
similarity index 100%
rename from bsition/frontend/nextjs/src/pages/create-document.tsx
rename to bsition/frontend/src/pages/create-document.tsx
diff --git a/bsition/frontend/nextjs/src/pages/documents/[id].tsx b/bsition/frontend/src/pages/documents/[id].tsx
similarity index 100%
rename from bsition/frontend/nextjs/src/pages/documents/[id].tsx
rename to bsition/frontend/src/pages/documents/[id].tsx
diff --git a/bsition/frontend/nextjs/src/pages/documents/[id]/access.tsx b/bsition/frontend/src/pages/documents/[id]/access.tsx
similarity index 85%
rename from bsition/frontend/nextjs/src/pages/documents/[id]/access.tsx
rename to bsition/frontend/src/pages/documents/[id]/access.tsx
index 0ef8365..85a8bc7 100644
--- a/bsition/frontend/nextjs/src/pages/documents/[id]/access.tsx
+++ b/bsition/frontend/src/pages/documents/[id]/access.tsx
@@ -12,12 +12,9 @@ import {
import Link from "next/link";
import classNames from "classnames";
-let socket;
-
export default function Document() {
const router = useRouter();
- const [text, setText] = useState("");
const [token, setToken] = useState("");
const [users, setUsers] = useState([]);
@@ -51,23 +48,6 @@ export default function Document() {
}
}, [token, router.query.id])
- useEffect(() => {
- if (token && router.query.id) {
- const interval = setInterval(() => {
- fetch(`http://localhost:8000/api/documents/${router.query.id}`, {
- method: 'PUT',
- body: `{"data": "${text}"}`,
- headers: {
- 'Content-type': 'application/json',
- 'Authorization': `Bearer ${token}`
- }
- })
- }, 500);
-
- return () => clearInterval(interval);
- }
- }, [token, text, router.query.id])
-
const handleSubmit = async (event) => {
event.preventDefault()
diff --git a/bsition/frontend/nextjs/src/pages/index.tsx b/bsition/frontend/src/pages/index.tsx
similarity index 100%
rename from bsition/frontend/nextjs/src/pages/index.tsx
rename to bsition/frontend/src/pages/index.tsx
diff --git a/bsition/frontend/nextjs/src/pages/login.tsx b/bsition/frontend/src/pages/login.tsx
similarity index 100%
rename from bsition/frontend/nextjs/src/pages/login.tsx
rename to bsition/frontend/src/pages/login.tsx
diff --git a/bsition/frontend/nextjs/src/pages/search.tsx b/bsition/frontend/src/pages/search.tsx
similarity index 92%
rename from bsition/frontend/nextjs/src/pages/search.tsx
rename to bsition/frontend/src/pages/search.tsx
index 5d688fe..5085ad3 100644
--- a/bsition/frontend/nextjs/src/pages/search.tsx
+++ b/bsition/frontend/src/pages/search.tsx
@@ -9,7 +9,9 @@ export default function Search() {
const [token, setToken] = useState("");
const [search, setSearch] = useState("");
- const [menuItems, setMenuItems] = useState([{id: 1, label: "", link: "/"}]);
+ const [menuItems, setMenuItems] = useState([
+ {id: 1, label: "", link: "/", first: "", bold: "", second: ""}
+ ]);
useEffect(() => {
setToken(() => localStorage.getItem("token"))
@@ -36,12 +38,12 @@ export default function Search() {
if (highlight.length < end + 15) {
second_str = highlight.substring(end, highlight.length)
} else {
- second_str = highlight.substring(end, end + 15)
+ second_str = highlight.substring(end, end + 15) + " ..."
}
if (initial - 10 < 0) {
first_str = highlight.substring(0, initial)
} else {
- first_str = highlight.substring(0, initial - 10)
+ first_str = "... " + highlight.substring(initial - 10, initial)
}
highlight = highlight.substring(initial + 4, end)
list.push({
diff --git a/bsition/frontend/nextjs/src/styles/Home.module.css b/bsition/frontend/src/styles/Home.module.css
similarity index 100%
rename from bsition/frontend/nextjs/src/styles/Home.module.css
rename to bsition/frontend/src/styles/Home.module.css
diff --git a/bsition/frontend/nextjs/src/styles/index.css b/bsition/frontend/src/styles/index.css
similarity index 100%
rename from bsition/frontend/nextjs/src/styles/index.css
rename to bsition/frontend/src/styles/index.css
diff --git a/bsition/frontend/nextjs/src/utils/sockets/messageHandler.tsx b/bsition/frontend/src/utils/sockets/messageHandler.tsx
similarity index 84%
rename from bsition/frontend/nextjs/src/utils/sockets/messageHandler.tsx
rename to bsition/frontend/src/utils/sockets/messageHandler.tsx
index d6091dc..ab2654c 100644
--- a/bsition/frontend/nextjs/src/utils/sockets/messageHandler.tsx
+++ b/bsition/frontend/src/utils/sockets/messageHandler.tsx
@@ -1,7 +1,5 @@
export default (io, socket) => {
const createdText = (text, room) => {
- console.log(room);
- console.log(text);
socket.to(room).emit("newIncomingText", text);
};
diff --git a/bsition/frontend/nextjs/tailwind.config.js b/bsition/frontend/tailwind.config.js
similarity index 100%
rename from bsition/frontend/nextjs/tailwind.config.js
rename to bsition/frontend/tailwind.config.js
diff --git a/bsition/frontend/nextjs/tsconfig.json b/bsition/frontend/tsconfig.json
similarity index 100%
rename from bsition/frontend/nextjs/tsconfig.json
rename to bsition/frontend/tsconfig.json
diff --git a/bsition/frontend/nextjs/yarn.lock b/bsition/frontend/yarn.lock
similarity index 100%
rename from bsition/frontend/nextjs/yarn.lock
rename to bsition/frontend/yarn.lock
diff --git a/run.sh b/run.sh
index 3bde578..3dbb95e 100644
--- a/run.sh
+++ b/run.sh
@@ -8,6 +8,7 @@ usage: ${0##*/} [command]
-i Install dependencies.
-d Run docker-compose up.
-c Configure databases.
+ -f Build and run frontend.
EOF
exit 1
}
@@ -19,6 +20,7 @@ while getopts "hadic" OPTION; do
d) RUN=docker ;;
i) RUN=install ;;
c) RUN=configure ;;
+ f) RUN=front ;;
*) usage ;;
esac
done
@@ -29,6 +31,11 @@ elif [ "$RUN" = 'api' ]; then
poetry run uvicorn bsition.api.main:app --host 0.0.0.0
elif [ "$RUN" = 'configure' ]; then
poetry run configure
+elif [ "$RUN" = 'front' ]; then
+ cd bsition/frontend
+ npm install
+ npm run build
+ npm run start
else
[ ! -d data ] && mkdir data
[ ! -d data/postgres ] && mkdir data/postgres