aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/CurrentUserUtils.ts
diff options
context:
space:
mode:
authoreperelm2 <emily_perelman@brown.edu>2023-08-01 11:07:24 -0400
committereperelm2 <emily_perelman@brown.edu>2023-08-01 11:07:24 -0400
commit07891f002c8758bd325fdcf08251deadc826e0e0 (patch)
tree867683b65c7ef0038fccd081749723d93c88fe68 /src/client/util/CurrentUserUtils.ts
parentae1c61907b6ffd0f9949d0d697bdc941eb28b7e2 (diff)
parent8f306fa2ece64630bac5521be1baadf079508939 (diff)
Merge branch 'master' into secondpropertiesmenu-emily
Diffstat (limited to 'src/client/util/CurrentUserUtils.ts')
-rw-r--r--src/client/util/CurrentUserUtils.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 8e91bf83f..21bcec6d1 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -737,7 +737,8 @@ export class CurrentUserUtils {
static setupContextMenuBtn(params:Button, menuDoc:Doc):Doc {
const menuBtnDoc = DocListCast(menuDoc?.data).find(doc => doc.title === params.title);
- if (!params.subMenu) { // button does not have a sub menu
+ const subMenu = params.subMenu;
+ if (!subMenu) { // button does not have a sub menu
return this.setupContextMenuButton(params, menuBtnDoc);
}
// linear view
@@ -745,14 +746,12 @@ export class CurrentUserUtils {
childDontRegisterViews: true, flexGap: 0, _height: 30, ignoreClick: params.scripts?.onClick ? false : true,
linearView_SubMenu: true, linearView_Expandable: params.btnType !== ButtonType.MultiToggleButton};
- const items = !menuBtnDoc ? [] : params.subMenu?.map(sub => this.setupContextMenuBtn(sub, menuBtnDoc) );
- if (params.btnType === ButtonType.MultiToggleButton) {
- const list = DocUtils.AssignScripts( DocUtils.AssignDocField(menuDoc, StrCast(params.title),
- (opts) => this.multiToggleList(opts, items??[]), reqdSubMenuOpts, items), params.scripts);
- return list;
- }
- return DocUtils.AssignScripts(
- DocUtils.AssignDocField(menuDoc, StrCast(params.title), (opts) => this.linearButtonList(opts, items??[]), reqdSubMenuOpts, items), params.scripts, params.funcs);
+ const items = (menuBtnDoc?:Doc) => !menuBtnDoc ? [] : subMenu.map(sub => this.setupContextMenuBtn(sub, menuBtnDoc) );
+ const creator = params.btnType === ButtonType.MultiToggleButton ? this.multiToggleList : this.linearButtonList;
+ const btnDoc = DocUtils.AssignScripts( DocUtils.AssignDocField(menuDoc, StrCast(params.title),
+ (opts) => creator(opts, items(menuBtnDoc)), reqdSubMenuOpts, items(menuBtnDoc)), params.scripts, params.funcs);
+ if (!menuBtnDoc) Doc.GetProto(btnDoc).data = new List<Doc>(items(btnDoc));
+ return btnDoc;
}
/// Initializes all the default buttons for the top bar context menu
@@ -916,9 +915,9 @@ export class CurrentUserUtils {
public static async loadCurrentUser() {
return rp.get(Utils.prepend("/getCurrentUser")).then(async response => {
if (response) {
- const result: { id: string, email: string, cacheDocumentIds: string } = JSON.parse(response);
+ const result: { id: string, email: string, cacheDocumentIds: string, resolvedPorts: string } = JSON.parse(response);
Doc.CurrentUserEmail = result.email;
- resolvedPorts = JSON.parse(await (await fetch("/resolvedPorts")).text());
+ resolvedPorts = result.resolvedPorts as any;
DocServer.init(window.location.protocol, window.location.hostname, resolvedPorts.socket, result.email);
if (result.cacheDocumentIds)
{