Skip to content

Commit

Permalink
Show new event button in Agenda view when it's empty (for single and …
Browse files Browse the repository at this point in the history
…two columns layout)
  • Loading branch information
andrehgdias authored and mup committed Jul 19, 2024
1 parent f97dedb commit 892b95f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/calendar-app/calendar/view/CalendarAgendaView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { PageView } from "../../../common/gui/base/PageView.js"
import { getIfLargeScroll } from "../../../common/gui/base/GuiUtils.js"
import { isKeyPressed } from "../../../common/misc/KeyManager.js"
import { Keys } from "../../../common/api/common/TutanotaConstants.js"
import { MainCreateButton } from "../../../common/gui/MainCreateButton.js"

export type CalendarAgendaViewAttrs = {
selectedDate: Date
Expand All @@ -49,6 +50,7 @@ export type CalendarAgendaViewAttrs = {
scrollPosition: number
onScrollPositionChange: (newPosition: number) => unknown
onViewChanged: (vnode: VnodeDOM) => unknown
onCreateEvent?: () => unknown
}

export class CalendarAgendaView implements Component<CalendarAgendaViewAttrs> {
Expand Down Expand Up @@ -184,6 +186,11 @@ export class CalendarAgendaView implements Component<CalendarAgendaViewAttrs> {
icon: BootIcons.Calendar,
message: "noEntries_msg",
color: theme.list_message_bg,
bottomContent: MainCreateButton({
label: "newEvent_action",
click: () => attrs.onCreateEvent?.(),
class: "mt-s",
}),
})
} else {
return m(
Expand Down
1 change: 1 addition & 0 deletions src/calendar-app/calendar/view/CalendarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class CalendarView extends BaseTopLevelView implements TopLevelView<Calen
scrollPosition: this.viewModel.getScrollPosition(),
onScrollPositionChange: (newPosition: number) => this.viewModel.setScrollPosition(newPosition),
onViewChanged: (vnode) => this.viewModel.setViewParameters(vnode.dom as HTMLElement),
onCreateEvent: () => this.createNewEventDialog(),
} satisfies CalendarAgendaViewAttrs),
})

Expand Down
20 changes: 2 additions & 18 deletions src/common/gui/FolderColumnView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { lang } from "../misc/LanguageViewModel.js"
import { AriaLandmarks, landmarkAttrs } from "./AriaUtils.js"
import type { ClickHandler } from "./base/GuiUtils.js"
import type { lazy } from "@tutao/tutanota-utils"
import { BaseButton, BaseButtonAttrs } from "./base/buttons/BaseButton.js"
import { px, size } from "./size.js"
import { MainCreateButton } from "./MainCreateButton.js"

export type Attrs = {
/** Button to be displayed on top of the column*/
Expand Down Expand Up @@ -44,22 +43,7 @@ export class FolderColumnView implements Component<Attrs> {

private renderMainButton(attrs: Attrs): Children {
if (attrs.button) {
const label = lang.get(attrs.button.label)
return m(
".plr-button-double.scrollbar-gutter-stable-or-fallback.scroll",
m(BaseButton, {
label,
text: label,
onclick: attrs.button.click,
class: "full-width border-radius-big center b flash",
style: {
border: `2px solid ${theme.content_accent}`,
// matching toolbar
height: px(size.button_height + size.vpad_xs * 2),
color: theme.content_accent,
},
} satisfies BaseButtonAttrs),
)
return m(".plr-button-double.scrollbar-gutter-stable-or-fallback.scroll", MainCreateButton(attrs.button))
} else {
return null
}
Expand Down
31 changes: 31 additions & 0 deletions src/common/gui/MainCreateButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { lang, TranslationKey } from "../misc/LanguageViewModel.js"
import { ClickHandler } from "./base/GuiUtils.js"
import m, { Children } from "mithril"
import { theme } from "./theme.js"
import { px, size } from "./size.js"
import { BaseButton, BaseButtonAttrs } from "./base/buttons/BaseButton.js"

export interface MainCreateButtonAttrs {
label: TranslationKey
click: ClickHandler
class?: string
}

/**
* Main button used to open the creation dialog for emails,contacts and events.
*/
export const MainCreateButton = (buttonAttrs: MainCreateButtonAttrs): Children => {
const label = lang.get(buttonAttrs.label)
return m(BaseButton, {
label,
text: label,
onclick: buttonAttrs.click,
class: `full-width border-radius-big center b flash ${buttonAttrs.class}`,
style: {
border: `2px solid ${theme.content_accent}`,
// matching toolbar
height: px(size.button_height + size.vpad_xs * 2),
color: theme.content_accent,
},
} satisfies BaseButtonAttrs)
}

0 comments on commit 892b95f

Please sign in to comment.