From b1b613df67071873671d643e156c186e4fccfd14 Mon Sep 17 00:00:00 2001 From: Khairul Hidayat Date: Fri, 30 Aug 2024 04:34:05 +0700 Subject: [PATCH] feat: add datetime & weather --- package.json | 1 + pnpm-lock.yaml | 8 +++++ src/app.tsx | 80 +++++++++++++++++++++++++++++++++++++++++++++++++- src/main.css | 6 ++++ 4 files changed, 94 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 75c0213..d539158 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@tanstack/react-query": "^5.52.2", "clsx": "^2.1.1", + "dayjs": "^1.11.13", "lucide-react": "^0.436.0", "react": "^18.3.1", "react-dom": "^18.3.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d9094e..3baeb26 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: clsx: specifier: ^2.1.1 version: 2.1.1 + dayjs: + specifier: ^1.11.13 + version: 1.11.13 lucide-react: specifier: ^0.436.0 version: 0.436.0(react@18.3.1) @@ -722,6 +725,9 @@ packages: csstype@3.1.3: resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + dayjs@1.11.13: + resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==} + debug@4.3.6: resolution: {integrity: sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==} engines: {node: '>=6.0'} @@ -2127,6 +2133,8 @@ snapshots: csstype@3.1.3: {} + dayjs@1.11.13: {} + debug@4.3.6: dependencies: ms: 2.1.2 diff --git a/src/app.tsx b/src/app.tsx index 887df76..5096aed 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -4,6 +4,10 @@ import dotPattern from "@/assets/dotpattern.svg"; import logo from "@/assets/logo.svg"; import ParallaxView from "./components/parallax-view"; import ChatWindow from "./components/chat-window"; +import { useEffect, useState } from "react"; +import dayjs from "dayjs"; +import { useQuery } from "@tanstack/react-query"; +import { CloudSun, GitPullRequest } from "lucide-react"; const App = () => { return ( @@ -45,13 +49,14 @@ const App = () => { depth={0.005} className="absolute left-1/2 -bottom-[5%] w-full" > -
+
+
{
+ +

+ Furina artwork by{" "} + + Rine + +

+ +

+ + Fork{" "} + + Repo + +

+ +
@@ -68,4 +99,51 @@ const App = () => { ); }; +const Clock = () => { + const [time, setTime] = useState(new Date()); + const { data: weather } = useQuery({ + queryKey: ["forecast"], + queryFn: async () => { + const url = + "https://api.open-meteo.com/v1/forecast?latitude=-6.2297401&longitude=106.7469453¤t_weather=true"; + const res = await fetch(url); + if (!res.ok) { + throw new Error(res.statusText); + } + const data = await res.json(); + return data?.current_weather; + }, + }); + + useEffect(() => { + const interval = setInterval(() => { + setTime(new Date()); + }, 1000); + return () => clearInterval(interval); + }, []); + + return ( + +

{dayjs(time).format("dddd, DD MMM YYYY")}

+ +

+ {dayjs(time).format("hh:mm:ss")} +

+ + {weather ? ( +
+ +

+ {weather?.temperature} + °C +

+
+ ) : null} +
+ ); +}; + export default App; diff --git a/src/main.css b/src/main.css index 2cfda7a..25d6e12 100644 --- a/src/main.css +++ b/src/main.css @@ -1,7 +1,13 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap'); + @tailwind base; @tailwind components; @tailwind utilities; +html, body { + font-family: 'Poppins', sans-serif; +} + /* Chrome, Edge and Safari */ *::-webkit-scrollbar { height: 8px;