Changeset View
Changeset View
Standalone View
Standalone View
web/url-utils.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import _keyBy from 'lodash/fp/keyBy.js'; | |||||
import { | import { | ||||
startDateForYearAndMonth, | startDateForYearAndMonth, | ||||
endDateForYearAndMonth, | endDateForYearAndMonth, | ||||
} from 'lib/utils/date-utils.js'; | } from 'lib/utils/date-utils.js'; | ||||
import { infoFromURL } from 'lib/utils/url-utils.js'; | import { infoFromURL } from 'lib/utils/url-utils.js'; | ||||
import { yearExtractor, monthExtractor } from './selectors/nav-selectors.js'; | import { yearExtractor, monthExtractor } from './selectors/nav-selectors.js'; | ||||
Show All 38 Lines | if (navInfo.tab === 'calendar') { | ||||
month !== null && | month !== null && | ||||
month !== undefined && | month !== undefined && | ||||
month !== today.getMonth() + 1 | month !== today.getMonth() + 1 | ||||
) { | ) { | ||||
newURL += `month/${month}/`; | newURL += `month/${month}/`; | ||||
} | } | ||||
} else if (navInfo.tab === 'chat') { | } else if (navInfo.tab === 'chat') { | ||||
if (navInfo.chatMode === 'create') { | if (navInfo.chatMode === 'create') { | ||||
const users = navInfo.selectedUserList?.join('+') ?? ''; | const users = | ||||
navInfo.selectedUserList?.map(({ id }) => id)?.join('+') ?? ''; | |||||
const potentiallyTrailingSlash = users.length > 0 ? '/' : ''; | const potentiallyTrailingSlash = users.length > 0 ? '/' : ''; | ||||
newURL += `thread/new/${users}${potentiallyTrailingSlash}`; | newURL += `thread/new/${users}${potentiallyTrailingSlash}`; | ||||
} else { | } else { | ||||
const activeChatThreadID = navInfo.activeChatThreadID; | const activeChatThreadID = navInfo.activeChatThreadID; | ||||
if (activeChatThreadID) { | if (activeChatThreadID) { | ||||
newURL += `thread/${activeChatThreadID}/`; | newURL += `thread/${activeChatThreadID}/`; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | const newNavInfo: NavInfo = { | ||||
tab, | tab, | ||||
startDate: startDateForYearAndMonth(year, month), | startDate: startDateForYearAndMonth(year, month), | ||||
endDate: endDateForYearAndMonth(year, month), | endDate: endDateForYearAndMonth(year, month), | ||||
activeChatThreadID, | activeChatThreadID, | ||||
chatMode, | chatMode, | ||||
}; | }; | ||||
if (urlInfo.selectedUserList) { | if (urlInfo.selectedUserList) { | ||||
newNavInfo.selectedUserList = urlInfo.selectedUserList; | const selectedUsers = _keyBy('id')(navInfo?.selectedUserList ?? []); | ||||
newNavInfo.selectedUserList = urlInfo.selectedUserList | |||||
?.map(id => selectedUsers[id]) | |||||
?.filter(Boolean); | |||||
} | } | ||||
if (urlInfo.settings) { | if (urlInfo.settings) { | ||||
newNavInfo.settingsSection = urlInfo.settings; | newNavInfo.settingsSection = urlInfo.settings; | ||||
} | } | ||||
if (urlInfo.inviteSecret) { | if (urlInfo.inviteSecret) { | ||||
newNavInfo.inviteSecret = urlInfo.inviteSecret; | newNavInfo.inviteSecret = urlInfo.inviteSecret; | ||||
} | } | ||||
return newNavInfo; | return newNavInfo; | ||||
} | } | ||||
export { canonicalURLFromReduxState, navInfoFromURL }; | export { canonicalURLFromReduxState, navInfoFromURL }; |