From 4c6daa1c6cdcc2c84e47352082716ccf97f994f2 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Fri, 26 Dec 2025 15:53:19 +0100 Subject: [PATCH] Add distant links --- eslint.config.js | 21 +++++++++++---------- package.json | 5 +++++ src/App.tsx | 22 +++++++++++++++++++--- src/CastesLinks.tsx | 35 +++++++++++++++++++++++++++++++---- src/LocalLinks.tsx | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 src/LocalLinks.tsx diff --git a/eslint.config.js b/eslint.config.js index d94e7de..f72c7ff 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,18 +1,19 @@ -import js from '@eslint/js' -import globals from 'globals' -import reactHooks from 'eslint-plugin-react-hooks' -import reactRefresh from 'eslint-plugin-react-refresh' -import tseslint from 'typescript-eslint' -import { globalIgnores } from 'eslint/config' +import js from "@eslint/js"; +import globals from "globals"; +import reactHooks from "eslint-plugin-react-hooks"; +import reactRefresh from "eslint-plugin-react-refresh"; +import tseslint from "typescript-eslint"; +import { globalIgnores } from "eslint/config"; +import { SemicolonPreference } from "typescript"; export default tseslint.config([ - globalIgnores(['dist']), + globalIgnores(["dist"]), { - files: ['**/*.{ts,tsx}'], + files: ["**/*.{ts,tsx}"], extends: [ js.configs.recommended, tseslint.configs.recommended, - reactHooks.configs['recommended-latest'], + reactHooks.configs["recommended-latest"], reactRefresh.configs.vite, ], languageOptions: { @@ -20,4 +21,4 @@ export default tseslint.config([ globals: globals.browser, }, }, -]) +]); diff --git a/package.json b/package.json index 83ceb4d..aee5031 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,11 @@ "name": "dashboardjs", "private": true, "version": "0.0.0", + "proxy": [ + "http://gpao.lan", + "http://raspitipi.local:3002", + "http://192.168.3.42:3002" + ], "type": "module", "scripts": { "dev": "vite", diff --git a/src/App.tsx b/src/App.tsx index ef96012..7d1a803 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import type { FC } from "react"; import { CastesLinks } from "./CastesLinks"; +import { LocalLinks } from "./LocalLinks"; function App() { const links = [ @@ -12,18 +13,33 @@ function App() { ]; const proLinks = [ + { + name: "ComCastes", + link: "http://comcastes.loc", + icon: "http://comcastes.loc/favicon.ico", + }, { name: "GPAO", link: "http://gpao.loc", icon: "http://gpao.loc/favicon.ico", }, - { name: "Mycastes", link: "http://mycastes.loc" }, + { + name: "API Castes", + link: "http://apicastes.loc", + icon: "http://apicastes.loc/favicon.ico", + }, + { + name: "Mycastes", + link: "http://mycastes.loc", + icon: "http://mycastes.loc/favicon.ico", + }, ]; return (

Frame Work

+
@@ -43,7 +59,7 @@ export const LinkGroup: FC = ({ title, links }) => {

{title}

@@ -70,7 +86,7 @@ const Link: FC = ({ link }) => { > {link.icon ? (
- {link.name} +
{link.name}
) : ( diff --git a/src/CastesLinks.tsx b/src/CastesLinks.tsx index 2e1ca0e..0fea6fb 100644 --- a/src/CastesLinks.tsx +++ b/src/CastesLinks.tsx @@ -3,7 +3,13 @@ import { LinkGroup } from "./App"; export const CastesLinks = () => { const [loading, setLoading] = useState(true); - const links = [{ name: "GPAO", link: "http://gpao.lan" }]; + const [error, setError] = useState(""); + const [links, setLinks] = useState([]); + const castesLinks = [ + { name: "GPAO", link: "http://gpao.lan" }, + { name: "Penpot", link: "https://penpot.castes-industrie.fr" }, + { name: "Schema", link: "http://schemas.castes-industrie.fr/" }, + ]; useEffect(() => { testConnection(); @@ -11,9 +17,30 @@ export const CastesLinks = () => { const testConnection = async () => { try { - const res = await fetch("http://gpao.lan"); + const res = await fetch("http://gpao.lan", { method: "HEAD" }); + console.log(res); + if (res.ok) { + setLinks(castesLinks); + } console.log("link", res); - } catch (error) {} + } catch (error: Error | NetworkError | unknown) { + console.log(error); + setError(error.response?.data.message || error.message); + } finally { + setLoading(false); + } }; - return ; + return loading ? ( +
Chargement...
+ ) : ( + <> +
Casty
+ {error && ( +
+ {error} +
+ )} + + + ); }; diff --git a/src/LocalLinks.tsx b/src/LocalLinks.tsx new file mode 100644 index 0000000..7f5f42a --- /dev/null +++ b/src/LocalLinks.tsx @@ -0,0 +1,41 @@ +import { useEffect, useState } from "react"; +import { LinkGroup } from "./App"; + +export const LocalLinks = () => { + const [loading, setLoading] = useState(true); + const [error, setError] = useState(false); + const [links, setLinks] = useState([]); + + useEffect(() => { + testConnection(); + }, []); + + const testConnection = async () => { + try { + const res = await fetch( + "http://192.168.3.42:3002/api/get_links2091652955602628755", + //"http://raspitipi.local:3002/api/get_links2091652955602628755", + ); + const data = await res.json(); + console.log(data, res); + setLinks(data); + console.log("link", res); + } catch (_: unknown) { + setError(true); + } finally { + setLoading(false); + } + }; + return loading ? ( +
Chargement...
+ ) : ( + <> + + {error ? ( +
+ Liens non accessibles +
+ ) : null} + + ); +};