Skip to content
Open
Show file tree
Hide file tree
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
41 changes: 38 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ import Home from "./components/Home";
import TitleBar from "./components/TitleBar";

type PipelineStatus = 'Ready' | 'Saving...' | 'Compiling...' | 'Error';

function cleanError(raw:string):string{
const lines=raw.split('\n');
const useful=lines.filter(line=>
line.trim()!='' &&
!line.toLowerCase().includes('fontconfig') &&
!line.toLowerCase().includes('compilation failed')&&
!line.toLowerCase().includes('halted on')
)
const main=useful.find(line=>line.includes('.tex:'))
return main?.trim() || useful[0]?.trim()||'Unknown LaTex error';
}
function App() {
const [projectPath, setProjectPath] = useState<string | null>(null);
const [activeFileContent, setActiveFileContent] = useState<string | null>(null);
const [filePath, setFilePath] = useState<string>("");
const [pdfPath, setPdfPath] = useState<string | null>(null);
const [pdfRevision, setPdfRevision] = useState<number>(0);
const [status, setStatus] = useState<PipelineStatus>('Ready');
const [compileError,setCompileError]=useState<string| null>(null);

const lastSavedContent = useRef<string | null>(null);

Expand Down Expand Up @@ -50,13 +61,36 @@ function App() {
const result: string = await invoke("compile_preview", { filePath: path });
setPdfPath(result);
setPdfRevision(prev => prev + 1);
setCompileError(null);
}

setStatus('Ready');
} catch (error) {
console.error("Pipeline failed:", error);
} catch (error:any){ //log the errors [show the errors in which line]
console.log("Pipeline failed:",error);
let raw="";
if(typeof error==="string"){
raw=error;
}else if(error?.message){
raw=error.message;
}else{
raw=JSON.stringify(raw);
}
const cleaned=cleanError(raw);
// let message="Unknown error occured";
// if(typeof error==='string'){
// message=error;
// }else if(error?.message){
// message=error.message;
// }else{
// message=JSON.stringify(error);
// }
setCompileError(cleaned);
setStatus('Error');
}
// catch (error) {
// console.error("Pipeline failed:", error);
// setStatus('Error');
// }
}, []);

// Automated Workflow Effect (Debounced)
Expand Down Expand Up @@ -136,6 +170,7 @@ function App() {
pdfPath={pdfPath}
pdfRevision={pdfRevision}
compiling={status === 'Compiling...'}
error={compileError}
/>
</div>
</Panel>
Expand Down
35 changes: 26 additions & 9 deletions src/components/PDFPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ interface PDFPreviewProps {
pdfPath: string | null;
pdfRevision?: number;
compiling?: boolean;
error:string | null;
}

const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewProps) => {
const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false, error}: PDFPreviewProps) => {
const [numPages, setNumPages] = useState<number | null>(null);
const [containerWidth, setContainerWidth] = useState<number>(600);
const [scale, setScale] = useState<number>(1.0);
const [fitToWidth, setFitToWidth] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);
// const [error, setError] = useState<string | null>(null);
const containerRef = useRef<HTMLDivElement>(null);

// Cache-busted URL
Expand Down Expand Up @@ -61,7 +62,7 @@ const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewP

function onDocumentLoadSuccess({ numPages }: { numPages: number }) {
setNumPages(numPages);
setError(null);
// setError(null);
}

const zoomIn = () => {
Expand Down Expand Up @@ -166,6 +167,21 @@ const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewP

{/* Scrollable Viewport */}
<div className="flex-1 overflow-auto custom-scrollbar flex flex-col items-center p-8 pt-24 min-h-full">
{error && (
<div className="w-full h-full flex items-center justify-center">
<div className="max-w-2xl w-full bg-red-950/40 border border-red-800/50 rounded-2xl p-6 shadow-2xl">
<div className="flex items-center gap-2 mb-3">
<AlertCircle className="w-5 h-5 text-red-500" /><span className="text-xs font-black uppercase tracking-widest text-red-400">
LaTeX Compilation Error
</span>
</div>
<pre className="text-sm whitespace-pre-wrap font-mono text-red-200 leading-relaxed">
{error}
</pre>
</div>
</div>
)}

{/* Compiling Overlay */}
{compiling && (
<div className="fixed inset-0 pointer-events-none z-40 bg-slate-950/20 backdrop-blur-[1px] flex items-center justify-center transition-opacity duration-300">
Expand All @@ -176,7 +192,7 @@ const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewP
</div>
)}

{!pdfPath && !compiling && (
{!pdfPath && !compiling && !error && (
<div className="flex-1 flex flex-col items-center justify-center gap-6 select-none h-full min-h-[400px]">
<div className="relative">
<Maximize className="w-24 h-24 stroke-[1] text-slate-600 opacity-50" />
Expand All @@ -191,11 +207,12 @@ const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewP
</div>
)}

{pdfPath && (
{pdfPath && !error && (
<Document
file={assetUrl}
onLoadSuccess={onDocumentLoadSuccess}
onLoadError={(err) => setError(err.message)}
// onLoadError={(err) => setError(err.message)} if fix not wrks revert bk
onLoadError={(err) => console.log("PDF load error:",err)}
loading={null}
className="flex flex-col items-center gap-12 w-full"
>
Expand All @@ -220,7 +237,7 @@ const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewP
</Document>
)}

{error && (
{/* {error && (
<div className="fixed bottom-8 right-8 z-50 p-4 bg-red-950/80 backdrop-blur-md border border-red-500/30 rounded-2xl flex items-center gap-4 text-red-200 shadow-2xl animate-in slide-in-from-bottom-4">
<AlertCircle className="w-5 h-5 text-red-500" />
<div className="flex flex-col">
Expand All @@ -234,10 +251,10 @@ const PDFPreview = ({ pdfPath, pdfRevision = 0, compiling = false }: PDFPreviewP
<RefreshCw size={14} />
</button>
</div>
)}
)} */}
</div>
</div>
);
};

export default PDFPreview;
export default PDFPreview;
6 changes: 3 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from "./App";
import "./styles.css";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>,
<React.StrictMode>
<App />
</React.StrictMode>,
);