diff --git a/compose.yaml b/compose.yaml index 2077703..582156a 100644 --- a/compose.yaml +++ b/compose.yaml @@ -47,7 +47,7 @@ services: develop: watch: - action: rebuild - path: src/ + path: . ignore: - node_modules/ diff --git a/init-mongo.js b/init-mongo.js index 70dd3a7..c883274 100644 --- a/init-mongo.js +++ b/init-mongo.js @@ -2,7 +2,7 @@ db = new Mongo().getDB("bot"); db.createCollection('authorizations'); -db.authorization.insert([ +db.authorizations.insert([ { app: "tester", secret: "test" diff --git a/src/App.tsx b/src/App.tsx index b0cfcfc..0dbec40 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,17 +1,12 @@ -import './App.css' -import ImageModerator, { ImageModeratorProps } from './components/ImageModerator/ImageModerator' - -const imageModeratorProps: ImageModeratorProps = { - acceptLabel: "Accept", - discardLabel: "Discard" -} +import "./App.css"; +import ImageModerator from "./components/ImageModerator/ImageModerator"; function App() { return ( <> - + - ) + ); } -export default App \ No newline at end of file +export default App; diff --git a/src/components/ImageModerator/ImageModerator.tsx b/src/components/ImageModerator/ImageModerator.tsx index 89cb61a..88d597b 100644 --- a/src/components/ImageModerator/ImageModerator.tsx +++ b/src/components/ImageModerator/ImageModerator.tsx @@ -1,50 +1,121 @@ import Button from "../Button/Button"; import { useEffect, useState } from "react"; -export interface ImageModeratorProps { - acceptLabel: string; - discardLabel: string; -} +// Let the user input the middleware URL, API url and app + secret +const MWURL = "http://localhost:8081"; +const APIURL = "http://localhost:8080"; +const app = "tester"; +const secret = "test"; -export default function ImageModerator({ acceptLabel, discardLabel }: ImageModeratorProps) { - const endpoint = "http://fe-middleware:8081/image"; +export default function ImageModerator() { + const acceptLabel = "Accept"; + const discardLabel = "Discard"; - const [isLoading, setIsLoading] = useState(true); - const [imageSrc, setImageSrc] = useState(""); - const [imageAlt, setImageAlt] = useState("No image"); + const endpoint = `${MWURL}/image`; - const getNewImage = () => { - setImageSrc(""); - setIsLoading(true); - fetch(endpoint, { - method: "GET", - }) - .then(response => { - if (!response.ok) throw new Error("Response was not ok"); - return response.json(); - }) - .then(data => { - const imageUrl = data.post[0].file_url; - setImageSrc(imageUrl); - setImageAlt(imageUrl); - }) - .catch(error => { - setImageAlt("Error"); - console.error(error); - }).finally(() => { - setIsLoading(false); - }); - } + const [isLoading, setIsLoading] = useState(true); + const [imageSrc, setImageSrc] = useState(""); + const [imageAlt, setImageAlt] = useState("No image"); + const [token, setToken] = useState(""); - useEffect(getNewImage, []); + useEffect(() => { + fetch(`${APIURL}/login`, { + method: "POST", + body: JSON.stringify({ app, secret }), + headers: { "Content-type": "application/json" }, + }) + .then((response) => { + return response.json(); + }) + .then((body) => { + setToken(body.token); + }); + }, []); - return
- {isLoading ? Loading... : - {imageAlt}} -
-} \ No newline at end of file + ); +} diff --git a/src/main.tsx b/src/main.tsx index 3d7150d..a4d5ce7 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,10 +1,7 @@ -import React from 'react' import ReactDOM from 'react-dom/client' import App from './App.tsx' import './index.css' ReactDOM.createRoot(document.getElementById('root')!).render( - - , )