You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
2 years ago
|
import {get as getBrowserGlobals} from 'app/client/lib/browserGlobals';
|
||
2 years ago
|
import {setupLocale} from 'app/client/lib/localization';
|
||
4 months ago
|
import {AppModel, newUserAPIImpl, TopAppModelImpl} from 'app/client/models/AppModel';
|
||
2 years ago
|
import {setUpErrorHandling} from 'app/client/models/errors';
|
||
|
import {buildSnackbarDom} from 'app/client/ui/NotifyUI';
|
||
|
import {addViewportTag} from 'app/client/ui/viewport';
|
||
|
import {attachCssRootVars} from 'app/client/ui2018/cssVars';
|
||
2 years ago
|
import {BaseAPI} from 'app/common/BaseAPI';
|
||
2 years ago
|
import {dom, DomContents} from 'grainjs';
|
||
|
|
||
2 years ago
|
const G = getBrowserGlobals('document', 'window');
|
||
|
|
||
4 months ago
|
export interface SetUpPageOptions {
|
||
|
/** Defaults to true. */
|
||
|
attachTheme?: boolean;
|
||
|
}
|
||
|
|
||
2 years ago
|
/**
|
||
|
* Sets up error handling and global styles, and replaces the DOM body with
|
||
|
* the result of calling `buildPage`.
|
||
|
*/
|
||
4 months ago
|
export function setUpPage(
|
||
|
buildPage: (appModel: AppModel) => DomContents,
|
||
|
options: SetUpPageOptions = {}
|
||
|
) {
|
||
|
const {attachTheme = true} = options;
|
||
2 years ago
|
setUpErrorHandling();
|
||
4 months ago
|
const topAppModel = TopAppModelImpl.create(null, {}, newUserAPIImpl(), {attachTheme});
|
||
2 years ago
|
attachCssRootVars(topAppModel.productFlavor);
|
||
|
addViewportTag();
|
||
2 years ago
|
|
||
2 years ago
|
void setupLocale();
|
||
|
|
||
2 years ago
|
// Add globals needed by test utils.
|
||
|
G.window.gristApp = {
|
||
|
testNumPendingApiRequests: () => BaseAPI.numPendingRequests(),
|
||
|
};
|
||
|
|
||
2 years ago
|
dom.update(document.body, dom.maybe(topAppModel.appObs, (appModel) => [
|
||
|
buildPage(appModel),
|
||
|
buildSnackbarDom(appModel.notifier, appModel),
|
||
|
]));
|
||
|
}
|