Skip to content

Commit 2bd4df0

Browse files
committed
Remove more ownRealmURL uses
There’s a big one left still
1 parent 659e8d9 commit 2bd4df0

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

packages/host/app/services/card-service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type CardSaveSubscriber = (
4444
content: SingleCardDocument | string,
4545
) => void;
4646

47-
const { ownRealmURL, environment } = ENV;
47+
const { environment } = ENV;
4848

4949
export default class CardService extends Service {
5050
@service private declare loaderService: LoaderService;
@@ -464,10 +464,8 @@ export default class CardService extends Service {
464464
async getRealmURL(card: CardDef) {
465465
let api = await this.getAPI();
466466
// in the case where we get no realm URL from the card, we are dealing with
467-
// a new card instance that does not have a realm URL yet. For now let's
468-
// assume that the new card instance will reside in the realm that is hosting the app...
469-
// TODO change this after implementing CS-6381
470-
return card[api.realmURL] ?? new URL(ownRealmURL);
467+
// a new card instance that does not have a realm URL yet.
468+
return card[api.realmURL] ?? new URL(this.realm.userDefaultRealm.path);
471469
}
472470

473471
async cardsSettled() {

packages/host/app/services/realm.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ import {
2121
SupportedMimeType,
2222
} from '@cardstack/runtime-common';
2323

24-
import ENV from '@cardstack/host/config/environment';
25-
2624
import type LoaderService from './loader-service';
2725
import type MatrixService from './matrix-service';
2826

29-
const { ownRealmURL } = ENV;
30-
3127
interface Meta {
3228
info: RealmInfo;
3329
isPublic: boolean;
@@ -286,13 +282,8 @@ export default class RealmService extends Service {
286282
.filter(([, i]) => i.canWrite)
287283
.sort(([, i], [, j]) => i.info.name.localeCompare(j.info.name));
288284

289-
let ownRealm = writeableRealms.find(([url]) => url === ownRealmURL);
290-
if (ownRealm) {
291-
return { path: ownRealm[0], info: ownRealm[1].info };
292-
} else {
293-
let first = writeableRealms[0];
294-
return { path: first[0], info: first[1].info };
295-
}
285+
let first = writeableRealms[0];
286+
return { path: first[0], info: first[1].info };
296287
}
297288

298289
token = (url: string): string | undefined => {

packages/host/app/templates/card.gts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import OperatorModeContainer from '@cardstack/host/components/operator-mode/cont
2525

2626
import Preview from '@cardstack/host/components/preview';
2727
import { Submodes } from '@cardstack/host/components/submode-switcher';
28-
import ENV from '@cardstack/host/config/environment';
2928

3029
import CardController from '@cardstack/host/controllers/card';
3130

@@ -39,6 +38,7 @@ import MessageService from '@cardstack/host/services/message-service';
3938
import OperatorModeStateService, {
4039
SerializedState as OperatorModeSerializedState,
4140
} from '@cardstack/host/services/operator-mode-state-service';
41+
import Realm from '@cardstack/host/services/realm';
4242
import RealmInfoService from '@cardstack/host/services/realm-info-service';
4343

4444
import type { CardDef } from 'https://cardstack.com/base/card-api';
@@ -56,7 +56,7 @@ interface CardRouteSignature {
5656
model: CardModel | null;
5757
};
5858
}
59-
const { ownRealmURL } = ENV;
59+
6060
@keyResponder
6161
class CardRouteComponent extends Component<CardRouteSignature> {
6262
isolatedCardComponent: ComponentLike | undefined;
@@ -66,6 +66,7 @@ class CardRouteComponent extends Component<CardRouteSignature> {
6666
@service declare router: RouterService;
6767
@service declare operatorModeStateService: OperatorModeStateService;
6868
@service declare messageService: MessageService;
69+
@service declare realm: Realm;
6970
@service declare realmInfoService: RealmInfoService;
7071

7172
constructor(owner: Owner, args: CardRouteSignature['Args']) {
@@ -128,7 +129,7 @@ class CardRouteComponent extends Component<CardRouteSignature> {
128129
// Users are not allowed to open guest mode
129130
// if realm is not publicly readable
130131
let isPublicReadableRealm = await this.realmInfoService.isPublicReadable(
131-
new URL(ownRealmURL),
132+
new URL(this.realm.userDefaultRealm.path),
132133
);
133134
if (!isPublicReadableRealm && this.args.controller.operatorModeEnabled) {
134135
return;
@@ -169,7 +170,9 @@ class CardRouteComponent extends Component<CardRouteSignature> {
169170
private fetchIsPublicReadableStatus = trackedFunction(
170171
this,
171172
async () =>
172-
await this.realmInfoService.isPublicReadable(new URL(ownRealmURL)),
173+
await this.realmInfoService.isPublicReadable(
174+
new URL(this.realm.userDefaultRealm.path),
175+
),
173176
);
174177

175178
<template>

0 commit comments

Comments
 (0)