From 8de55fd74542150317e4253951fb7270726ca785 Mon Sep 17 00:00:00 2001 From: haochengxu Date: Sun, 14 Jan 2024 00:14:32 +0800 Subject: [PATCH] add a new project tiny to track project progress --- pages/index.tsx | 29 +++- pages/play-lab.tsx | 17 +++ pages/projects/tiny/IterationDetail.tsx | 188 ++++++++++++++++++++++++ pages/projects/tiny/index.tsx | 91 ++++++++++++ pages/projects/tiny/types.tsx | 16 ++ 5 files changed, 334 insertions(+), 7 deletions(-) create mode 100644 pages/play-lab.tsx create mode 100644 pages/projects/tiny/IterationDetail.tsx create mode 100644 pages/projects/tiny/index.tsx create mode 100644 pages/projects/tiny/types.tsx diff --git a/pages/index.tsx b/pages/index.tsx index 62e8a75..5f32a78 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,5 @@ import Link from 'next/link'; +import { useState, useEffect } from 'react'; const IMAGE_NUMBER = 3; @@ -7,20 +8,34 @@ const indexStyle = { position: 'relative' as 'relative', backgroundSize: 'cover', backgroundRepeat: 'no-repeat', - backgroundImage: `url('/assets/photo/${Math.floor(Math.random() * IMAGE_NUMBER) + 1}.JPG')`, height: '100vh', }; +const blurStyle = { + backdropFilter: 'blur(5px)', + backgroundColor: 'rgba(255, 255, 255, 0.1)' +} + export default function Index() { + const [backgroundImage, setBackgroundImage] = useState(''); + + useEffect(() => { + setBackgroundImage(`url('/assets/photo/${Math.floor(Math.random() * IMAGE_NUMBER) + 1}.JPG')`); + }, []); + return ( <> -
+

- - Blog - +
+ + Blog + +
+ + PlayLab + +

diff --git a/pages/play-lab.tsx b/pages/play-lab.tsx new file mode 100644 index 0000000..45e98e8 --- /dev/null +++ b/pages/play-lab.tsx @@ -0,0 +1,17 @@ +// pages/play-lab.tsx 或 pages/play-lab/index.tsx + +import React from 'react' +import Link from 'next/link' + +const PlayLab = () => { + return ( +
+

Welcome to PlayLab!

+ + Go to Project Tracker + +
+ ) +} + +export default PlayLab \ No newline at end of file diff --git a/pages/projects/tiny/IterationDetail.tsx b/pages/projects/tiny/IterationDetail.tsx new file mode 100644 index 0000000..b2a4289 --- /dev/null +++ b/pages/projects/tiny/IterationDetail.tsx @@ -0,0 +1,188 @@ +import React, { useState } from "react"; +import { Project } from "./types"; + +interface Props { + // Define the props for your component here + project: Project; + updateProject: (project: Project) => void; +} + +const IterationDetail: React.FC = ({ + project: currentProject, + updateProject, +}) => { + const [timerId, setTimerId] = useState(null); + const [elapsedTime, setElapsedTime] = useState(0); + const [showPanel, setShowPanel] = useState(false); + + const [startTime, setStartTime] = useState(''); + const [isPaused, setIsPaused] = useState(false); + const [rating, setRating] = useState(1); + const [notes, setNotes] = useState(""); + + const startTimer = () => { + if (timerId !== null) return; + const id = setInterval(() => { + setElapsedTime((time) => time + 1); + }, 1000); + setTimerId(id); + }; + + const resumeTimer = () => { + const id = setInterval(() => { + setElapsedTime((prevTime) => prevTime + 1); + }, 1000); + setTimerId(id); + }; + + const pauseTimer = () => { + clearInterval(timerId); + setTimerId(null); + }; + + const submitIteration = () => { + if (!window.confirm(`你确定要完成这次${currentProject.name}吗?`)) { + return; + } + const newIteration = { + startTime: startTime, + elapsedTime: elapsedTime, + notes: notes, + quality: rating, + tags: [], + }; + + currentProject.iterations = currentProject.iterations ? [...currentProject.iterations, newIteration] : [newIteration]; + updateProject(Object.assign({}, currentProject)); + }; + + return ( +
+ {currentProject ? ( + <> +

+ {currentProject && currentProject.name} +

{" "} +
+ {currentProject.iterations && ( +

+ + 累积时间: + {Math.floor( + currentProject.iterations.reduce((prev, iteration) => { + return Number(iteration.elapsedTime) + prev; + }, 0) / 3600 + )} + 小时 + + + 累积次数: + {currentProject.iterations.length} + +

+ )} +
+ + {showPanel && ( +
+
+ + {startTime && ( + + )} + +

+ 评分: + setRating(Number(e.target.value))} + /> +

+

+ 笔记: +