Skip to content

Commit b167695

Browse files
committed
UPDATE: pass document not documentId to editor
1 parent 952d0d6 commit b167695

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

client/src/components/DocumentArchive.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,20 @@ const DocumentArchive = () => {
171171
<div className="flex justify-between text-sm text-muted-foreground mb-4">
172172
<span>{formatDate(doc.uploadDate)}</span>
173173
<span
174-
className={`px-2 py-0.5 rounded-full transition-all duration-200 ${
175-
doc.status === 'Anonymized'
174+
className={`px-2 py-0.5 rounded-full transition-all duration-200 ${doc.status === 'Anonymized'
176175
? 'bg-green-100 text-green-800 group-hover:bg-green-200'
177176
: 'bg-gray-100 text-gray-800 group-hover:bg-gray-200'
178-
}`}
177+
}`}
179178
>
180179
{doc.status}
181180
</span>
182181
</div>
183182
<Link
184-
to={`/editor?id=${
185-
doc.documentType === 'anonymized'
186-
? doc.originalDocumentId
187-
: doc.id
188-
}`}
183+
to="/editor"
184+
state={{ document: doc }}
189185
>
190186
<Button className="w-full transition-all duration-200 group-hover:bg-primary/90">
191-
{doc.documentType === 'anonymized'
192-
? 'View Anonymized'
193-
: 'Open Document'}
187+
{doc.documentType === 'anonymized' ? 'View Anonymized' : 'Open Document'}
194188
</Button>
195189
</Link>
196190
</div>

client/src/components/DocumentEditor.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import AnonymizationPanel from './AnonymizationPanel';
66
import SummarizationPanel from './SummarizationPanel';
77
import EditAnonymizedDialog from './EditAnonymizedDialog';
88
import { DocumentContent } from '@/types/documentContent';
9+
import {Document} from '@/types/document';
910
import { toast } from 'sonner';
1011

1112
type DocumentEditorProps = {
12-
documentId?: string | null;
13+
document?: Document | any;
1314
};
1415

15-
const DocumentEditor = ({ documentId }: DocumentEditorProps) => {
16+
const DocumentEditor = ({ document }: DocumentEditorProps) => {
1617
const [activeTab, setActiveTab] = useState('anonymize');
1718
const [documentData, setDocumentData] = useState<DocumentContent>();
1819
const [selectedText, setSelectedText] = useState<string>('');
@@ -62,8 +63,18 @@ const DocumentEditor = ({ documentId }: DocumentEditorProps) => {
6263
}, [documentData]);
6364

6465
useEffect(() => {
65-
console.log('Fetching document with ID:', documentId);
66+
console.log('Fetching document with ID:', document);
6667

68+
const documentInfo = sessionStorage.getItem('currentDocument');
69+
if (document) {
70+
const realContent: DocumentContent = {
71+
title: document.fileName?.replace(/\.pdf$/i, '') || 'Untitled',
72+
paragraph: document.documentText || '',
73+
sensitive: [],
74+
summary: '',
75+
};
76+
setDocumentData(realContent);
77+
} else {
6778
const documentInfo = sessionStorage.getItem('currentDocument');
6879
if (documentInfo) {
6980
const parsedInfo = JSON.parse(documentInfo);
@@ -73,10 +84,10 @@ const DocumentEditor = ({ documentId }: DocumentEditorProps) => {
7384
sensitive: [],
7485
summary: '',
7586
};
76-
7787
setDocumentData(realContent);
7888
}
79-
}, [documentId]);
89+
}
90+
}, [document]);
8091

8192
if (!documentData) {
8293
return <div className="p-4 text-muted-foreground">Loading document...</div>;

client/src/pages/Editor.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { useState, useEffect } from 'react';
2-
import { useSearchParams, useNavigate } from 'react-router-dom';
2+
import { useSearchParams, useNavigate, useLocation } from 'react-router-dom';
33
import { Button } from '@/components/ui/button';
44
import { ArrowLeft } from 'lucide-react';
55
import DocumentEditor from '@/components/DocumentEditor';
66
import Navbar from '@/components/Navbar';
7+
import { Document } from '@/types/document';
8+
9+
type DocumentState = {
10+
document: Document;
11+
};
712

813
const Editor = () => {
914
const [searchParams] = useSearchParams();
1015
const documentId = searchParams.get('id');
1116
const navigate = useNavigate();
17+
const location = useLocation();
18+
const state = location.state as DocumentState | undefined;
19+
const document = state?.document;
20+
21+
1222

1323
return (
1424
<div className="min-h-screen flex flex-col">
@@ -31,7 +41,7 @@ const Editor = () => {
3141
</p>
3242
</div>
3343

34-
<DocumentEditor documentId={documentId} />
44+
<DocumentEditor document={document} />
3545
</div>
3646
</main>
3747
</div>

client/src/pages/Index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const Index = () => {
7070
if (response.status == "PROCESSED") {
7171
toast.success("File uploaded successfully!");
7272
sessionStorage.setItem("currentDocument", JSON.stringify(response));
73-
navigate(`/editor`);
73+
navigate(`/editor`, { state: { document: response } });
7474
setSelectedFile(null);
7575
if (fileInputRef.current) {
7676
fileInputRef.current.value = "";

0 commit comments

Comments
 (0)