Skip to content

Commit

Permalink
Fix double-clicking on a search category logging out the desktop client
Browse files Browse the repository at this point in the history
Closes #7319.
  • Loading branch information
rezbyte committed Aug 2, 2024
1 parent d8c32e0 commit 8fe0319
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/common/search/view/SearchRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SearchRestriction } from "../../api/worker/search/SearchTypes.js"
import { getRestriction, getSearchUrl } from "../../../mail-app/search/model/SearchUtils.js"
import { getRestriction, getSearchParameters } from "../../../mail-app/search/model/SearchUtils.js"
import m from "mithril"
import { Router } from "../../gui/ScopedRouter.js"
import { memoizedWithHiddenArgument } from "@tutao/tutanota-utils"
Expand All @@ -15,7 +15,7 @@ export class SearchRouter {
readonly getRestriction: () => SearchRestriction = memoizedWithHiddenArgument(() => m.route.get(), getRestriction)

routeTo(query: string, restriction: SearchRestriction, selectionKey: string | null = null): void {
const { path, params } = getSearchUrl(query, restriction, selectionKey)
const { path, params } = getSearchParameters(query, restriction, selectionKey)
this.router.routeTo(path, params)
}
}
8 changes: 7 additions & 1 deletion src/mail-app/search/model/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ export function searchCategoryForRestriction(restriction: SearchRestriction): Se
return assertNotNull(SEARCH_CATEGORIES.find((c) => isSameTypeRef(c.typeRef, restriction.type))).name
}

export function getSearchUrl(
// Gets the resulting URL if the output of `getSearchParameters()` was routed to
export function getSearchUrl(query: string | null, restriction: SearchRestriction, selectionKey: string | null = null): string {
const { path, params } = getSearchParameters(query, restriction, selectionKey)
return m.buildPathname(path, params as m.Params)
}

export function getSearchParameters(
query: string | null,
restriction: SearchRestriction,
selectionKey: string | null,
Expand Down
17 changes: 6 additions & 11 deletions src/mail-app/search/view/SearchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class SearchView extends BaseTopLevelView implements TopLevelView<SearchV
m(NavButton, {
label: "emails_label",
icon: () => BootIcons.Mail,
href: "#",
href: this.searchViewModel.getUrlFromSearchCategory(SearchCategoryTypes.mail),
click: () => {
this.switchCategory(SearchCategoryTypes.mail)
this.viewSlider.focus(this.resultListColumn)
},
isSelectedPrefix: "/search/mail",
colors: NavButtonColor.Nav,
Expand All @@ -165,9 +165,9 @@ export class SearchView extends BaseTopLevelView implements TopLevelView<SearchV
m(NavButton, {
label: "contacts_label",
icon: () => BootIcons.Contacts,
href: "#",
href: this.searchViewModel.getUrlFromSearchCategory(SearchCategoryTypes.contact),
click: () => {
this.switchCategory(SearchCategoryTypes.contact)
this.viewSlider.focus(this.resultListColumn)
},
isSelectedPrefix: "/search/contact",
colors: NavButtonColor.Nav,
Expand All @@ -179,9 +179,9 @@ export class SearchView extends BaseTopLevelView implements TopLevelView<SearchV
m(NavButton, {
label: "calendar_label",
icon: () => BootIcons.Calendar,
href: "#",
href: this.searchViewModel.getUrlFromSearchCategory(SearchCategoryTypes.calendar),
click: () => {
this.switchCategory(SearchCategoryTypes.calendar)
this.viewSlider.focus(this.resultListColumn)
},
isSelectedPrefix: "/search/calendar",
colors: NavButtonColor.Nav,
Expand Down Expand Up @@ -243,11 +243,6 @@ export class SearchView extends BaseTopLevelView implements TopLevelView<SearchV
this.viewSlider = new ViewSlider([this.folderColumn, this.resultListColumn, this.resultDetailsColumn])
}

private switchCategory(category: SearchCategoryTypes): void {
this.searchViewModel.switchSearchCategory(category)
this.viewSlider.focus(this.resultListColumn)
}

private getResultColumnLayout() {
return m(SearchListView, {
listModel: this.searchViewModel.listModel,
Expand Down
9 changes: 5 additions & 4 deletions src/mail-app/search/view/SearchViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
decodeCalendarSearchKey,
encodeCalendarSearchKey,
getRestriction,
getSearchUrl,
searchCategoryForRestriction,
SearchCategoryTypes,
} from "../model/SearchUtils.js"
Expand Down Expand Up @@ -448,7 +449,7 @@ export class SearchViewModel {
}
}

switchSearchCategory(category: SearchCategoryTypes) {
getUrlFromSearchCategory(category: SearchCategoryTypes): string {
if (this.currentQuery) {
let latestRestriction: SearchRestriction | null = null
switch (category) {
Expand All @@ -464,12 +465,12 @@ export class SearchViewModel {
}

if (latestRestriction) {
this.router.routeTo(this.currentQuery, latestRestriction)
return getSearchUrl(this.currentQuery, latestRestriction)
} else {
this.router.routeTo(this.currentQuery, createRestriction(category, null, null, null, [], null))
return getSearchUrl(this.currentQuery, createRestriction(category, null, null, null, [], null))
}
} else {
this.router.routeTo("", createRestriction(category, null, null, null, [], null))
return getSearchUrl("", createRestriction(category, null, null, null, [], null))
}
}

Expand Down

0 comments on commit 8fe0319

Please sign in to comment.