Skip to content

Commit

Permalink
Merge pull request #19 from funidata/trunk
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
joonashak authored Oct 2, 2024
2 parents 122825f + 3e3423d commit 2a65df2
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 82 deletions.
2 changes: 1 addition & 1 deletion app/src/entities/presence/presence.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
14 changes: 0 additions & 14 deletions app/src/gui/block-builder.interface.ts

This file was deleted.

5 changes: 2 additions & 3 deletions app/src/gui/dev/dev-ui.builder.ts
Original file line number Diff line number Diff line change
@@ -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<ViewBlockBuilder> {
export class DevUiBuilder {
buildBlocks() {
return [
Header({ text: ":wrench: Developer Tools" }),
Expand Down
2 changes: 1 addition & 1 deletion app/src/gui/gui.module.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ViewBlockBuilder> {
export class HomeTabBuilder {
constructor(
private dayListBlocks: DayListBuilder,
private dayListBlocks: DayList,
private devToolsBuilder: DevUiBuilder,
private visibleOfficeSelectBuilder: VisibleOfficeSelectBuilder,
private visibleOfficeSelectBuilder: VisibleOfficeSelect,
) {}

async buildBlocks(userId: string): Promise<Appendable<ViewBlockBuilder>> {
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<SlackHomeTabDto> {
Expand Down
15 changes: 15 additions & 0 deletions app/src/gui/home-tab/home-tab.controller.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 17 additions & 0 deletions app/src/gui/home-tab/home-tab.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +12,7 @@ type DayListItemProps = {
};

@Injectable()
export class DayListItemBuilder implements BlockBuilder<ViewBlockBuilder> {
export class DayListItem {
buildBlocks(props: DayListItemProps) {
const { date } = props;
const dateString = date.toISOString();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,9 +29,9 @@ const dayRange = (len: number, days: Dayjs[] = [], i = 0): Dayjs[] => {
};

@Injectable()
export class DayListBuilder implements BlockBuilder<ViewBlockBuilder> {
export class DayList {
constructor(
private dayListItemBuilder: DayListItemBuilder,
private dayListItemBuilder: DayListItem,
private officeService: OfficeService,
private presenceService: PresenceService,
) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ViewBlockBuilder> {
export class VisibleOfficeSelect {
constructor(private officeService: OfficeService) {}

async buildBlocks() {
Expand Down
15 changes: 0 additions & 15 deletions app/src/gui/tabs/home/home-tab.controller.ts

This file was deleted.

17 changes: 0 additions & 17 deletions app/src/gui/tabs/home/home-tab.module.ts

This file was deleted.

0 comments on commit 2a65df2

Please sign in to comment.