-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
286 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,7 @@ out/ | |
|
||
qodana.yaml | ||
/scripts/afs.main.kts | ||
/docs-site/src/pages/404.js | ||
|
||
/**/*.js | ||
!workers/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
declare const _default: import("vite").UserConfig & Promise<import("vite").UserConfig> & (import("vite").UserConfigFnObject & import("vite").UserConfigExport); | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/cccv/src/components/FreshwaterManagementUnit/renderPDF.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type {FreshwaterManagementUnitPDFProps} from './FreshwaterManagementUnit.pdf.tsx' | ||
|
||
export const renderPDF = async (props: FreshwaterManagementUnitPDFProps) => { | ||
const { pdf } = await import('@react-pdf/renderer') | ||
const { FreshwaterManagementUnitPDF } = await import('./FreshwaterManagementUnit.pdf.tsx') | ||
return pdf(FreshwaterManagementUnitPDF(props)).toBlob() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/cccv/src/components/LoadingIndicator/LoadingContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,63 @@ | ||
import { UsePDFInstance } from "@react-pdf/renderer" | ||
import React, { useState } from "react" | ||
import { Spinner as DownloadSpinner } from "@components/LoadingIndicator/LoadingIndicatorOverlay.tsx" | ||
import { makeFileNameSafe } from "@lib/makeSafe.ts" | ||
import {makeFileNameSafe} from "@lib/makeSafe.ts" | ||
|
||
export const DownloadLink: React.FC<DownloadLinkProps> = ({ instance, fileName, loading, error }) => { | ||
// const [ready, setReady] = useState(false) | ||
// | ||
// useEffect(() => { | ||
// const preloadBlob = async () => { | ||
// if (instance && instance.url) { | ||
// try { | ||
// const response = await fetch(instance.url) | ||
// const blob = await response.blob() | ||
// } catch (error) { | ||
// console.error("Preload failed:", error) | ||
// } | ||
// } | ||
// } | ||
// | ||
// preloadBlob().then() | ||
// }, [instance]) | ||
|
||
export const DownloadLink: React.FC<DownloadLinkProps> = ({ | ||
href, | ||
fileName, | ||
pdfLoading, | ||
hasError, | ||
}) => { | ||
const [downloading, setDownloading] = useState(false) | ||
|
||
const handleDownload = () => { | ||
setDownloading(true) | ||
|
||
const link = document.createElement("a") | ||
link.href = href | ||
link.download = makeFileNameSafe(fileName, ["pdf"]) | ||
|
||
document.body.appendChild(link) | ||
link.click() | ||
document.body.removeChild(link) | ||
|
||
setDownloading(false) | ||
} | ||
|
||
if (pdfLoading) { | ||
return ( | ||
<div className="loading-state"> | ||
<DownloadSpinner width={3} height={5} /> | ||
<span>Preparing PDF...</span> | ||
</div> | ||
) | ||
} | ||
|
||
if (hasError) { | ||
return ( | ||
<div className="error-state"> | ||
<span className="text-red-500">Error generating PDF.</span> | ||
</div> | ||
) | ||
if (instance.blob && fileName) { | ||
setDownloading(true) | ||
const link = document.createElement('a') | ||
try { | ||
link.href = instance.url! | ||
link.download = makeFileNameSafe(fileName, ["pdf"]) | ||
|
||
document.body.appendChild(link) | ||
link.click() | ||
|
||
document.body.removeChild(link) | ||
URL.revokeObjectURL(link.href) | ||
} catch (error) { | ||
console.error("Download failed:", error) | ||
} finally { | ||
URL.revokeObjectURL(link.href) | ||
document.body.removeChild(link) | ||
setDownloading(false) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<button | ||
className="button-style" | ||
onClick={handleDownload} | ||
disabled={downloading || pdfLoading || hasError} | ||
> | ||
{downloading ? <DownloadSpinner width={3} height={5} /> : "Print"} | ||
return loading ? ( | ||
<DownloadSpinner width={3} height={5} /> | ||
) : ( | ||
<button className="button-style" onClick={handleDownload} disabled={loading || error || downloading || !instance.blob}> | ||
</button> | ||
) | ||
} | ||
|
||
interface DownloadLinkProps { | ||
pdfLoading: boolean; | ||
href: string; | ||
instance: UsePDFInstance; | ||
fileName: string; | ||
hasError?: boolean; | ||
loading?: boolean; | ||
error?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export default function formatFilename(input: string, defaultName: string): string { | ||
import {randomString} from "@lib/randomString.ts" | ||
|
||
const sanitized = input.replace(/[^a-z0-9\_\-\.]/gi, '_') | ||
export default function formatFilename(input: string, defaultName?: string, extension?: string): string { | ||
|
||
const sanitized = input.replace(/[^a-z0-9_\-.]/gi, '_') | ||
const trimmed = sanitized.trim() | ||
|
||
return trimmed.length > 0 ? trimmed : defaultName | ||
return trimmed.length > 0 ? trimmed : defaultName || randomString(8) + (extension ? `.${extension}` : '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const randomString = (length: number) => { | ||
let result = '' | ||
const characters = | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' | ||
const charactersLength = characters.length | ||
for (let i = 0; i < length; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)) | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.