Skip to content

Commit 7c4c191

Browse files
Farshad SepehrAraFarshad SepehrAra
authored andcommitted
handleSubmitDaysAfterNow
1 parent 99d62fb commit 7c4c191

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cSpell.words": [
3+
"miscfeat",
34
"noopener",
45
"noreferrer",
56
"samplereact",

app/miscfeat/page.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
import { useState } from 'react';
44

55
export default function MiscFeat() {
6-
const [days, setDays] = useState('');
6+
const [days, setDays] = useState(0);
7+
const [daysAfterNow, setDaysAfterNow] = useState('');
78

89
function handleDaysChange(e) {
910
setDays(e.target.value);
1011
}
1112

12-
async function handleSubmit(e) {
13+
async function handleSubmitDaysAfterNow(e) {
1314
e.preventDefault();
15+
const rsp = await fetch(`/api/miscfeat/daysAfterNow?days=${days}`);
16+
const res = await rsp.json()
17+
setDaysAfterNow(new Date(res.theTime).toString());
1418
}
1519

1620
return (
1721
<main className="flex min-h-screen flex-col items-center justify-between p-24">
18-
<form onSubmit={handleSubmit} className="grid grid-cols-[1fr_3fr] gap-4">
22+
<form onSubmit={handleSubmitDaysAfterNow} className="grid grid-cols-[1fr_3fr] gap-4 place-items-center justify-items-stretch">
1923
<label htmlFor='txtDays'>Days:</label>
2024
<input id='txtDays' type="text" value={days} onChange={handleDaysChange} />
2125
<button className="col-start-2 py-2 px-4 bg-blue-500 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-opacity-75">Days After Now</button>
26+
<label htmlFor='txtDaysAfterNow'>Result:</label>
27+
<input type="text" id='txtDaysAfterNow' value={daysAfterNow} readOnly />
2228
</form>
2329
</main>
2430
)

0 commit comments

Comments
 (0)