Skip to content

Commit f1e6cb6

Browse files
committed
chore: fix page title
1 parent d10fe40 commit f1e6cb6

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

web/src/Playground.tsx

+26-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ const Link = ({ children, href }: { children: ReactNode; href: string }) => (
3838
</a>
3939
);
4040

41+
const tryHandlePageTitle = ({
42+
title,
43+
version,
44+
}: {
45+
title: string;
46+
version: string;
47+
}) => {
48+
try {
49+
const pageTitle = `${title} ${version} | Speakeasy OpenAPI Overlay Playground`;
50+
if (document.title !== pageTitle) {
51+
document.title = pageTitle;
52+
}
53+
} catch (e: unknown) {
54+
console.error(e);
55+
}
56+
};
57+
4158
function Playground() {
4259
const [ready, setReady] = useState(false);
4360

@@ -136,8 +153,10 @@ function Playground() {
136153
);
137154
if (changedNew.type == "success") {
138155
const info = await GetInfo(original.current, false);
156+
const parsedInfo = JSON.parse(info);
157+
tryHandlePageTitle(parsedInfo);
139158
posthog.capture("overlay.speakeasy.com:load-shared", {
140-
openapi: JSON.parse(info),
159+
openapi: parsedInfo,
141160
});
142161
changed.current = changedNew.result;
143162
}
@@ -179,6 +198,8 @@ function Playground() {
179198
true,
180199
);
181200
result.current = res;
201+
const info = await GetInfo(original.current, false);
202+
tryHandlePageTitle(JSON.parse(info));
182203
setError("");
183204
} catch (e: unknown) {
184205
if (e instanceof Error) {
@@ -204,6 +225,8 @@ function Playground() {
204225
result.current,
205226
true,
206227
);
228+
const info = await GetInfo(changed.current, false);
229+
tryHandlePageTitle(JSON.parse(info));
207230
setError("");
208231
} catch (e: unknown) {
209232
if (e instanceof Error) {
@@ -233,6 +256,8 @@ function Playground() {
233256
changed.current = response.result || "";
234257
setError("");
235258
setOverlayMarkers([]);
259+
const info = await GetInfo(changed.current, false);
260+
tryHandlePageTitle(JSON.parse(info));
236261
} else if (response.type == "incomplete") {
237262
setApplyOverlayMode("jsonpathexplorer");
238263
changed.current = response.result || "";
@@ -264,22 +289,6 @@ function Playground() {
264289

265290
const onChangeCDebounced = useDebounceCallback(onChangeC, 500);
266291

267-
useEffect(() => {
268-
const tryHandlePageTitle = async () => {
269-
try {
270-
const info = await GetInfo(original.current);
271-
const { title, version } = JSON.parse(info);
272-
const pageTitle = `${title} ${version} | Speakeasy OpenAPI Overlay Playground`;
273-
if (document.title !== pageTitle) {
274-
document.title = pageTitle;
275-
}
276-
} catch (e: unknown) {
277-
console.error(e);
278-
}
279-
};
280-
tryHandlePageTitle();
281-
}, [original]);
282-
283292
const ref = useRef<ImperativePanelGroupHandle>(null);
284293

285294
const maxLayout = useCallback((index: number) => {

0 commit comments

Comments
 (0)