Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

todopageのエラーを修正 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions pages/edit/todopage.jsx

This file was deleted.

96 changes: 96 additions & 0 deletions pages/edit/todopage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, {useRef, useEffect, useState} from 'react';
import axios from 'axios';

const todo_page = () => {
const inputEl1 = useRef(null);
const inputEl2 = useRef(null);
const inputEl3 = useRef(null);

const handleClick = () => {
const cur_time = new Date()
const getTime = cur_time.getTime();
const getDdl = Date.parse(inputEl2.current.value);
if (inputEl1.current.value.length !== 0 && getTime < getDdl) {
axios({
method: 'POST',
url: 'https://api.digital-future.jp/task',
data: {name: inputEl1.current.value, deadline: inputEl2.current.value, is_finished: false}
}).then(response => console.log('response body:', response.data.tasks));
}
}

// const data = [{name: "finish my work", deadline: "2021-12-05", id: "1", is_finished: true}]

// eslint-disable-next-line react-hooks/rules-of-hooks
const [data, setData] = useState([]);

// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
const fetchData = async () => {
const result = await axios('https://api.digital-future.jp/task/read',);

setData(result.data.tasks);
};

fetchData();
}, []);


const handleOnchange = () => {
axios({
method: 'POST',
url: 'https://api.digital-future.jp/task/',
data: {id: inputEl3.current.id, is_finished: inputEl3.current.checked}
}).then(response => console.log('response body:', response.data.tasks));
}

console.log(data)
// @ts-ignore
const uuid = require("uuid")
if (data !== undefined && data !== null && data.length !== 0) {
console.log(data)
return (
<>
<div>
<input
ref={inputEl1}
type="text"
placeholder={"Enter your tasks here"}
/><br/>
<input
ref={inputEl2}
type="date"
/>
<button
onClick={handleClick}
>登録
</button>
{
data.map(item => (
<ul key={uuid.v4()}>
<li>
<input
ref={inputEl3}
id={item.id}
type="checkbox"
//チェックボックスの値が格納される
defaultChecked={false}
checked={item.is_finished}
//値が変わるときに呼ばれる関数
onChange={handleOnchange}
/>
<label className="todo-label" htmlFor={item.id}>
{item.name}&emsp;&emsp;&emsp;{item.deadline}
</label>
</li>
</ul>
)
)}
</div>
</>)
} else {
return (<></>)
}

}
export default todo_page;