topic-preparation.fixture.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import type { BotTopicPreparation } from "@zcode/shared";
  4. import type { UserInputRow } from "@zcode/shared/zcode-protocol-v4";
  5. import { TooltipProvider } from "@/components/ui/tooltip.js";
  6. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  7. import { BotTopicPreparationList } from "@/v4/BotTopicPreparation.js";
  8. import { ConversationUserInputBubble } from "@/v4/ConversationUserInputBubble.js";
  9. import "@/styles.css";
  10. const params = new URLSearchParams(location.search);
  11. const chinese = params.get("locale") === "zh-CN";
  12. document.documentElement.className =
  13. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  14. const text = chinese ? "北京今天天气如何?" : "What is the weather in Beijing today?";
  15. const initial: BotTopicPreparation[] = [
  16. { messageId: "first", senderName: "莫汝舰", text, status: "preparing" },
  17. {
  18. messageId: "waiting",
  19. senderName: "Long sender name ".repeat(12),
  20. text: (chinese ? "补充:请同时查看明天的天气。" : "Also check tomorrow's weather. ").repeat(32),
  21. status: "waitingStop",
  22. },
  23. { messageId: "empty", senderName: "Alice", text: " ", status: "preparing" },
  24. {
  25. messageId: "failed",
  26. senderName: "Bob",
  27. text: "file_" + "long".repeat(50),
  28. status: "failed",
  29. error: chinese ? "附件下载失败,请重试。" : "Attachment download failed. Please retry.",
  30. },
  31. ];
  32. function Fixture() {
  33. const [items, setItems] = useState(initial);
  34. const [accepted, setAccepted] = useState(false);
  35. const rows = accepted
  36. ? ([{ kind: "userInput", botGroupSource: { messageId: "first" } }] as UserInputRow[])
  37. : [];
  38. return (
  39. <ZCodeIntlProvider initialLocale={chinese ? "zh-CN" : "en-US"}>
  40. <TooltipProvider>
  41. <main className="min-h-screen bg-background p-6 text-foreground @container/conversation">
  42. <div className="mx-auto flex max-w-3xl flex-col items-end" data-testid="formal">
  43. <ConversationUserInputBubble text={text} rowId="formal" />
  44. </div>
  45. <div className="mx-auto max-w-3xl">
  46. <BotTopicPreparationList provider="feishu" items={items} acceptedRows={rows} />
  47. </div>
  48. <div className="mt-6 flex flex-wrap gap-4">
  49. <button onClick={() => setAccepted(true)}>Accept first</button>
  50. <button
  51. onClick={() =>
  52. setItems(
  53. items.map((item) =>
  54. item.messageId === "waiting"
  55. ? { ...item, status: "failed", error: "failed after preparing" }
  56. : item,
  57. ),
  58. )
  59. }
  60. >
  61. Fail waiting
  62. </button>
  63. </div>
  64. </main>
  65. </TooltipProvider>
  66. </ZCodeIntlProvider>
  67. );
  68. }
  69. createRoot(document.getElementById("root")!).render(<Fixture />);