diff --git a/.gitignore b/.gitignore index d622fee..171b775 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -backend/.env +*/.env */target/ \ No newline at end of file diff --git a/backend/go.mod b/backend/go.mod index d33458f..6ff8035 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -5,6 +5,7 @@ go 1.20 require github.com/go-chi/chi/v5 v5.0.10 require ( + github.com/go-chi/cors v1.2.1 github.com/golang/snappy v0.0.1 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/klauspost/compress v1.13.6 // indirect diff --git a/backend/go.sum b/backend/go.sum index c9da598..d253b70 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,6 +1,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= +github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= diff --git a/backend/main.go b/backend/main.go index a228bf6..8028de7 100644 --- a/backend/main.go +++ b/backend/main.go @@ -6,6 +6,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" + "github.com/go-chi/cors" "github.com/g00gol/frieren/backend/db" "github.com/g00gol/frieren/backend/routes" @@ -15,7 +16,16 @@ func main() { port := "8080" r := chi.NewRouter() + r.Use(cors.Handler(cors.Options{ + AllowedOrigins: []string{"http://*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "OPTIONS"}, + AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, + ExposedHeaders: []string{"Link"}, + AllowCredentials: false, + MaxAge: 300, // Maximum value not ignored by any of major browsers + })) r.Use(middleware.Logger) + routes.RegisterRoutes(r) // Connect to MongoDB diff --git a/frontend/app/globals.css b/frontend/app/globals.css index 30e16f0..ead80bc 100644 --- a/frontend/app/globals.css +++ b/frontend/app/globals.css @@ -27,4 +27,10 @@ html, body { small { @apply text-sm; } +} + +@layer components { + .tab-active { + @apply text-sky-blue; + } } \ No newline at end of file diff --git a/frontend/app/page.js b/frontend/app/page.js index d702e99..9b01f55 100644 --- a/frontend/app/page.js +++ b/frontend/app/page.js @@ -2,11 +2,12 @@ import React from "react"; import Searchbar from "@/components/searchbar"; +import Cards from "@/components/cards/cards"; export default function Home() { return ( -
-

+
+

celebrating open source projects. discover projects that interest you!

@@ -14,6 +15,8 @@ export default function Home() { collaboration, so you can focus on the projects you love

+ +
); } diff --git a/frontend/components/cards.js b/frontend/components/cards.js deleted file mode 100644 index 6b15b05..0000000 --- a/frontend/components/cards.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function Cards({ children }) { - return
{children}
; -} diff --git a/frontend/components/cards/card.js b/frontend/components/cards/card.js new file mode 100644 index 0000000..70d437d --- /dev/null +++ b/frontend/components/cards/card.js @@ -0,0 +1,7 @@ +export default function Card({ project }) { + return ( +
+ {project.name} +
+ ); +} diff --git a/frontend/components/cards/cards.js b/frontend/components/cards/cards.js new file mode 100644 index 0000000..a223f68 --- /dev/null +++ b/frontend/components/cards/cards.js @@ -0,0 +1,25 @@ +import { useContext, useEffect, useState } from "react"; + +import SearchbarContext from "@/context/searchbar"; +import fetchApi from "@/utils/fetchApi"; +import Card from "./card"; + +export default function Cards({ children }) { + const [data, setData] = useState([]); + const { searchTerm } = useContext(SearchbarContext); + + useEffect(() => { + fetchApi("104.248.58.127/api/repos").then((data) => { + console.log(data); + setData(data); + }); + }, [searchTerm]); + + return ( + <> + {data.map((project) => ( + + ))} + + ); +} diff --git a/frontend/components/nav.js b/frontend/components/nav.js index e552248..49a4560 100644 --- a/frontend/components/nav.js +++ b/frontend/components/nav.js @@ -4,7 +4,7 @@ export default function Nav() { return ( ); diff --git a/frontend/components/searchbar.js b/frontend/components/searchbar.js index df5ed37..89ca7e6 100644 --- a/frontend/components/searchbar.js +++ b/frontend/components/searchbar.js @@ -1,22 +1,40 @@ -import { useContext } from "react"; +import { useContext, useRef } from "react"; +import { AiOutlineSearch } from "react-icons/ai"; + import SearchbarContext from "@/context/searchbar"; export default function Searchbar() { + const inputRef = useRef(); + const { searchTerm, setSearchTerm } = useContext(SearchbarContext); - function handleSearchbarChange(e) { - setSearchTerm(e.target.value); + function handleSearchbarSubmit(e) { + e.preventDefault(); + setSearchTerm(inputRef.current.value); } return ( - <> -