Skip to content

Commit

Permalink
observable shortcut to current tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Dec 22, 2020
1 parent a4afdf0 commit 776ca47
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions spotlight-client/src/DataStore/RootStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// =============================================================================

import { Auth0ClientOptions } from "@auth0/auth0-spa-js";
import { computed, makeObservable } from "mobx";
import TenantStore from "./TenantStore";
import UserStore from "./UserStore";

Expand Down Expand Up @@ -47,6 +48,8 @@ export default class RootStore {
userStore: UserStore;

constructor() {
makeObservable(this, { tenant: computed });

this.tenantStore = new TenantStore({ rootStore: this });

this.userStore = new UserStore({
Expand All @@ -55,4 +58,8 @@ export default class RootStore {
rootStore: this,
});
}

get tenant(): TenantStore["currentTenant"] {
return this.tenantStore.currentTenant;
}
}
2 changes: 1 addition & 1 deletion spotlight-client/src/PageExplore/PageExplore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import withRouteSync from "../withRouteSync";
import getUrlForResource from "../routerUtils/getUrlForResource";

const PageExplore: React.FC<RouteComponentProps> = () => {
const tenant = useDataStore().tenantStore.currentTenant;
const { tenant } = useDataStore();

return (
<article>
Expand Down
2 changes: 1 addition & 1 deletion spotlight-client/src/PageMetric/PageMetric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import withRouteSync from "../withRouteSync";
type PageMetricProps = RouteComponentProps & { metricTypeId?: MetricTypeId };

const PageMetric: React.FC<PageMetricProps> = ({ metricTypeId }) => {
const tenant = useDataStore().tenantStore.currentTenant;
const { tenant } = useDataStore();

// if this component is used properly as a route component,
// this should never be true;
Expand Down
2 changes: 1 addition & 1 deletion spotlight-client/src/PageNarrative/PageNarrative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type PageNarrativeProps = RouteComponentProps & {
};

const PageNarrative: React.FC<PageNarrativeProps> = ({ narrativeTypeId }) => {
const tenant = useDataStore().tenantStore.currentTenant;
const { tenant } = useDataStore();

// if this component is used properly as a route component,
// this should never be true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useDataStore } from "../StoreProvider";
import withRouteSync from "../withRouteSync";

const PageNarrativeList: React.FC<RouteComponentProps> = () => {
const tenant = useDataStore().tenantStore.currentTenant;
const { tenant } = useDataStore();

const systemNarratives = tenant?.systemNarratives;

Expand Down
2 changes: 1 addition & 1 deletion spotlight-client/src/PageTenant/PageTenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type PageTenantProps = RouteComponentProps & { tenantId?: TenantId };

const PageTenant: React.FC<PageTenantProps> = () => {
// tenant may be briefly undefined during initial page load
const tenant = useDataStore().tenantStore.currentTenant;
const { tenant } = useDataStore();

return (
<article>
Expand Down
2 changes: 1 addition & 1 deletion spotlight-client/src/SiteNavigation/SiteNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function getNavLinkProps({ matchPartial }: { matchPartial: boolean }) {
}

const SiteNavigation: React.FC = () => {
const tenant = useDataStore().tenantStore.currentTenant;
const { tenant } = useDataStore();

return (
<NavContainer>
Expand Down

0 comments on commit 776ca47

Please sign in to comment.