mirror of
https://github.com/hex248/sprint.git
synced 2026-02-09 02:33:02 +00:00
display work time in issue detail pane
This commit is contained in:
30
packages/frontend/src/lib/server/timer/getInactive.ts
Normal file
30
packages/frontend/src/lib/server/timer/getInactive.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function getInactive({
|
||||
issueId,
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
issueId: number;
|
||||
} & ServerQueryInput) {
|
||||
const url = new URL(`${getServerURL()}/timer/get-inactive`);
|
||||
url.searchParams.set("issueId", `${issueId}`);
|
||||
|
||||
const csrfToken = getCsrfToken();
|
||||
const headers: HeadersInit = {};
|
||||
if (csrfToken) headers["X-CSRF-Token"] = csrfToken;
|
||||
|
||||
const res = await fetch(url.toString(), {
|
||||
headers,
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.text();
|
||||
onError?.(error || `failed to get timers (${res.status})`);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
onSuccess?.(data, res);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export { end } from "@/lib/server/timer/end";
|
||||
export { get } from "@/lib/server/timer/get";
|
||||
export { getInactive } from "@/lib/server/timer/getInactive";
|
||||
export { list } from "@/lib/server/timer/list";
|
||||
export { toggle } from "@/lib/server/timer/toggle";
|
||||
|
||||
@@ -40,3 +40,13 @@ export function getServerURL() {
|
||||
}
|
||||
return serverURL;
|
||||
}
|
||||
|
||||
export function formatTime(ms: number): string {
|
||||
const totalSeconds = Math.floor(ms / 1000);
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user