Skip to content

Commit cc1dd6d

Browse files
committed
move playground local storage key to utils
1 parent ecf186f commit cc1dd6d

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

packages/host/app/components/operator-mode/code-submode/playground-panel.gts

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import type RealmService from '@cardstack/host/services/realm';
3838
import type RealmServerService from '@cardstack/host/services/realm-server';
3939
import type RecentFilesService from '@cardstack/host/services/recent-files-service';
4040

41+
import { PlaygroundSelections } from '@cardstack/host/utils/local-storage-keys';
42+
4143
import type { CardDef, Format } from 'https://cardstack.com/base/card-api';
4244

4345
import PrerenderedCardSearch, {
@@ -363,7 +365,7 @@ class PlaygroundPanelContent extends Component<PlaygroundContentSignature> {
363365

364366
constructor(owner: Owner, args: PlaygroundContentSignature['Args']) {
365367
super(owner, args);
366-
let selections = window.localStorage.getItem('playground-selections');
368+
let selections = window.localStorage.getItem(PlaygroundSelections);
367369

368370
this.playgroundSelections = new TrackedObject(
369371
selections?.length ? JSON.parse(selections) : {},
@@ -456,7 +458,7 @@ class PlaygroundPanelContent extends Component<PlaygroundContentSignature> {
456458
private persistSelections = (cardId: string, format = this.format) => {
457459
this.playgroundSelections[this.args.moduleId] = { cardId, format };
458460
window.localStorage.setItem(
459-
'playground-selections',
461+
PlaygroundSelections,
460462
JSON.stringify(this.playgroundSelections),
461463
);
462464
};

packages/host/app/utils/local-storage-keys.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const CodeModePanelWidths = 'code-mode-panel-widths';
44
export const CodeModePanelHeights = 'code-mode-panel-heights';
55
export const CodeModePanelSelections = 'code-mode-panel-selections';
66
export const SessionLocalStorageKey = 'boxel-session';
7+
export const PlaygroundSelections = 'playground-selections';

packages/host/tests/acceptance/code-submode/playground-test.gts

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { module, test } from 'qunit';
55

66
import type { Realm } from '@cardstack/runtime-common';
77

8+
import { PlaygroundSelections } from '@cardstack/host/utils/local-storage-keys';
9+
810
import type { Format } from 'https://cardstack.com/base/card-api';
911

1012
import {
@@ -232,7 +234,7 @@ export class BlogPost extends CardDef {
232234
[testRealmURL, 'Author/jane-doe.json'],
233235
]),
234236
);
235-
window.localStorage.setItem('playground-selections', '');
237+
window.localStorage.setItem(PlaygroundSelections, '');
236238
});
237239

238240
test('can render playground panel when a card def is selected', async function (assert) {
@@ -264,7 +266,7 @@ export class BlogPost extends CardDef {
264266

265267
test('can populate instance chooser dropdown options from recent files', async function (assert) {
266268
window.localStorage.setItem('recent-files', '');
267-
window.localStorage.setItem('playground-selections', '');
269+
window.localStorage.setItem(PlaygroundSelections, '');
268270

269271
await visitOperatorMode({
270272
submode: 'code',
@@ -352,7 +354,7 @@ export class BlogPost extends CardDef {
352354
},
353355
};
354356
window.localStorage.setItem(
355-
'playground-selections',
357+
PlaygroundSelections,
356358
JSON.stringify(selections),
357359
);
358360
const assertCardExists = (fileName: string) => {
@@ -739,7 +741,7 @@ export class BlogPost extends CardDef {
739741
const blogPostId2 = `${testRealmURL}BlogPost/remote-work`;
740742

741743
window.localStorage.setItem(
742-
'playground-selections',
744+
PlaygroundSelections,
743745
JSON.stringify({
744746
[`${authorModuleId}`]: {
745747
cardId: authorId,
@@ -755,7 +757,7 @@ export class BlogPost extends CardDef {
755757
}),
756758
);
757759
const getSelection = (moduleId: string) => {
758-
let selections = window.localStorage.getItem('playground-selections');
760+
let selections = window.localStorage.getItem(PlaygroundSelections);
759761
if (!selections) {
760762
throw new Error('No selections found in mock local storage');
761763
}
@@ -818,7 +820,7 @@ export class BlogPost extends CardDef {
818820
format: 'fitted',
819821
});
820822

821-
let selections = window.localStorage.getItem('playground-selections');
823+
let selections = window.localStorage.getItem(PlaygroundSelections);
822824
assert.strictEqual(
823825
selections,
824826
JSON.stringify({

0 commit comments

Comments
 (0)