2022-06-06 16:21:26 +00:00
|
|
|
import {get as getBrowserGlobals} from 'app/client/lib/browserGlobals';
|
2022-09-29 08:01:37 +00:00
|
|
|
import {setupLocale} from 'app/client/lib/localization';
|
2024-01-24 09:58:19 +00:00
|
|
|
import {AppModel, newUserAPIImpl, TopAppModelImpl} from 'app/client/models/AppModel';
|
2022-01-19 19:41:06 +00:00
|
|
|
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';
|
2022-06-06 16:21:26 +00:00
|
|
|
import {BaseAPI} from 'app/common/BaseAPI';
|
2022-01-19 19:41:06 +00:00
|
|
|
import {dom, DomContents} from 'grainjs';
|
|
|
|
|
2022-06-06 16:21:26 +00:00
|
|
|
const G = getBrowserGlobals('document', 'window');
|
|
|
|
|
2024-01-24 09:58:19 +00:00
|
|
|
export interface SetUpPageOptions {
|
|
|
|
/** Defaults to true. */
|
|
|
|
attachTheme?: boolean;
|
|
|
|
}
|
|
|
|
|
2022-01-19 19:41:06 +00:00
|
|
|
/**
|
|
|
|
* Sets up error handling and global styles, and replaces the DOM body with
|
|
|
|
* the result of calling `buildPage`.
|
|
|
|
*/
|
2024-01-24 09:58:19 +00:00
|
|
|
export function setUpPage(
|
|
|
|
buildPage: (appModel: AppModel) => DomContents,
|
|
|
|
options: SetUpPageOptions = {}
|
|
|
|
) {
|
|
|
|
const {attachTheme = true} = options;
|
2022-01-19 19:41:06 +00:00
|
|
|
setUpErrorHandling();
|
2024-01-24 09:58:19 +00:00
|
|
|
const topAppModel = TopAppModelImpl.create(null, {}, newUserAPIImpl(), {attachTheme});
|
2022-01-19 19:41:06 +00:00
|
|
|
attachCssRootVars(topAppModel.productFlavor);
|
|
|
|
addViewportTag();
|
2022-06-06 16:21:26 +00:00
|
|
|
|
2022-09-29 08:01:37 +00:00
|
|
|
void setupLocale();
|
|
|
|
|
2022-06-06 16:21:26 +00:00
|
|
|
// Add globals needed by test utils.
|
|
|
|
G.window.gristApp = {
|
|
|
|
testNumPendingApiRequests: () => BaseAPI.numPendingRequests(),
|
|
|
|
};
|
|
|
|
|
2022-01-19 19:41:06 +00:00
|
|
|
dom.update(document.body, dom.maybe(topAppModel.appObs, (appModel) => [
|
|
|
|
buildPage(appModel),
|
|
|
|
buildSnackbarDom(appModel.notifier, appModel),
|
|
|
|
]));
|
|
|
|
}
|