From 0dcd93ef92d4ae9a4e5a63e5bac74f0c9b23c16a Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 19 Jun 2023 15:45:26 -0300 Subject: [PATCH] added discord and twitter icons, added github stars --- .../src/components/headerComponent/index.tsx | 52 +++++++++++++------ src/frontend/src/controllers/API/index.ts | 17 ++++++ 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/frontend/src/components/headerComponent/index.tsx b/src/frontend/src/components/headerComponent/index.tsx index 67ef327f2..48c73ac86 100644 --- a/src/frontend/src/components/headerComponent/index.tsx +++ b/src/frontend/src/components/headerComponent/index.tsx @@ -1,6 +1,6 @@ import { BellIcon, Home, Users2 } from "lucide-react"; -import { useContext } from "react"; -import { FaGithub } from "react-icons/fa"; +import { useContext, useEffect, useState } from "react"; +import { FaDiscord, FaGithub, FaTwitter } from "react-icons/fa"; import { Button } from "../ui/button"; import { TabsContext } from "../../contexts/tabsContext"; import AlertDropdown from "../../alerts/alertDropDown"; @@ -11,6 +11,7 @@ import { typesContext } from "../../contexts/typesContext"; import MenuBar from "./components/menuBar"; import { Link, useLocation, useParams } from "react-router-dom"; import { USER_PROJECTS_HEADER } from "../../constants"; +import { getRepoStars } from "../../controllers/API"; export default function Header() { const { flows, addFlow, tabId } = useContext(TabsContext); @@ -22,6 +23,16 @@ export default function Header() { const { notificationCenter, setNotificationCenter, setErrorData } = useContext(alertContext); const location = useLocation(); + + const [stars, setStars] = useState(null); + + useEffect(() => { + async function fetchStars() { + const starsCount = await getRepoStars("logspace-ai", "langflow"); + setStars(starsCount); + } + fetchStars(); + }, []); return (
@@ -57,22 +68,35 @@ export default function Header() {
-
- {/* - {/* */}
diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index f0c36a215..fb24a0f2b 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -18,6 +18,23 @@ export async function getAll(): Promise> { return await axios.get(`/api/v1/all`); } +const GITHUB_API_URL = "https://api.github.com"; +const GITHUB_PERSONAL_ACCESS_TOKEN = "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"; + +axios.defaults.headers.common[ + "Authorization" +] = `token ${GITHUB_PERSONAL_ACCESS_TOKEN}`; + +export async function getRepoStars(owner, repo) { + try { + const response = await axios.get(`${GITHUB_API_URL}/repos/${owner}/${repo}`); + return response.data.stargazers_count; + } catch (error) { + console.error("Error fetching repository data:", error); + return null; + } +} + /** * Sends data to the API for prediction. *