From fa981f041967ad8ddc948ecbdbf646fdbe31b99c Mon Sep 17 00:00:00 2001 From: mathayay Date: Mon, 13 Oct 2025 16:45:38 +0200 Subject: [PATCH] next step tired --- source/components/DeviceSection.js | 36 ----------------- source/components/LoadingBar.js | 20 --------- source/components/MatchesSection.js | 25 ------------ source/components/MemoSection.js | 15 ------- source/components/TaskTroveSection.js | 36 ----------------- source/components/WeatherSection.js | 28 ------------- source/config.js | 12 ------ source/hooks/useDeviceInfo.js | 34 ---------------- source/hooks/useLatestMemo.js | 54 ------------------------- source/hooks/useMatches.js | 58 --------------------------- source/hooks/useTaskTroveTasks.js | 54 ------------------------- source/hooks/useTerminalSize.js | 22 ---------- source/hooks/useWeather.js | 35 ---------------- source/utils/dateUtils.js | 22 ---------- source/utils/weatherCodes.js | 32 --------------- 15 files changed, 483 deletions(-) delete mode 100644 source/components/DeviceSection.js delete mode 100644 source/components/LoadingBar.js delete mode 100644 source/components/MatchesSection.js delete mode 100644 source/components/MemoSection.js delete mode 100644 source/components/TaskTroveSection.js delete mode 100644 source/components/WeatherSection.js delete mode 100644 source/config.js delete mode 100644 source/hooks/useDeviceInfo.js delete mode 100644 source/hooks/useLatestMemo.js delete mode 100644 source/hooks/useMatches.js delete mode 100644 source/hooks/useTaskTroveTasks.js delete mode 100644 source/hooks/useTerminalSize.js delete mode 100644 source/hooks/useWeather.js delete mode 100644 source/utils/dateUtils.js delete mode 100644 source/utils/weatherCodes.js diff --git a/source/components/DeviceSection.js b/source/components/DeviceSection.js deleted file mode 100644 index d254bd8..0000000 --- a/source/components/DeviceSection.js +++ /dev/null @@ -1,36 +0,0 @@ -// components/DeviceSection.js - -import React from 'react'; -import { Box, Text } from 'ink'; -import { LoadingBar } from './LoadingBar.js'; - -function renderDeviceInfo(deviceInfo, deviceError) { - if (deviceError) { - return {deviceError}; - } - if (!deviceInfo) { - return Chargement des informations...; - } - - const percentage = deviceInfo.percentage; - if (percentage == null) { - return Status : {deviceInfo.status || 'N/A'}; - } else { - return ( - - - Temps restant : {deviceInfo.remainingTime || 'N/A'} - Status : {deviceInfo.status || 'N/A'} - - ); - } -} - -export function DeviceSection({ deviceInfo, deviceError, width }) { - return ( - - Informations du device : - {renderDeviceInfo(deviceInfo, deviceError)} - - ); -} diff --git a/source/components/LoadingBar.js b/source/components/LoadingBar.js deleted file mode 100644 index 60a121d..0000000 --- a/source/components/LoadingBar.js +++ /dev/null @@ -1,20 +0,0 @@ -// components/LoadingBar.js - -import React from 'react'; -import { Box, Text } from 'ink'; - -export const LoadingBar = ({ percentage }) => { - const width = 30; - const filledWidth = Math.round((percentage / 100) * width); - const emptyWidth = width - filledWidth; - - return ( - - [ - {'='.repeat(filledWidth)} - {' '.repeat(emptyWidth)} - ] - {percentage}% - - ); -}; diff --git a/source/components/MatchesSection.js b/source/components/MatchesSection.js deleted file mode 100644 index 9c803dd..0000000 --- a/source/components/MatchesSection.js +++ /dev/null @@ -1,25 +0,0 @@ -// components/MatchesSection.js - -import React from 'react'; -import { Box, Text } from 'ink'; - -function translateHomeAway(homeAway) { - if (homeAway === 'Home') return 'domicile'; - if (homeAway === 'Away') return 'extérieur'; - return homeAway; -} - -export function MatchesSection({ matches, teamColor, teamName, width }) { - return ( - - Matches à venir de {teamName} : - {!matches && Chargement des matchs...} - {matches && matches.length === 0 && Aucun match trouvé.} - {matches && matches.slice(0, 2).map((m, i) => ( - - {m.date} {m.time} - {teamName} vs {m.opponent} ({translateHomeAway(m.homeAway)}) - - ))} - - ); -} diff --git a/source/components/MemoSection.js b/source/components/MemoSection.js deleted file mode 100644 index 1df9923..0000000 --- a/source/components/MemoSection.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import { Box, Text } from 'ink'; - -export function MemoSection({ latestMemo, width, height }) { - const lines = latestMemo.split('\n'); - const maxLines = Math.max(height - 28, 4); - return ( - - Liste de courses - {lines.slice(0, maxLines).map((line, index) => ( - {line} - ))} - - ); -} \ No newline at end of file diff --git a/source/components/TaskTroveSection.js b/source/components/TaskTroveSection.js deleted file mode 100644 index 9f6acb0..0000000 --- a/source/components/TaskTroveSection.js +++ /dev/null @@ -1,36 +0,0 @@ -// components/TaskTroveSection.js - -import React from 'react'; -import { Box, Text } from 'ink'; - -function renderTaskTroveList(tasks) { - if (!tasks) { - return Chargement des tâches...; - } - - if (tasks.length === 0) { - return Aucune tâche à afficher.; - } - - return ( - - {tasks.map((task, index) => { - const color = task.priority === 1 ? 'red' : task.priority === 2 ? 'yellow' : 'white'; - return ( - - - {task.title} - - ); - })} - - ); -} - -export function TaskTroveSection({ tasks, width }) { - return ( - - To-Do List - {renderTaskTroveList(tasks)} - - ); -} \ No newline at end of file diff --git a/source/components/WeatherSection.js b/source/components/WeatherSection.js deleted file mode 100644 index 3028ac1..0000000 --- a/source/components/WeatherSection.js +++ /dev/null @@ -1,28 +0,0 @@ -// components/WeatherSection.js - -import React from 'react'; -import { Box, Text } from 'ink'; -import { weatherCodeMap } from '../utils/weatherCodes.js'; - -function renderWeather(location, weather) { - if (!weather) return {location}: Loading weather...; - - const weatherInfo = weatherCodeMap[weather.weathercode] || { desc: 'Unknown', color: 'white' }; - - return ( - - {location}: {weatherInfo.desc},{' '} - {weather.temperature}°C (Vent : {weather.windspeed} km/h) - - ); -} - -export function WeatherSection({ weatherNancy, weatherParis, width }) { - const flexDirection = width >= 60 ? "row" : "column"; - return ( - - {renderWeather('Nancy', weatherNancy)} - {renderWeather('Paris', weatherParis)} - - ); -} diff --git a/source/config.js b/source/config.js deleted file mode 100644 index 7cdc329..0000000 --- a/source/config.js +++ /dev/null @@ -1,12 +0,0 @@ -export const locations = { - Nancy: { latitude: 48.6921, longitude: 6.1844 }, - Paris: { latitude: 48.8566, longitude: 2.3522 } -}; - -export const INTER_ID = 6684; // SC Internacional team id -export const PARIS_ID = 1045; // Paris FC team id - -export const TASKTROVE_API = 'https://tasktrove.couraud.xyz/api/v1/tasks'; -export const TASKTROVE_TOKEN = 'eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGFza3Ryb3ZlIiwiaXNzIjoibWVtb3MiLCJzdWIiOiIzIiwiYXVkIjpbInVzZXIuYWNjZXNzLXRva2VuIl0sImlhdCI6MTc1OTk5MjI0N30.666jJ97j9a3d8c3a2a2a2a2a2a2a2a2a2a2a2a2a2a2'; - -export const FOOTBALL_API_TOKEN = "1535f68086e542528841b5e276f50b45"; diff --git a/source/hooks/useDeviceInfo.js b/source/hooks/useDeviceInfo.js deleted file mode 100644 index e41267d..0000000 --- a/source/hooks/useDeviceInfo.js +++ /dev/null @@ -1,34 +0,0 @@ -// hooks/useDeviceInfo.js - -import { useState, useEffect } from 'react'; - -async function fetchDeviceInfo() { - const url = 'http://192.168.0.19:19837/device-info'; - const response = await fetch(url); - if (!response.ok) throw new Error('Erreur HTTP ' + response.status); - return response.json(); -} - -export function useDeviceInfo() { - const [deviceInfo, setDeviceInfo] = useState(null); - const [deviceError, setDeviceError] = useState(null); - - async function updateDeviceInfo() { - try { - const data = await fetchDeviceInfo(); - setDeviceInfo(data); - setDeviceError(null); - } catch (_) { - setDeviceError("Impossible de récupérer les informations du device"); - setDeviceInfo(null); - } - } - - useEffect(() => { - updateDeviceInfo(); - const interval = setInterval(updateDeviceInfo, 60000); - return () => clearInterval(interval); - }, []); - - return { deviceInfo, deviceError }; -} diff --git a/source/hooks/useLatestMemo.js b/source/hooks/useLatestMemo.js deleted file mode 100644 index 60ff288..0000000 --- a/source/hooks/useLatestMemo.js +++ /dev/null @@ -1,54 +0,0 @@ -// hooks/useLatestMemo.js - -import { useState, useEffect } from 'react'; - -function formatMemoContent(markdownContent) { - if (!markdownContent) return ""; - return markdownContent.split('\n').map(line => { - const taskItemMatch = line.match(/^-\s*\[( |x|X)\]\s*/); - if (taskItemMatch) { - return '- ' + line.slice(taskItemMatch[0].length); - } - return line; - }).join('\n'); -} - -async function fetchLatestMemo() { - const url = "https://memos.couraud.xyz/api/v1/memos?page=1&perPage=1"; - try { - const response = await fetch(url, { - headers: { - Authorization: "Bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoiZ3JvY2VyaWVzIiwiaXNzIjoibWVtb3MiLCJzdWIiOiIyIiwiYXVkIjpbInVzZXIuYWNjZXNzLXRva2VuIl0sImlhdCI6MTc2MDI3NzQwMX0.H8m6LSaav7cuiQgt_rrzB7Fx4UM7Un11M2S0L5JJfPc" - } - }); - if (!response.ok) { - throw new Error(`HTTP error ${response.status}`); - } - const json = await response.json(); - - const memosArray = json.memos; - if (memosArray && memosArray.length > 0) { - return formatMemoContent(memosArray[0].content); - } - return "Aucune note trouvée."; - } catch (error) { - return `Erreur lors de la récupération de la note: ${error.message}`; - } -} - -export function useLatestMemo() { - const [latestMemo, setLatestMemo] = useState("Chargement de la dernière note..."); - - async function updateMemo() { - const memo = await fetchLatestMemo(); - setLatestMemo(memo); - } - - useEffect(() => { - updateMemo(); - const interval = setInterval(updateMemo, 60000); - return () => clearInterval(interval); - }, []); - - return { latestMemo }; -} diff --git a/source/hooks/useMatches.js b/source/hooks/useMatches.js deleted file mode 100644 index a0aa7e6..0000000 --- a/source/hooks/useMatches.js +++ /dev/null @@ -1,58 +0,0 @@ -// hooks/useMatches.js - -import { useState, useEffect } from 'react'; -import { formatDateTimeUTC } from '../utils/dateUtils.js'; -import { FOOTBALL_API_TOKEN } from '../config.js'; - -async function fetchScheduledMatches(teamId) { - const url = `https://api.football-data.org/v4/teams/${teamId}/matches?status=SCHEDULED`; - try { - const response = await fetch(url, { - headers: { "X-Auth-Token": FOOTBALL_API_TOKEN } - }); - const data = await response.json(); - if (!data.matches) return []; - return data.matches.map(match => { - let opponent, homeAway; - if (match.homeTeam.id === teamId) { - opponent = match.awayTeam.name; - homeAway = 'Home'; - } else if (match.awayTeam.id === teamId) { - opponent = match.homeTeam.name; - homeAway = 'Away'; - } else { - return null; - } - const { date, time } = formatDateTimeUTC(match.utcDate); - return { date, time, opponent, homeAway }; - }).filter(Boolean); - } catch { - return []; - } -} - -export function useMatches(teamIds) { - // teamIds is an object like { inter: 6684, paris: 1045 } - const [matchesInter, setMatchesInter] = useState(null); - const [matchesParis, setMatchesParis] = useState(null); - - async function updateMatchesData() { - try { - const [interMatches, parisMatches] = await Promise.all([ - fetchScheduledMatches(teamIds.inter), - fetchScheduledMatches(teamIds.paris) - ]); - setMatchesInter(interMatches); - setMatchesParis(parisMatches); - } catch (_) { } - } - - useEffect(() => { - updateMatchesData(); - const interval = setInterval(updateMatchesData, 60000); - return () => clearInterval(interval); - }, [teamIds]); - - - return { matchesInter, matchesParis }; -} diff --git a/source/hooks/useTaskTroveTasks.js b/source/hooks/useTaskTroveTasks.js deleted file mode 100644 index 2071353..0000000 --- a/source/hooks/useTaskTroveTasks.js +++ /dev/null @@ -1,54 +0,0 @@ -// hooks/useTaskTroveTasks.js - -import { useState, useEffect } from 'react'; -import { TASKTROVE_API, TASKTROVE_TOKEN } from '../config.js'; - -async function fetchTaskTroveTasks() { - try { - const response = await fetch(TASKTROVE_API, { - headers: { - Authorization: `Bearer ${TASKTROVE_TOKEN}` - } - }); - - if (!response.ok) return []; - - const data = await response.json(); - const tasks = data.tasks || []; - const today = new Date().toISOString().split('T')[0]; - - return tasks - .filter(task => { - if (task.completed) return false; - const isDueToday = task.dueDate === today; - const isP1 = task.priority === 1; - const isP2 = task.priority === 2; - return isDueToday || isP1 || isP2; - }) - .map(task => ({ - title: task.title, - priority: task.priority, - dueDate: task.dueDate - })); - - } catch (err) { - return []; - } -} - -export function useTaskTroveTasks() { - const [tasks, setTasks] = useState(null); - - async function updateTasks() { - const tsks = await fetchTaskTroveTasks(); - setTasks(tsks); - } - - useEffect(() => { - updateTasks(); - const interval = setInterval(updateTasks, 60000); - return () => clearInterval(interval); - }, []); - - return { tasks }; -} diff --git a/source/hooks/useTerminalSize.js b/source/hooks/useTerminalSize.js deleted file mode 100644 index 90f1bb9..0000000 --- a/source/hooks/useTerminalSize.js +++ /dev/null @@ -1,22 +0,0 @@ -// hooks/useTerminalSize.js - -import { useState, useEffect } from 'react'; -import { useStdout } from 'ink'; - -export function useTerminalSize() { - const { stdout } = useStdout(); - const [size, setSize] = useState({ width: stdout.columns, height: stdout.rows }); - - useEffect(() => { - if (!stdout) return; - function onResize() { - setSize({ width: stdout.columns, height: stdout.rows }); - } - stdout.on('resize', onResize); - return () => { - stdout.off('resize', onResize); - }; - }, [stdout]); - - return size; -} diff --git a/source/hooks/useWeather.js b/source/hooks/useWeather.js deleted file mode 100644 index 44b48bc..0000000 --- a/source/hooks/useWeather.js +++ /dev/null @@ -1,35 +0,0 @@ -// hooks/useWeather.js - -import { useState, useEffect } from 'react'; -import { locations } from '../config.js'; - -async function fetchWeather(lat, lon) { - const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t_weather=true&temperature_unit=celsius&timezone=Europe/Paris`; - const response = await fetch(url); - const data = await response.json(); - return data.current_weather; -} - -export function useWeather() { - const [weatherNancy, setWeatherNancy] = useState(null); - const [weatherParis, setWeatherParis] = useState(null); - - async function updateWeatherData() { - try { - const [nancy, paris] = await Promise.all([ - fetchWeather(locations.Nancy.latitude, locations.Nancy.longitude), - fetchWeather(locations.Paris.latitude, locations.Paris.longitude) - ]); - setWeatherNancy(nancy); - setWeatherParis(paris); - } catch (_) { } - } - - useEffect(() => { - updateWeatherData(); - const interval = setInterval(updateWeatherData, 60000); - return () => clearInterval(interval); - }, []); - - return { weatherNancy, weatherParis }; -} diff --git a/source/utils/dateUtils.js b/source/utils/dateUtils.js deleted file mode 100644 index 1ce2762..0000000 --- a/source/utils/dateUtils.js +++ /dev/null @@ -1,22 +0,0 @@ -// utils/dateUtils.js - -export function formatTime(date) { - return date.toLocaleTimeString('fr-FR', { hour12: false }); -} - -export function formatDate(date) { - return date.toLocaleDateString('fr-FR', { - weekday: 'long', - year: 'numeric', - month: 'long', - day: 'numeric' - }); -} - -export function formatDateTimeUTC(utcString) { - const date = new Date(utcString); - return { - date: formatDate(date), - time: formatTime(date) - }; -} diff --git a/source/utils/weatherCodes.js b/source/utils/weatherCodes.js deleted file mode 100644 index 356740a..0000000 --- a/source/utils/weatherCodes.js +++ /dev/null @@ -1,32 +0,0 @@ -// utils/weatherCodes.js - -export const weatherCodeMap = { - 0: { desc: 'Ciel clair', color: 'yellow' }, - 1: { desc: 'Principalement clair', color: 'yellow' }, - 2: { desc: 'Partiellement nuageux', color: 'cyan' }, - 3: { desc: 'Couvert', color: 'gray' }, - 45: { desc: 'Brouillard', color: 'gray' }, - 48: { desc: 'Brouillard givrant', color: 'gray' }, - 51: { desc: 'Bruine légère', color: 'blue' }, - 53: { desc: 'Bruine modérée', color: 'blue' }, - 55: { desc: 'Bruine dense', color: 'blue' }, - 56: { desc: 'Bruine verglaçante légère', color: 'blue' }, - 57: { desc: 'Bruine verglaçante dense', color: 'blue' }, - 61: { desc: 'Pluie faible', color: 'blue' }, - 63: { desc: 'Pluie modérée', color: 'blue' }, - 65: { desc: 'Pluie forte', color: 'blue' }, - 66: { desc: 'Pluie verglaçante légère', color: 'blue' }, - 67: { desc: 'Pluie verglaçante forte', color: 'blue' }, - 71: { desc: 'Chute de neige légère', color: 'white' }, - 73: { desc: 'Chute de neige modérée', color: 'white' }, - 75: { desc: 'Chute de neige forte', color: 'white' }, - 77: { desc: 'Grains de neige', color: 'white' }, - 80: { desc: 'Averses de pluie faibles', color: 'blue' }, - 81: { desc: 'Averses de pluie modérées', color: 'blue' }, - 82: { desc: 'Averses de pluie violentes', color: 'blue' }, - 85: { desc: 'Averses de neige faibles', color: 'white' }, - 86: { desc: 'Averses de neige fortes', color: 'white' }, - 95: { desc: 'Orage', color: 'magenta' }, - 96: { desc: 'Orage avec faible grêle', color: 'magenta' }, - 99: { desc: 'Orage avec forte grêle', color: 'magenta' } -};