Prefix hash for potential future changes and transparency
This commit is contained in:
parent
24cc765027
commit
126033b029
|
@ -238,7 +238,7 @@ export const SquigglePlayground: FC<PlaygroundProps> = ({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onSettingsChange?.(vars);
|
onSettingsChange?.(vars);
|
||||||
}, [vars]);
|
}, [vars, onSettingsChange]);
|
||||||
|
|
||||||
const chartSettings = {
|
const chartSettings = {
|
||||||
start: Number(vars.diagramStart),
|
start: Number(vars.diagramStart),
|
||||||
|
|
|
@ -4,13 +4,18 @@ import React from "react";
|
||||||
import Layout from "@theme/Layout";
|
import Layout from "@theme/Layout";
|
||||||
import { SquigglePlayground } from "../components/SquigglePlayground";
|
import { SquigglePlayground } from "../components/SquigglePlayground";
|
||||||
|
|
||||||
|
const HASH_PREFIX = "#code=";
|
||||||
function getHashData() {
|
function getHashData() {
|
||||||
if (typeof window === "undefined" || !window.location.hash) {
|
if (typeof window === "undefined") {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const hash = window.location.hash;
|
||||||
|
if (!hash.startsWith(HASH_PREFIX)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const compressed = toByteArray(
|
const compressed = toByteArray(
|
||||||
decodeURIComponent(window.location.hash.slice(1))
|
decodeURIComponent(hash.slice(HASH_PREFIX.length))
|
||||||
);
|
);
|
||||||
const text = inflate(compressed, { to: "string" });
|
const text = inflate(compressed, { to: "string" });
|
||||||
return JSON.parse(text);
|
return JSON.parse(text);
|
||||||
|
@ -26,7 +31,7 @@ function setHashData(data) {
|
||||||
window.history.replaceState(
|
window.history.replaceState(
|
||||||
undefined,
|
undefined,
|
||||||
"",
|
"",
|
||||||
"#" + encodeURIComponent(fromByteArray(compressed))
|
HASH_PREFIX + encodeURIComponent(fromByteArray(compressed))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user