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