diff --git a/app/src/entities/presence/presence.controller.ts b/app/src/entities/presence/presence.controller.ts index 4745f10..ddb66b0 100644 --- a/app/src/entities/presence/presence.controller.ts +++ b/app/src/entities/presence/presence.controller.ts @@ -3,7 +3,7 @@ import dayjs from "dayjs"; import BoltAction from "../../bolt/decorators/bolt-action.decorator"; import Action from "../../bolt/enums/action.enum"; import { BoltActionArgs } from "../../bolt/types/bolt-action-args.type"; -import { HomeTabBuilder } from "../../gui/tabs/home/home-tab.builder"; +import { HomeTabBuilder } from "../../gui/home-tab/home-tab.builder"; import { PresenceType } from "./presence.model"; import { PresenceService } from "./presence.service"; diff --git a/app/src/gui/block-builder.interface.ts b/app/src/gui/block-builder.interface.ts deleted file mode 100644 index d29be2d..0000000 --- a/app/src/gui/block-builder.interface.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BlockBuilder as BlockBuilderType } from "slack-block-builder"; -import { Appendable } from "slack-block-builder/dist/internal"; - -/** - * Interface for classes that build views with `slack-block-builder`. - * - * Type parameter should be imported from `slack-block-builder` with respect to - * the intended consumer of the class implementing this interface. This way the - * library's type system will take care of checking that only allowed blocks are - * used throughout the block tree. - */ -export interface BlockBuilder { - buildBlocks(...args: unknown[]): Appendable | Promise>; -} diff --git a/app/src/gui/dev/dev-ui.builder.ts b/app/src/gui/dev/dev-ui.builder.ts index 832e291..9c541f1 100644 --- a/app/src/gui/dev/dev-ui.builder.ts +++ b/app/src/gui/dev/dev-ui.builder.ts @@ -1,10 +1,9 @@ import { Injectable } from "@nestjs/common"; -import { Actions, Button, Context, Divider, Header, ViewBlockBuilder } from "slack-block-builder"; +import { Actions, Button, Context, Divider, Header } from "slack-block-builder"; import Action from "../../bolt/enums/action.enum"; -import { BlockBuilder } from "../block-builder.interface"; @Injectable() -export class DevUiBuilder implements BlockBuilder { +export class DevUiBuilder { buildBlocks() { return [ Header({ text: ":wrench: Developer Tools" }), diff --git a/app/src/gui/gui.module.ts b/app/src/gui/gui.module.ts index 0d02328..fad3214 100644 --- a/app/src/gui/gui.module.ts +++ b/app/src/gui/gui.module.ts @@ -1,5 +1,5 @@ import { Global, Module } from "@nestjs/common"; -import { HomeTabModule } from "./tabs/home/home-tab.module"; +import { HomeTabModule } from "./home-tab/home-tab.module"; /** * Global module avoids having to use forward references to resolve circular diff --git a/app/src/gui/tabs/home/home-tab.builder.ts b/app/src/gui/home-tab/home-tab.builder.ts similarity index 56% rename from app/src/gui/tabs/home/home-tab.builder.ts rename to app/src/gui/home-tab/home-tab.builder.ts index c8c617b..a6aa219 100644 --- a/app/src/gui/tabs/home/home-tab.builder.ts +++ b/app/src/gui/home-tab/home-tab.builder.ts @@ -1,28 +1,37 @@ import { Injectable } from "@nestjs/common"; import { BlockAction } from "@slack/bolt"; -import { Header, HomeTab, ViewBlockBuilder } from "slack-block-builder"; +import { Actions, Button, Header, HomeTab, ViewBlockBuilder } from "slack-block-builder"; import { Appendable, SlackHomeTabDto } from "slack-block-builder/dist/internal"; -import { AppHomeOpenedArgs } from "../../../bolt/types/app-home-opened.type"; -import { ViewsPublishResponse } from "../../../bolt/types/views-publish-response.type"; -import { WebClient } from "../../../bolt/types/web-client.type"; -import { BlockBuilder } from "../../block-builder.interface"; -import { DevUiBuilder } from "../../dev/dev-ui.builder"; -import { DayListBuilder } from "./day-list.builder"; -import { VisibleOfficeSelectBuilder } from "./visible-office-select.builder"; +import { AppHomeOpenedArgs } from "../../bolt/types/app-home-opened.type"; +import { ViewsPublishResponse } from "../../bolt/types/views-publish-response.type"; +import { WebClient } from "../../bolt/types/web-client.type"; +import { DevUiBuilder } from "../dev/dev-ui.builder"; +import { DayList } from "./views/day-list.builder"; +import { VisibleOfficeSelect } from "./views/visible-office-select.builder"; @Injectable() -export class HomeTabBuilder implements BlockBuilder { +export class HomeTabBuilder { constructor( - private dayListBlocks: DayListBuilder, + private dayListBlocks: DayList, private devToolsBuilder: DevUiBuilder, - private visibleOfficeSelectBuilder: VisibleOfficeSelectBuilder, + private visibleOfficeSelectBuilder: VisibleOfficeSelect, ) {} async buildBlocks(userId: string): Promise> { const devTools = this.devToolsBuilder.buildBlocks(); const officeSelect = await this.visibleOfficeSelectBuilder.buildBlocks(); const dayList = await this.dayListBlocks.buildBlocks(userId); - return [...devTools, Header({ text: "Ilmoittautumiset" }), ...officeSelect, ...dayList]; + return [ + ...devTools, + Actions().elements([ + Button({ text: "Ilmoittautuminen" }), + Button({ text: "Läsnäolijat" }), + Button({ text: "Asetukset" }), + ]), + Header({ text: "Ilmoittautuminen" }), + ...officeSelect, + ...dayList, + ]; } async buildView(userId: string): Promise { diff --git a/app/src/gui/home-tab/home-tab.controller.ts b/app/src/gui/home-tab/home-tab.controller.ts new file mode 100644 index 0000000..8454099 --- /dev/null +++ b/app/src/gui/home-tab/home-tab.controller.ts @@ -0,0 +1,15 @@ +import { Controller } from "@nestjs/common"; +import BoltEvent from "../../bolt/decorators/bolt-event.decorator"; +import Event from "../../bolt/enums/event.enum"; +import { AppHomeOpenedArgs } from "../../bolt/types/app-home-opened.type"; +import { HomeTabBuilder } from "./home-tab.builder"; + +@Controller() +export class HomeTabController { + constructor(private homeTabBuilder: HomeTabBuilder) {} + + @BoltEvent(Event.APP_HOME_OPENED) + async getView(args: AppHomeOpenedArgs) { + await this.homeTabBuilder.publish(args); + } +} diff --git a/app/src/gui/home-tab/home-tab.module.ts b/app/src/gui/home-tab/home-tab.module.ts new file mode 100644 index 0000000..7552db2 --- /dev/null +++ b/app/src/gui/home-tab/home-tab.module.ts @@ -0,0 +1,17 @@ +import { Module } from "@nestjs/common"; +import { OfficeModule } from "../../entities/office/office.module"; +import { PresenceModule } from "../../entities/presence/presence.module"; +import { DevUiModule } from "../dev/dev-ui.module"; +import { HomeTabBuilder } from "./home-tab.builder"; +import { HomeTabController } from "./home-tab.controller"; +import { DayListItem } from "./views/day-list-item.builder"; +import { DayList } from "./views/day-list.builder"; +import { VisibleOfficeSelect } from "./views/visible-office-select.builder"; + +@Module({ + imports: [DevUiModule, OfficeModule, PresenceModule], + providers: [HomeTabBuilder, DayList, DayListItem, VisibleOfficeSelect], + controllers: [HomeTabController], + exports: [HomeTabBuilder], +}) +export class HomeTabModule {} diff --git a/app/src/gui/tabs/home/day-list-item.builder.ts b/app/src/gui/home-tab/views/day-list-item.builder.ts similarity index 87% rename from app/src/gui/tabs/home/day-list-item.builder.ts rename to app/src/gui/home-tab/views/day-list-item.builder.ts index b4b1915..755e96a 100644 --- a/app/src/gui/tabs/home/day-list-item.builder.ts +++ b/app/src/gui/home-tab/views/day-list-item.builder.ts @@ -1,18 +1,9 @@ import { Injectable } from "@nestjs/common"; import dayjs, { Dayjs } from "dayjs"; -import { - Actions, - Button, - Header, - Option, - OverflowMenu, - StaticSelect, - ViewBlockBuilder, -} from "slack-block-builder"; +import { Actions, Button, Header, Option, OverflowMenu, StaticSelect } from "slack-block-builder"; import Action from "../../../bolt/enums/action.enum"; import { Office } from "../../../entities/office/office.model"; import { Presence } from "../../../entities/presence/presence.model"; -import { BlockBuilder } from "../../block-builder.interface"; type DayListItemProps = { date: Dayjs; @@ -21,7 +12,7 @@ type DayListItemProps = { }; @Injectable() -export class DayListItemBuilder implements BlockBuilder { +export class DayListItem { buildBlocks(props: DayListItemProps) { const { date } = props; const dateString = date.toISOString(); diff --git a/app/src/gui/tabs/home/day-list.builder.ts b/app/src/gui/home-tab/views/day-list.builder.ts similarity index 81% rename from app/src/gui/tabs/home/day-list.builder.ts rename to app/src/gui/home-tab/views/day-list.builder.ts index 6d12de6..b2d1b9f 100644 --- a/app/src/gui/tabs/home/day-list.builder.ts +++ b/app/src/gui/home-tab/views/day-list.builder.ts @@ -1,11 +1,9 @@ import { Injectable } from "@nestjs/common"; import dayjs, { Dayjs } from "dayjs"; import { flatten } from "lodash"; -import { ViewBlockBuilder } from "slack-block-builder"; import { OfficeService } from "../../../entities/office/office.service"; import { PresenceService } from "../../../entities/presence/presence.service"; -import { BlockBuilder } from "../../block-builder.interface"; -import { DayListItemBuilder } from "./day-list-item.builder"; +import { DayListItem } from "./day-list-item.builder"; /** * Get range of days from today (inclusive) for the next `len` working days @@ -31,9 +29,9 @@ const dayRange = (len: number, days: Dayjs[] = [], i = 0): Dayjs[] => { }; @Injectable() -export class DayListBuilder implements BlockBuilder { +export class DayList { constructor( - private dayListItemBuilder: DayListItemBuilder, + private dayListItemBuilder: DayListItem, private officeService: OfficeService, private presenceService: PresenceService, ) {} diff --git a/app/src/gui/tabs/home/visible-office-select.builder.ts b/app/src/gui/home-tab/views/visible-office-select.builder.ts similarity index 80% rename from app/src/gui/tabs/home/visible-office-select.builder.ts rename to app/src/gui/home-tab/views/visible-office-select.builder.ts index 7765c9b..17f3fab 100644 --- a/app/src/gui/tabs/home/visible-office-select.builder.ts +++ b/app/src/gui/home-tab/views/visible-office-select.builder.ts @@ -1,11 +1,10 @@ import { Injectable } from "@nestjs/common"; -import { Option, Section, StaticSelect, ViewBlockBuilder } from "slack-block-builder"; +import { Option, Section, StaticSelect } from "slack-block-builder"; import Action from "../../../bolt/enums/action.enum"; import { OfficeService } from "../../../entities/office/office.service"; -import { BlockBuilder } from "../../block-builder.interface"; @Injectable() -export class VisibleOfficeSelectBuilder implements BlockBuilder { +export class VisibleOfficeSelect { constructor(private officeService: OfficeService) {} async buildBlocks() { diff --git a/app/src/gui/tabs/home/home-tab.controller.ts b/app/src/gui/tabs/home/home-tab.controller.ts deleted file mode 100644 index 5b1927c..0000000 --- a/app/src/gui/tabs/home/home-tab.controller.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Controller } from "@nestjs/common"; -import BoltEvent from "../../../bolt/decorators/bolt-event.decorator"; -import Event from "../../../bolt/enums/event.enum"; -import { AppHomeOpenedArgs } from "../../../bolt/types/app-home-opened.type"; -import { HomeTabBuilder } from "./home-tab.builder"; - -@Controller() -export class HomeTabController { - constructor(private homeTabBlocks: HomeTabBuilder) {} - - @BoltEvent(Event.APP_HOME_OPENED) - async getView(args: AppHomeOpenedArgs) { - await this.homeTabBlocks.publish(args); - } -} diff --git a/app/src/gui/tabs/home/home-tab.module.ts b/app/src/gui/tabs/home/home-tab.module.ts deleted file mode 100644 index 0c9ad63..0000000 --- a/app/src/gui/tabs/home/home-tab.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Module } from "@nestjs/common"; -import { OfficeModule } from "../../../entities/office/office.module"; -import { PresenceModule } from "../../../entities/presence/presence.module"; -import { DevUiModule } from "../../dev/dev-ui.module"; -import { DayListItemBuilder } from "./day-list-item.builder"; -import { DayListBuilder } from "./day-list.builder"; -import { HomeTabBuilder } from "./home-tab.builder"; -import { HomeTabController } from "./home-tab.controller"; -import { VisibleOfficeSelectBuilder } from "./visible-office-select.builder"; - -@Module({ - imports: [DevUiModule, OfficeModule, PresenceModule], - providers: [HomeTabBuilder, DayListBuilder, DayListItemBuilder, VisibleOfficeSelectBuilder], - controllers: [HomeTabController], - exports: [HomeTabBuilder], -}) -export class HomeTabModule {}