-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from bcgov/feature/more-editing-iterative-impr…
…ovements More Editing Improvements
- Loading branch information
Showing
18 changed files
with
225 additions
and
41 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
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,38 @@ | ||
"use client"; | ||
import { Alert } from "antd"; | ||
import React from "react"; | ||
|
||
interface ErrorBoundaryState { | ||
hasError: boolean; | ||
errorMessage?: string; | ||
} | ||
|
||
class ErrorBoundary extends React.Component<{ children: React.ReactNode }, ErrorBoundaryState> { | ||
constructor(props: { children: React.ReactNode }) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
|
||
static getDerivedStateFromError(error: Error): ErrorBoundaryState { | ||
// Update state so the next render will show the fallback UI. | ||
return { hasError: true, errorMessage: error.message }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { | ||
// Log to any new error reporting service here | ||
console.error("Uncaught error:", error, errorInfo); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
// Fallback UI | ||
return ( | ||
<Alert message={<b>Something went wrong.</b>} description={this.state.errorMessage} type="error" showIcon /> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
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 @@ | ||
export { default } from "./ErrorBoundary"; |
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 |
---|---|---|
|
@@ -2,7 +2,3 @@ | |
min-height: 500px; | ||
border: 1px solid #d9d9d9; | ||
} | ||
|
||
.spinner { | ||
min-height: 500px; | ||
} |
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
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,24 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
export default function useLeaveScreenPopup() { | ||
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleBeforeUnload = (event: { preventDefault: () => void; returnValue: string }) => { | ||
if (hasUnsavedChanges) { | ||
// Standard way to trigger the confirmation dialog | ||
event.preventDefault(); | ||
// Chrome requires returnValue to be set | ||
event.returnValue = ""; | ||
} | ||
}; | ||
// Attach the event listener | ||
window.addEventListener("beforeunload", handleBeforeUnload); | ||
// Cleanup function to remove the event listener | ||
return () => { | ||
window.removeEventListener("beforeunload", handleBeforeUnload); | ||
}; | ||
}, [hasUnsavedChanges]); | ||
|
||
return { setHasUnsavedChanges }; | ||
} |
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.