Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 36 additions & 2 deletions src/components/TicketList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from "react";
import type { AppSettings, JiraTicket } from "../lib/types";
import { fetchInProgressTickets, fetchDoneTickets, fetchTicketsByKeys, checkWorklogPermission } from "../lib/jira";
import { fetchInProgressTickets, fetchDoneTickets, fetchTicketsByKeys, checkWorklogPermission, addWorklog } from "../lib/jira";
import { useActiveTimer } from "../hooks/useActiveTimer";
import { saveSettings } from "../lib/storage";
import { TicketItem } from "./TicketItem";
Expand Down Expand Up @@ -41,6 +41,7 @@ export const TicketList = ({ settings, onSettingsChange, onTimeUpdate }: TicketL
const [showDone, setShowDone] = useState(false);
const [refreshing, setRefreshing] = useState(false);
const [elapsedTime, setElapsedTime] = useState("");
const [stoppingHidden, setStoppingHidden] = useState(false);

// DnD Sensors
const sensors = useSensors(
Expand Down Expand Up @@ -105,7 +106,33 @@ export const TicketList = ({ settings, onSettingsChange, onTimeUpdate }: TicketL

// Fetch today's time AFTER tickets load (doesn't block initial ticket display)

const handleStopHiddenTimer = async () => {
if (!activeTimer) return;
setStoppingHidden(true);
try {
let seconds = Math.floor((Date.now() - activeTimer.startTime) / 1000);
if (seconds >= 28800) {
alert("Whoa, that's 8+ hours! 🌿\n\nGo touch some grass.\n(Saving your time anyway...)");
}
if (seconds < 60) {
seconds = 60;
}

const descKey = `jira_desc_draft_${activeTimer.ticketId}`;
const desc = localStorage.getItem(descKey) || "";

await addWorklog(settings, activeTimer.ticketId, seconds, desc);

localStorage.removeItem(descKey);
await stopTimer();
handleRefresh();
} catch (err) {
console.error(err);
alert(err instanceof Error ? err.message : "Failed to save hidden timer.");
} finally {
setStoppingHidden(false);
}
};
// Toggle functions with localStorage persistence
const togglePinnedCollapse = () => {
const newValue = !isPinnedCollapsed;
Expand Down Expand Up @@ -557,7 +584,14 @@ export const TicketList = ({ settings, onSettingsChange, onTimeUpdate }: TicketL
<div className="text-sm font-medium">
Timer running on hidden ticket
</div>
<Button variant="secondary" className="h-8 text-xs" onClick={stopTimer}>Stop</Button>
<Button
variant="secondary"
className="h-8 text-xs"
onClick={handleStopHiddenTimer}
isLoading={stoppingHidden}
>
Stop & Save
</Button>
</div>
)}
</DndContext>
Expand Down
Loading