@@ -13,10 +13,9 @@ import { ApplyOverlay, CalculateOverlay, GetInfo } from "./bridge";
13
13
import { Alert } from "@speakeasy-api/moonshine" ;
14
14
import { blankOverlay , petstore } from "./defaults" ;
15
15
import { useAtom } from "jotai" ;
16
- import { throttledPushState } from "./url" ;
17
16
import speakeasyWhiteLogo from "./assets/speakeasy-white.svg" ;
18
17
import openapiLogo from "./assets/openapi.svg" ;
19
- import { atomWithHash } from "jotai-location " ;
18
+ import { atom } from "jotai" ;
20
19
import { compress , decompress } from "@/compress" ;
21
20
import { CopyButton } from "@/components/CopyButton" ;
22
21
import { Button } from "@/components/ui/button" ;
@@ -27,17 +26,11 @@ import {
27
26
ImperativePanelGroupHandle ,
28
27
} from "react-resizable-panels" ;
29
28
import posthog from "posthog-js" ;
30
- import { useMediaQuery } from "usehooks-ts" ;
29
+ import { useDebounceCallback , useMediaQuery } from "usehooks-ts" ;
31
30
32
- const originalOpenAPI = atomWithHash ( "originalOpenAPI" , petstore , {
33
- setHash : throttledPushState ,
34
- } ) ;
35
- const changedOpenAPI = atomWithHash ( "changedOpenAPI" , petstore , {
36
- setHash : throttledPushState ,
37
- } ) ;
38
- const overlay = atomWithHash ( "overlay" , blankOverlay , {
39
- setHash : throttledPushState ,
40
- } ) ;
31
+ const originalOpenAPI = atom ( petstore ) ;
32
+ const changedOpenAPI = atom ( petstore ) ;
33
+ const overlay = atom ( blankOverlay ) ;
41
34
const Link = ( { children, href } : { children : ReactNode ; href : string } ) => (
42
35
< a
43
36
className = "border-b border-transparent pb-[2px] transition-all duration-200 hover:border-current "
@@ -50,14 +43,6 @@ const Link = ({ children, href }: { children: ReactNode; href: string }) => (
50
43
</ a >
51
44
) ;
52
45
53
- function removeShareURL ( ) {
54
- const currentUrl = new URL ( window . location . href ) ;
55
- if ( currentUrl . searchParams . has ( "s" ) ) {
56
- currentUrl . searchParams . delete ( "s" ) ;
57
- history . pushState ( null , "" , currentUrl . toString ( ) ) ;
58
- }
59
- }
60
-
61
46
function Playground ( ) {
62
47
const [ ready , setReady ] = useState ( false ) ;
63
48
@@ -152,7 +137,6 @@ function Playground() {
152
137
const onChangeA = useCallback (
153
138
async ( value : string | undefined , _ : editor . IModelContentChangedEvent ) => {
154
139
try {
155
- removeShareURL ( ) ;
156
140
setResultLoading ( true ) ;
157
141
setOriginal ( value || "" ) ;
158
142
const res = await CalculateOverlay ( value || "" , changed , true ) ;
@@ -169,10 +153,11 @@ function Playground() {
169
153
[ changed , original ] ,
170
154
) ;
171
155
156
+ const onChangeADebounced = useDebounceCallback ( onChangeA , 500 ) ;
157
+
172
158
const onChangeB = useCallback (
173
159
async ( value : string | undefined , _ : editor . IModelContentChangedEvent ) => {
174
160
try {
175
- removeShareURL ( ) ;
176
161
setResultLoading ( true ) ;
177
162
setChanged ( value || "" ) ;
178
163
const res = await CalculateOverlay ( original , value || "" , true ) ;
@@ -189,10 +174,11 @@ function Playground() {
189
174
[ changed , original ] ,
190
175
) ;
191
176
177
+ const onChangeBDebounced = useDebounceCallback ( onChangeB , 500 ) ;
178
+
192
179
const onChangeC = useCallback (
193
180
async ( value : string | undefined , _ : editor . IModelContentChangedEvent ) => {
194
181
try {
195
- removeShareURL ( ) ;
196
182
setChangedLoading ( true ) ;
197
183
setResult ( value || "" ) ;
198
184
const res = await ApplyOverlay ( original , value || "" , true ) ;
@@ -209,6 +195,8 @@ function Playground() {
209
195
[ changed , original ] ,
210
196
) ;
211
197
198
+ const onChangeCDebounced = useDebounceCallback ( onChangeC , 500 ) ;
199
+
212
200
useEffect ( ( ) => {
213
201
const tryHandlePageTitle = async ( ) => {
214
202
try {
@@ -364,7 +352,7 @@ function Playground() {
364
352
< Editor
365
353
readonly = { false }
366
354
value = { original }
367
- onChange = { onChangeA }
355
+ onChange = { onChangeADebounced }
368
356
title = "Original"
369
357
index = { 0 }
370
358
maxOnClick = { maxLayout }
@@ -377,7 +365,7 @@ function Playground() {
377
365
< Editor
378
366
readonly = { false }
379
367
value = { changed }
380
- onChange = { onChangeB }
368
+ onChange = { onChangeBDebounced }
381
369
loading = { changedLoading }
382
370
title = { "Original + Overlay" }
383
371
index = { 1 }
@@ -391,7 +379,7 @@ function Playground() {
391
379
< Editor
392
380
readonly = { false }
393
381
value = { result }
394
- onChange = { onChangeC }
382
+ onChange = { onChangeCDebounced }
395
383
loading = { resultLoading }
396
384
title = { "Overlay" }
397
385
index = { 2 }
0 commit comments