|
1 | 1 | import { useRequest } from "ahooks";
|
2 | 2 | import { useEffect, useState } from "react";
|
| 3 | +import { useStatus } from "~/Services/Status"; |
3 | 4 | import { StatusEnum } from "~/Services/Status.Entities";
|
4 | 5 | import { Models } from "~/Services/Status.Models";
|
5 | 6 | import { useAccessToken } from "../Auth/useAccessToken";
|
@@ -172,6 +173,7 @@ export function useEditForm(event: Models.IEvent) {
|
172 | 173 | }, [start, end]);
|
173 | 174 |
|
174 | 175 | const getToken = useAccessToken();
|
| 176 | + const { DB, Update } = useStatus(); |
175 | 177 |
|
176 | 178 | const { runAsync, loading } = useRequest(async () => {
|
177 | 179 | if (![setTitle(), setType(), setUpdate(), setStatus(), setStart(), setEnd(), setUpdateAt()].every(Boolean)) {
|
@@ -223,7 +225,27 @@ export function useEditForm(event: Models.IEvent) {
|
223 | 225 | throw new Error("Failed to update event: " + await raw.text());
|
224 | 226 | }
|
225 | 227 |
|
226 |
| - window.location.reload(); |
| 228 | + const eventIndex = DB.Events.findIndex(e => e.Id === event.Id); |
| 229 | + if (eventIndex !== -1) { |
| 230 | + const updatedEvent = { ...DB.Events[eventIndex] }; |
| 231 | + updatedEvent.Title = title; |
| 232 | + updatedEvent.Type = type; |
| 233 | + updatedEvent.Status = status; |
| 234 | + updatedEvent.Start = start; |
| 235 | + updatedEvent.End = end; |
| 236 | + |
| 237 | + const newHistory: Models.IHistory = { |
| 238 | + Id: Math.max(...Array.from(updatedEvent.Histories).map(h => h.Id), 0) + 1, |
| 239 | + Message: update, |
| 240 | + Created: updateAt, |
| 241 | + Status: status, |
| 242 | + Event: updatedEvent |
| 243 | + }; |
| 244 | + updatedEvent.Histories.add(newHistory); |
| 245 | + |
| 246 | + DB.Events[eventIndex] = updatedEvent; |
| 247 | + Update(); |
| 248 | + } |
227 | 249 | }, {
|
228 | 250 | manual: true
|
229 | 251 | });
|
|
0 commit comments