Commit 7a5409ce authored by HSX's avatar HSX
Browse files

use react

parent ba810fe8
Pipeline #60 failed with stages
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# web-shell-react
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin http://xlab.zju.edu.cn/git/HSX/web-shell-react.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](http://xlab.zju.edu.cn/git/HSX/web-shell-react/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
# web-shell 实习期项目
## Syntax
- ```add``` title content deadline : 添加标题为title,内容为content,截至时间为dealine代办事件
**deadline should be the format "yyyy/MM/dd"**
- ```modify``` id title = newtitle : 修改id条事件的title/ content/ deadline
**title be substitued by content or deadline, and space is allowed**
- ```resolve``` id : 完成id条事件,完成事件字体变为灰色
- ```delete``` id : 删除id条事件
- ```update``` : 根据代办事件的deadline和当前时间,若超过时间则字体变为红色
\ No newline at end of file
This diff is collapsed.
{
"name": "web-shell-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>TODO List</title>
<link rel="stylesheet" href="../src/style/style.css">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">
<div class="todo-app">
<h1 id="title">Todo List.<div id="border"></div></h1>
<!-- shell command input part -->
<div id="todo-input"></div>
<!-- current login time -->
<div class="todo-time">
<p><span id="datetime"></span></p>
<script>
let dt = new Date();
document.getElementById("datetime").innerHTML = dt.toLocaleString();
</script>
</div>
<!-- todo card display part -->
<div class="todo-body" id="list-todo">
<div class="todo-record" id="todo-00" x-resolved="0">
<strong class="todo-record-title">title</strong>
<span>&nbsp;(id=0)</span>
<p class="todo-record-content">
content
</p>
<i class="todo-record-duedate">Remaining time: ???</i>
</div>
</div>
</div>
</div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './pages/App';
import "./style/style.css"
ReactDOM.render(<App />, document.getElementById("todo-input"));
\ No newline at end of file
// @ts-check
/// <reference path="./shim.d.ts" />
/// <reference path="./date-fns.d.ts" />
import { format, compareAsc, parse } from 'https://esm.run/date-fns';
import React, { Component } from "react";
import "../style/style.css"
var id = 1;
/**
* @param {number} id
* @param {string} title
* @param {string} content
* @param {Date} deadline
*/
function addTodoToDOM(id, title, content, deadline, resolve = 0) {
const newId = "todo-" + id;
const todoElem = document.createElement("div");
const todoTitleElem = document.createElement("strong");
const todoIdElem = document.createElement("span");
const todoContentElem = document.createElement("p");
const todoDeadlineElem = document.createElement("i");
todoElem.setAttribute("class", "todo-record");
todoTitleElem.setAttribute("class", "todo-record-title");
todoContentElem.setAttribute("class", "todo-record-content");
todoDeadlineElem.setAttribute("class", "todo-record-duedate");
todoElem.id = newId;
todoTitleElem.textContent = title;
todoIdElem.textContent = " (id=" + id + ")";
todoContentElem.textContent = content;
const formatdate = format(deadline, 'yyyy/MM/dd');
todoDeadlineElem.textContent = formatdate;
todoElem.appendChild(todoTitleElem);
todoElem.appendChild(todoIdElem);
todoElem.appendChild(todoContentElem);
todoElem.appendChild(todoDeadlineElem);
const parentElem = document.getElementById("list-todo");
if (!parentElem) {
alert("Failed to get input element");
return;
}
parentElem.appendChild(todoElem);
localStorage.setItem("todo-" + id, JSON.stringify({ "title": title, "content": content, "deadline": formatdate, "resolve": resolve}));
}
/**
* @param {number} id
*/
function resolveTodo(id) {
const todo = document.getElementById("todo-" + id);
if (!todo) {
return;
}
todo.setAttribute("x-resolved", "1");
todo.style.color = "gray"; // set color to gray
let item = JSON.parse(localStorage.getItem("todo-" + id) || '0');
localStorage.setItem("todo-" + id, JSON.stringify({"title": item.title, "content": item.content, "deadline": item.deadline, "resolve": 1}));
}
function deleteTodo(id) {
const todo = document.getElementById("todo-" + id);
if(!todo) {
return;
}
if(todo.parentNode)
{
todo.parentNode.removeChild(todo);
}
localStorage.removeItem("todo-" + id);
}
/**
* @param {number} id
*/
function updateOverdueStatus(id) {
const todo = document.getElementById("todo-" + id);
if (!todo) {
return;
}
if (todo.getAttribute("x-resolved") === "1") {
return;
}
var currentDate = new Date();
const todoDeadlineElemSet = todo.getElementsByTagName("i"); // ref: index.html example todo div
if (todoDeadlineElemSet.length !== 1) {
alert("Failed to get deadline element: unexpected number of <i> elements");
}
const todoDeadline = todoDeadlineElemSet[0].textContent; // get text content of element
if(!todoDeadline) {
return;
}
const deadline = parse(todoDeadline, 'yyyy/MM/dd', currentDate); // use date-fns here to parse date string
if (compareAsc(deadline, currentDate) === -1) {
todo.style.color = "red"; // set color to red
}
}
class Input extends Component {
constructor(props) {
super(props);
this.inputKeyUp = this.inputKeyUp.bind(this);
}
inputKeyUp = e => {
if(e.keyCode === 13) {
const addTodoRegex = /^add\s+(\w+)\s+(\w+)\s+(\d+)\/(\d+)\/(\d+)$/;
const modifyTodoRegex = /^modify\s+(\d+)\s+(\w+)\s*=\s*(.+)/;
const resolveTodoRegex = /^resolve\s+(\d+)\s*/;
const deleteTodoRegex = /^delete\s+(\d+)\s*/;
const updateTodoRegex = /^update\s*/;
const shellInputElem = /** @type {HTMLInputElement | null} */ (document.getElementById("input-todo"));
if (shellInputElem === null) {
alert("Failed to get input element");
return;
}
const inputContent = shellInputElem.value;
if (addTodoRegex.test(inputContent)) {
let match = inputContent.match(addTodoRegex);
var deadline = new Date();
if(!match || match.length !== 6) // immediately test the possible NULL variable
{
alert("add operation input format is wrong");
return;
}
deadline.setFullYear(parseInt(match[3]), parseInt(match[4]) - 1, parseInt(match[5]));
addTodoToDOM(id++, match[1], match[2], deadline);
localStorage.setItem("todo-0", JSON.stringify({"id": id})); // 每次修改id,同时在localstorage对应位置修改id的值
}
else if (modifyTodoRegex.test(inputContent)) {
let match = inputContent.match(modifyTodoRegex);
if(!match || match.length !== 4)
{
alert("modify operation input format is wrong");
return;
}
match[3] = match[3].trim(); // delete the front and back spaces
var modifyElem = document.getElementById("todo-" + match[1]);
if(!modifyElem) {
alert("Failed to get modify element");
return; // to prevent future error
}
match[2].toLocaleLowerCase(); // upper and lower input texts are both supported
if(match[2] === "title") {
const elem = modifyElem.getElementsByTagName("strong"); // getElementByTagName returns an array, so elem should be used with index
elem[0].textContent = match[3];
let item = JSON.parse(localStorage.getItem("todo-" + match[1]) || '0');
localStorage.setItem("todo-" + match[1], JSON.stringify({"title": match[3], "content": item.content, "deadline": item.deadline, "resolve": item.resolve}));
}
else if(match[2] === "content") {
const elem = modifyElem.getElementsByTagName("p");
elem[0].textContent = match[3];
let item = JSON.parse(localStorage.getItem("todo-" + match[1]) || '0');
localStorage.setItem("todo-" + match[1], JSON.stringify({"title": item.title, "content": match[3], "deadline": item.deadline, "resolve": item.resolve}));
} else if(match[2] === "deadline"){
const elem = modifyElem.getElementsByTagName("i");
var date = match[3].split("/");
if(date.length !== 3)
{
alert("duedate input format is wrong");
return;
}
date[0] = date[0].trim(); // spaces are allowed in input date format " yyyy / MM / dd "
date[1] = date[1].trim();
date[2] = date[2].trim();
elem[0].textContent = date[0] + "/" + date[1] + "/" + date[2];
let item = JSON.parse(localStorage.getItem("todo-" + match[1]) || '0');
localStorage.setItem("todo-" + match[1], JSON.stringify({"title": item.title, "content": item.content, "deadline": elem[0].textContent, "resolve": item.resolve}));
}
}
else if(resolveTodoRegex.test(inputContent)) {
let match = inputContent.match(resolveTodoRegex);
if(!match || match.length !== 2)
{
alert("Failed to get resolve element");
return;
}
resolveTodo(parseInt(match[1]));
}
else if(deleteTodoRegex.test(inputContent)) {
let match = inputContent.match(deleteTodoRegex);
if(!match || match.length !== 2)
{
alert("Failed to get delete element");
return;
}
deleteTodo(parseInt(match[1]));
}
else if(updateTodoRegex.test(inputContent)) {
for(var i = 1; i < id; i++) {
updateOverdueStatus(i);
}
}
else {
var s = "operation \"" + inputContent.split(" ")[0] + "\" is not supported";
alert(s);
}
}
}
render() {
return (
<div className="todo-header">
<input className="todo-header-input" id="input-todo" placeholder="Title Content DueDate"
onKeyUp={this.inputKeyUp}
></input>
</div>
);
}
}
function App() {
if(localStorage.getItem("todo-0")) { // 取回localstorage中存储的全局变量id
let item = JSON.parse(localStorage.getItem("todo-0") || '0');
id = parseInt(item.id);
}
for(let i = 1; i < id; i++) {
let elem = localStorage.getItem("todo-" + i);
if(elem) {
let item = JSON.parse(elem);
addTodoToDOM(i, item.title, item.content, parse(item.deadline, 'yyyy/MM/dd', new Date()), item.resolve);
if(item.resolve) {
resolveTodo(i);
}
else {
updateOverdueStatus(i);
}
}
}
return (
<Input />
);
}
export default App;
\ No newline at end of file
This diff is collapsed.
declare module "https://esm.run/date-fns" {
export * from "date-fns";
}
body {
background-image: linear-gradient(100deg, #c8e8fc, #fbceda);
transition: 0.3s linear;
overflow: auto;
}
.todo-app {
/* 使用 margin: auto 实现这个元素的水平居中(但内容仍然是左对齐) */
width: 1200px;
margin: 100px auto;
}
/* 标题字体样式设置 */
#title {
font-family: 'Times New Roman', Times, serif;
font-size: 5rem;
white-space: pre;
overflow: hidden;
letter-spacing: 0.30rem;
margin: 25px auto;
width: 25rem;
}
/* 时间样式设计 */
.todo-time {
width: 10rem;
margin: 0 auto;
}
#datetime {
font-family: 'Work Sans', sans-serif;
font-size: 1rem;
min-height: 10vh;
width: 100%;
}
div.todo-header {
width: 800px;
margin: 0 auto;
}
.todo-body {
margin: 5px auto;
margin-top: 0px;
}
.todo-record {
width: 56rem;
font-size: 1.2rem;
padding:1rem 1rem;
margin:1rem auto;
transition:all 500ms ease;
color:#41403E;
letter-spacing:1px;
outline:none;
box-shadow: 20px 38px 34px -26px hsla(0,0%,0%,.2);
border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
border:solid 0.2rem #41403E;
border-left: none;
border-right: none;
border-bottom: none;
background: transparent;
background-image: url('wave.png');
background-size: 100% 100%;
background-repeat: no-repeat;
}
.todo-record:nth-child(1) {
margin-top: 0px;
}
.todo-record:hover {
box-shadow:2px 8px 4px -6px hsla(0,0%,0%,.3);
}
.todo-record .todo-record-title, .todo-record span {
font-family: Gabriola;
font-size: 2rem;
letter-spacing: 0.2rem;
font-weight: bold;
}
.todo-record .todo-record-content {
font-family: 'Lucida Handwriting';
font-size: 1.8rem;
text-indent: 1rem;
margin-top: 0;
margin-bottom: 1rem;
}
.todo-record .todo-record-content::first-letter {
text-transform: uppercase;
font-size: 2rem;
}
.todo-record .todo-record-duedate {
font-family: 'Work Sans', sans-serif;
font-size: 1rem;
min-height: 10vh;
width: 100%;
}
.todo-record[x-resolved="1"] .todo-record-title,
.todo-record[x-resolved="1"] span,
.todo-record[x-resolved="1"] .todo-record-content,
.todo-record[x-resolved="1"] .todo-record-duedate {
color: gray;
text-decoration: line-through;
}
/* 输入框 */
.todo-header-input {
padding: 10px;
font-size: 17px;
border: none;
outline: none;
text-indent: 5px;
border-radius: 17px;
transition: background-color 300ms ease-in-out;
width: 800px;
background-color: #c2c6c9;
color: #1a150e;
}
.todo-header-input::placeholder {
color: #1a150e;
/* 设置不透明度 */
opacity: 0.7;
}
.todo-header-input:hover {
background-color: #919699;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment