Skip to content

Commit

Permalink
目標作成後に正しい値でモーダルをリセット
Browse files Browse the repository at this point in the history
  • Loading branch information
MurakawaTakuya committed Jan 8, 2025
1 parent 320e3fc commit dd018ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ For More information, please refer to the Top Page.
[TODO REAL](https://todo-real-c28fa.web.app/)

## Getting Started
First run this command to install required packages:

```bash
npm install
```

Then, run the development server:
Run the development server:

```bash
npm run dev
```
This includes `npm i` and `next dev`, so you don't have to care about refreshing packages.

## Learn More
To learn more about Next.js, take a look at the following resources:
Expand Down Expand Up @@ -46,7 +41,7 @@ Then, you can start the emulator by running the following command if you have ac
cd .\functions\
npm run emu
```
This command includes `firebase emulators:start` and `npx tsc --watch` which watches the files and restarts the server when the files are changed.
This command includes `npm i`, `firebase emulators:start` and `npx tsc --watch` which watches the files and restarts the server when the files are changed.

if you don't want ts-node to watch the files, just use
```
Expand Down
4 changes: 2 additions & 2 deletions src/Components/GoalModal/CopyGoalAfterPostButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default function CopyGoalAfterPostButton({
onClick={() => {
setOpen(true);
showSnackBar({
message: "1日後の同じ時間で同じ目標を作成できます",
type: "success",
message: "明日の同じ時間で同じ目標を作成できます",
type: "normal",
});
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/GoalModal/CopyGoalButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function CopyModalButton({
onClick={() => {
setOpen(true);
showSnackBar({
message: "1日後の同じ時間で同じ目標を作成できます",
type: "success",
message: "明日の同じ時間で同じ目標を作成できます",
type: "normal",
});
}}
sx={{ cursor: "pointer", fontSize: "23px" }}
Expand Down
24 changes: 14 additions & 10 deletions src/Components/GoalModal/CreateGoalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ export default function CreateGoalModal({

const { user } = useUser();

const resetDeadline = () => {
// 次の日の23時に設定
const nextDay = new Date();
nextDay.setDate(nextDay.getDate() + 1);
nextDay.setHours(23, 0, 0, 0);
const localNextDay = new Date(
nextDay.getTime() - nextDay.getTimezoneOffset() * 60000
);
setDeadline(localNextDay.toISOString().slice(0, 16));
};

useEffect(() => {
if (defaultText) {
setText(defaultText);
Expand All @@ -42,17 +53,10 @@ export default function CreateGoalModal({
const localDate = new Date(
convertedDate.getTime() - convertedDate.getTimezoneOffset() * 60000
);
localDate.setDate(localDate.getDate() + 1); // 1日後にする
localDate.setDate(localDate.getDate() + 1); // 明日にする
setDeadline(localDate.toISOString().slice(0, 16));
} else {
// 初期値の指定が無い場合は次の日の23時に設定
const nextDay = new Date();
nextDay.setDate(nextDay.getDate() + 1);
nextDay.setHours(23, 0, 0, 0);
const localNextDay = new Date(
nextDay.getTime() - nextDay.getTimezoneOffset() * 60000
);
setDeadline(localNextDay.toISOString().slice(0, 16));
resetDeadline();
}
}, [defaultText, defaultDeadline]);

Expand All @@ -75,7 +79,7 @@ export default function CreateGoalModal({
triggerDashBoardRerender();

setText("");
setDeadline("");
resetDeadline();
setOpen(false);
} catch (error: unknown) {
console.error("Error creating goal:", error);
Expand Down

0 comments on commit dd018ad

Please sign in to comment.