Skip to content
Draft
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
10 changes: 8 additions & 2 deletions frontend/src/pages/Tickets.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { api } from "../api";
import AISuggestions from "../components/AISuggestions";
import { LoadingState, ErrorState, InlineError } from "../components/AsyncState";
Expand Down Expand Up @@ -42,6 +42,9 @@ export default function Tickets() {
const [detailLoading, setDetailLoading] = useState(false);
const [saving, setSaving] = useState(false);
const [noteSaving, setNoteSaving] = useState(false);
// Identifies the most recent detail request so a slow response for a
// previously clicked ticket can't overwrite the currently selected one.
const detailRequestRef = useRef(0);

const load = async () => {
setLoading(true);
Expand All @@ -63,6 +66,7 @@ export default function Tickets() {
};

const loadDetail = async (t) => {
const requestId = ++detailRequestRef.current;
setSelected(t);
setDetailError(null);
setDetailLoading(true);
Expand All @@ -73,12 +77,14 @@ export default function Tickets() {
api.get(`/tickets/${t.id}/notes`),
api.get(`/tickets/${t.id}/history`),
]);
if (requestId !== detailRequestRef.current) return;
setNotes(ticketNotes);
setHistory(ticketHistory);
} catch (e) {
if (requestId !== detailRequestRef.current) return;
setDetailError(e.message || String(e));
} finally {
setDetailLoading(false);
if (requestId === detailRequestRef.current) setDetailLoading(false);
}
};

Expand Down
Loading