feat: history view in feedback popover

This commit is contained in:
Maze Winther
2026-04-15 06:39:52 +02:00
parent 8161de00e6
commit 66e4367bc4
@@ -3,6 +3,7 @@
import { useState } from "react"; import { useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { toast } from "sonner"; import { toast } from "sonner";
import { ClockIcon } from "lucide-react";
import { import {
Popover, Popover,
PopoverContent, PopoverContent,
@@ -106,8 +107,11 @@ export function FeedbackPopover() {
); );
} }
type View = "compose" | "history";
function FeedbackPopoverContent({ onClose }: { onClose: () => void }) { function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
const { entries, isSubmitting, submit } = useFeedback(); const { entries, isSubmitting, submit } = useFeedback();
const [view, setView] = useState<View>("compose");
const form = useForm<FeedbackFormValues>({ const form = useForm<FeedbackFormValues>({
defaultValues: { message: "" }, defaultValues: { message: "" },
@@ -124,6 +128,33 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
}); });
} }
if (view === "history") {
return (
<div className="flex flex-col">
<div
className="max-h-72 overflow-y-auto divide-y"
style={{
maskImage:
"linear-gradient(to bottom, black 80%, transparent 100%)",
}}
>
{entries.map((entry) => (
<FeedbackEntryItem key={entry.id} entry={entry} />
))}
</div>
<div className="border-t px-3 py-2">
<button
type="button"
onClick={() => setView("compose")}
className="text-xs text-muted-foreground/60 hover:text-muted-foreground transition-colors"
>
Back
</button>
</div>
</div>
);
}
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
<Form persistKey={PERSIST_KEY} {...form}> <Form persistKey={PERSIST_KEY} {...form}>
@@ -143,7 +174,20 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
</FormItem> </FormItem>
)} )}
/> />
<div className="flex justify-end border-t px-3 py-2 gap-2"> <div className="flex items-center justify-between border-t px-3 py-2">
{entries.length > 0 ? (
<button
type="button"
onClick={() => setView("history")}
className="flex items-center gap-1.5 text-xs text-muted-foreground/60 hover:text-muted-foreground transition-colors"
>
<ClockIcon className="size-3" />
{entries.length}
</button>
) : (
<span />
)}
<div className="flex gap-2">
{!form.watch("message").trim() && ( {!form.watch("message").trim() && (
<Button <Button
type="button" type="button"
@@ -162,24 +206,9 @@ function FeedbackPopoverContent({ onClose }: { onClose: () => void }) {
{isSubmitting ? <Spinner /> : "Send"} {isSubmitting ? <Spinner /> : "Send"}
</Button> </Button>
</div> </div>
</div>
</form> </form>
</Form> </Form>
{entries.length > 0 && (
<div className="border-t overflow-hidden">
<div
className="max-h-52 overflow-y-auto divide-y"
style={{
maskImage:
"linear-gradient(to bottom, black 70%, transparent 100%)",
}}
>
{entries.map((entry) => (
<FeedbackEntryItem key={entry.id} entry={entry} />
))}
</div>
</div>
)}
</div> </div>
); );
} }