diff --git a/Architecture.md b/Architecture.md index 8185c634..e25a67c2 100644 --- a/Architecture.md +++ b/Architecture.md @@ -147,7 +147,6 @@ frontend/ │ │ └── utils/ │ │ ├── buildLocationPrefix.ts # Helper function for location prefix │ │ ├── scrolling.ts # Helper function for window scrolling -│ │ ├── dompurify.ts # Helper function for sanitizing text │ │ └── formatLocation.ts # Formats OregonCity/UsaState into a display string (e.g. "Portland, OR") │ └── tests/ # Testing suite │ │ ├── components/ # Component testing @@ -168,7 +167,6 @@ frontend/ │ │ │ ├── useLetterContent.test.tsx # useLetterContent testing │ │ │ └── useMessages.test.ts # useMessages testing │ │ └── utils/ # Utility function testing -│ │ ├── dompurify.test.ts # dompurify testing │ │ ├── exportHelper.test.ts # exportHelper testing │ │ ├── feedbackHelper.test.ts # feedbackHelper testing │ │ ├── letterHelper.test.ts # letterHelper testing diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 6112e01a..bfbebe1f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -12,7 +12,6 @@ "@tailwindcss/vite": "^4.1.6", "@tanstack/react-query": "^5.77.2", "clsx": "^2.1.1", - "dompurify": "^3.3.0", "react": "^19.2.3", "react-dom": "^19.2.3", "react-markdown": "^10.1.0", @@ -2053,12 +2052,6 @@ "@types/react": "^19.2.0" } }, - "node_modules/@types/trusted-types": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", - "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", - "optional": true - }, "node_modules/@types/unist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", @@ -3043,15 +3036,6 @@ "dev": true, "peer": true }, - "node_modules/dompurify": { - "version": "3.4.13", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.13.tgz", - "integrity": "sha512-2vmYIoqjze2d+kakP8S/nS5shfsl587kzwEjcGlTdiksUVgFHnFCsLYDVj/JNqJVOQZGSYBTmuycv0PodwmnMQ==", - "license": "(MPL-2.0 OR Apache-2.0)", - "optionalDependencies": { - "@types/trusted-types": "^2.0.7" - } - }, "node_modules/electron-to-chromium": { "version": "1.5.427", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.427.tgz", diff --git a/frontend/package.json b/frontend/package.json index 29f1142e..bdb9f843 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -23,7 +23,6 @@ "@tailwindcss/vite": "^4.1.6", "@tanstack/react-query": "^5.77.2", "clsx": "^2.1.1", - "dompurify": "^3.3.0", "react": "^19.2.3", "react-dom": "^19.2.3", "react-markdown": "^10.1.0", diff --git a/frontend/src/Letter.tsx b/frontend/src/Letter.tsx index 5126048f..4a89a473 100644 --- a/frontend/src/Letter.tsx +++ b/frontend/src/Letter.tsx @@ -7,7 +7,10 @@ import { Navigate, useParams, useSearchParams } from "react-router-dom"; import { useLetterContent } from "./hooks/useLetterContent"; import { streamText } from "./pages/Chat/utils/streamHelper"; import LetterGenerationDialog from "./pages/Letter/components/LetterGenerationDialog"; -import { buildLetterUserMessage } from "./pages/Letter/utils/letterHelper"; +import { + buildLetterUserMessage, + sanitizeOrg, +} from "./pages/Letter/utils/letterHelper"; import { classifyStateSegment, pathFor, @@ -180,7 +183,10 @@ function LetterView({ jurisdiction, org }: LetterViewProps) { return ( <> - +
diff --git a/frontend/src/contexts/HousingContext.tsx b/frontend/src/contexts/HousingContext.tsx index b5bbbcd0..dc6915e2 100644 --- a/frontend/src/contexts/HousingContext.tsx +++ b/frontend/src/contexts/HousingContext.tsx @@ -1,5 +1,4 @@ import { createContext, useCallback, useMemo, useState } from "react"; -import DOMPurify, { SANITIZE_USER_SETTINGS } from "../shared/utils/dompurify"; import type { Location } from "../types/models"; import type { JurisdictionKey } from "../shared/constants/jurisdictions"; @@ -39,9 +38,7 @@ export default function HousingContextProvider({ children }: Props) { const handleIssueDescription = useCallback( (event: React.ChangeEvent) => { - setIssueDescription( - DOMPurify.sanitize(event.target.value, SANITIZE_USER_SETTINGS), - ); + setIssueDescription(event.target.value); }, [], ); diff --git a/frontend/src/pages/Chat/components/FeedbackModal.tsx b/frontend/src/pages/Chat/components/FeedbackModal.tsx index a48df1ca..9f408d2f 100644 --- a/frontend/src/pages/Chat/components/FeedbackModal.tsx +++ b/frontend/src/pages/Chat/components/FeedbackModal.tsx @@ -1,7 +1,9 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import sendFeedback from "../utils/feedbackHelper"; import type { ChatMessage } from "../../../shared/types/messages"; +const AUTO_CLOSE_DELAY_MS = 1500; + interface Props { messages: ChatMessage[]; setOpenFeedback: React.Dispatch>; @@ -14,7 +16,10 @@ export default function FeedbackModal({ messages, setOpenFeedback }: Props) { const [feedback, setFeedback] = useState(""); const [wordsToRedact, setWordsToRedact] = useState(""); const [emailsToCC, setEmailsToCC] = useState(""); - const [status, setStatus] = useState("idle"); + const [status, setStatus] = useState<"idle" | "sending" | "sent" | "error">( + "idle", + ); + const canEdit = status === "idle" || status === "error"; const handleModalClose = () => { setOpenFeedback(false); @@ -24,6 +29,14 @@ export default function FeedbackModal({ messages, setOpenFeedback }: Props) { setWordsToRedact(""); }; + // Unmounting the modal resets its state, so closing is enough; the cleanup + // cancels the timer if the user clicks Close first. + useEffect(() => { + if (status !== "sent") return; + const timer = setTimeout(() => setOpenFeedback(false), AUTO_CLOSE_DELAY_MS); + return () => clearTimeout(timer); + }, [status, setOpenFeedback]); + return ( - {status === "idle" ? ( + {canEdit ? ( <> + {status === "error" && ( +

+ Couldn't send feedback. Please try again. +

+ )}