Changeset View
Changeset View
Standalone View
Standalone View
web/types/nav-types.js
// @flow | // @flow | ||||
import t from 'tcomb'; | import t from 'tcomb'; | ||||
import type { TInterface } from 'tcomb'; | import type { TInterface } from 'tcomb'; | ||||
import { type BaseNavInfo } from 'lib/types/nav-types.js'; | import { type BaseNavInfo } from 'lib/types/nav-types.js'; | ||||
import { | import { | ||||
type ThreadInfo, | type ThreadInfo, | ||||
threadInfoValidator, | threadInfoValidator, | ||||
} from 'lib/types/thread-types.js'; | } from 'lib/types/thread-types.js'; | ||||
import { | |||||
type AccountUserInfo, | |||||
accountUserInfoValidator, | |||||
} from 'lib/types/user-types.js'; | |||||
import { tID, tShape } from 'lib/utils/validation-utils.js'; | import { tID, tShape } from 'lib/utils/validation-utils.js'; | ||||
export type NavigationTab = 'calendar' | 'chat' | 'settings'; | export type NavigationTab = 'calendar' | 'chat' | 'settings'; | ||||
const navigationTabValidator = t.enums.of(['calendar', 'chat', 'settings']); | const navigationTabValidator = t.enums.of(['calendar', 'chat', 'settings']); | ||||
export type NavigationSettingsSection = 'account' | 'danger-zone'; | export type NavigationSettingsSection = 'account' | 'danger-zone'; | ||||
const navigationSettingsSectionValidator = t.enums.of([ | const navigationSettingsSectionValidator = t.enums.of([ | ||||
'account', | 'account', | ||||
'danger-zone', | 'danger-zone', | ||||
]); | ]); | ||||
export type NavigationChatMode = 'view' | 'create'; | export type NavigationChatMode = 'view' | 'create'; | ||||
const navigationChatModeValidator = t.enums.of(['view', 'create']); | const navigationChatModeValidator = t.enums.of(['view', 'create']); | ||||
export type NavInfo = { | export type NavInfo = { | ||||
...$Exact<BaseNavInfo>, | ...$Exact<BaseNavInfo>, | ||||
+tab: NavigationTab, | +tab: NavigationTab, | ||||
+activeChatThreadID: ?string, | +activeChatThreadID: ?string, | ||||
+pendingThread?: ThreadInfo, | +pendingThread?: ThreadInfo, | ||||
+settingsSection?: NavigationSettingsSection, | +settingsSection?: NavigationSettingsSection, | ||||
+selectedUserList?: $ReadOnlyArray<string>, | +selectedUserList?: $ReadOnlyArray<AccountUserInfo>, | ||||
+chatMode?: NavigationChatMode, | +chatMode?: NavigationChatMode, | ||||
+inviteSecret?: ?string, | +inviteSecret?: ?string, | ||||
}; | }; | ||||
export const navInfoValidator: TInterface<NavInfo> = tShape<$Exact<NavInfo>>({ | export const navInfoValidator: TInterface<NavInfo> = tShape<$Exact<NavInfo>>({ | ||||
startDate: t.String, | startDate: t.String, | ||||
endDate: t.String, | endDate: t.String, | ||||
tab: navigationTabValidator, | tab: navigationTabValidator, | ||||
activeChatThreadID: t.maybe(tID), | activeChatThreadID: t.maybe(tID), | ||||
pendingThread: t.maybe(threadInfoValidator), | pendingThread: t.maybe(threadInfoValidator), | ||||
settingsSection: t.maybe(navigationSettingsSectionValidator), | settingsSection: t.maybe(navigationSettingsSectionValidator), | ||||
selectedUserList: t.maybe(t.list(t.String)), | selectedUserList: t.maybe(t.list(accountUserInfoValidator)), | ||||
chatMode: t.maybe(navigationChatModeValidator), | chatMode: t.maybe(navigationChatModeValidator), | ||||
inviteSecret: t.maybe(t.String), | inviteSecret: t.maybe(t.String), | ||||
}); | }); |