Show a deserialization error modal if needed.
rodzic
9572aab1ed
commit
4d4baca1c3
|
@ -84,13 +84,15 @@ export function createPageWithShareableState<T>({
|
||||||
*/
|
*/
|
||||||
const [isInOnChange, setIsInOnChange] = useState(false);
|
const [isInOnChange, setIsInOnChange] = useState(false);
|
||||||
|
|
||||||
/** The default state from th URL, which we'll pass into our component. */
|
/** The default state from the URL, which we'll pass into our component. */
|
||||||
let defaults: T = defaultValue;
|
let defaults: T = defaultValue;
|
||||||
|
let deserializeError = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
defaults = deserialize(state || "");
|
defaults = deserialize(state || "");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Error deserializing state: ${e}`);
|
console.log(`Error deserializing state: ${e}`);
|
||||||
|
deserializeError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
|
@ -115,7 +117,26 @@ export function createPageWithShareableState<T>({
|
||||||
}
|
}
|
||||||
}, [isInOnChange, state, latestState, key]);
|
}, [isInOnChange, state, latestState, key]);
|
||||||
|
|
||||||
return <Component key={key} defaults={defaults} onChange={onChange} />;
|
return (
|
||||||
|
<>
|
||||||
|
{deserializeError && (
|
||||||
|
<div className="page-error">
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Sorry, an error occurred when trying to load the composition on
|
||||||
|
this page.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Either its data is corrupted, or displaying it is no longer
|
||||||
|
supported.
|
||||||
|
</p>
|
||||||
|
<button>Alas</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Component key={key} defaults={defaults} onChange={onChange} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return PageWithShareableState;
|
return PageWithShareableState;
|
||||||
|
|
36
lib/page.css
36
lib/page.css
|
@ -116,3 +116,39 @@ ul.navbar li:last-child {
|
||||||
.error {
|
.error {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-error {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
pointer-events: none;
|
||||||
|
background-color: rgba(0, 0, 0, 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-error div {
|
||||||
|
background: crimson;
|
||||||
|
color: white;
|
||||||
|
padding: 2em;
|
||||||
|
max-width: 50em;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-error div p:first-child {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-error div p:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-error div button {
|
||||||
|
display: block;
|
||||||
|
width: 66%;
|
||||||
|
margin: 3em auto 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue