From 75b20dc50846545b33f091a9c9207fec2b27eff4 Mon Sep 17 00:00:00 2001 From: Markus Huggler Date: Fri, 23 Dec 2022 10:22:05 +0100 Subject: [PATCH] feat: adds table view feat: adds table view --- .../mastolists/src/app/app-routing.module.ts | 9 ++- projects/mastolists/src/app/app.component.ts | 7 +-- .../followings-list-routing.module.ts} | 6 +- .../followings-list.module.ts} | 10 ++-- .../list/list.component.html} | 0 .../list/list.component.scss} | 0 .../list/list.component.spec.ts} | 10 ++-- .../list/list.component.ts} | 8 +-- .../matrix/matrix.component.scss | 2 +- .../followings-table-routing.module.ts | 17 ++++++ .../followings-table.module.ts | 22 +++++++ .../table/table.component.html | 53 +++++++++++++++++ .../table/table.component.scss | 25 ++++++++ .../table/table.component.spec.ts | 23 ++++++++ .../followings-table/table/table.component.ts | 58 +++++++++++++++++++ .../src/app/home/home/home.component.html | 2 +- .../src/app/sync/sync/sync.component.html | 2 +- projects/mastolists/src/styles/themes.scss | 2 +- 18 files changed, 229 insertions(+), 27 deletions(-) rename projects/mastolists/src/app/{followings/followings-routing.module.ts => followings-list/followings-list-routing.module.ts} (62%) rename projects/mastolists/src/app/{followings/followings.module.ts => followings-list/followings-list.module.ts} (61%) rename projects/mastolists/src/app/{followings/followings/followings.component.html => followings-list/list/list.component.html} (100%) rename projects/mastolists/src/app/{followings/followings/followings.component.scss => followings-list/list/list.component.scss} (100%) rename projects/mastolists/src/app/{followings/followings/followings.component.spec.ts => followings-list/list/list.component.spec.ts} (58%) rename projects/mastolists/src/app/{followings/followings/followings.component.ts => followings-list/list/list.component.ts} (88%) create mode 100644 projects/mastolists/src/app/followings-table/followings-table-routing.module.ts create mode 100644 projects/mastolists/src/app/followings-table/followings-table.module.ts create mode 100644 projects/mastolists/src/app/followings-table/table/table.component.html create mode 100644 projects/mastolists/src/app/followings-table/table/table.component.scss create mode 100644 projects/mastolists/src/app/followings-table/table/table.component.spec.ts create mode 100644 projects/mastolists/src/app/followings-table/table/table.component.ts diff --git a/projects/mastolists/src/app/app-routing.module.ts b/projects/mastolists/src/app/app-routing.module.ts index 2e3afa2..c83fe90 100644 --- a/projects/mastolists/src/app/app-routing.module.ts +++ b/projects/mastolists/src/app/app-routing.module.ts @@ -22,8 +22,8 @@ const routes: Routes = [ canActivate: [AuthGuard], }, { - path: 'followings', - loadChildren: () => import('./followings/followings.module').then(m => m.FollowingsModule), + path: 'list', + loadChildren: () => import('./followings-list/followings-list.module').then(m => m.FollowingsListModule), canActivate: [AuthGuard], }, { @@ -31,6 +31,11 @@ const routes: Routes = [ loadChildren: () => import('./followings-matrix/followings-matrix.module').then(m => m.FollowingsMatrixModule), canActivate: [AuthGuard], }, + { + path: 'table', + loadChildren: () => import('./followings-table/followings-table.module').then(m => m.FollowingsTableModule), + canActivate: [AuthGuard], + }, ]; @NgModule({ diff --git a/projects/mastolists/src/app/app.component.ts b/projects/mastolists/src/app/app.component.ts index 497b5fd..b70f460 100644 --- a/projects/mastolists/src/app/app.component.ts +++ b/projects/mastolists/src/app/app.component.ts @@ -1,8 +1,6 @@ import {Component, isDevMode} from '@angular/core'; -import {select, Store} from "@ngrx/store"; +import {Store} from "@ngrx/store"; import {MastodonApiActions} from "./shared/state/store/actions"; -import {Observable, tap} from "rxjs"; -import {selectLoadingPercentage} from "./shared/state/store/selectors"; import {PersistentStore} from "./shared/state/persistent/persistent-store.service"; @Component({ @@ -16,8 +14,9 @@ export class AppComponent { navigationItems = [ {title: 'Authorize', link: '/auth'}, {title: 'Stats', link: '/sync'}, - {title: 'List view', link: '/followings'}, + {title: 'List view', link: '/list'}, {title: 'Matrix View', link: '/matrix'}, + {title: 'Table View', link: '/table'}, ]; constructor(private store: Store, private persistentStore: PersistentStore) { diff --git a/projects/mastolists/src/app/followings/followings-routing.module.ts b/projects/mastolists/src/app/followings-list/followings-list-routing.module.ts similarity index 62% rename from projects/mastolists/src/app/followings/followings-routing.module.ts rename to projects/mastolists/src/app/followings-list/followings-list-routing.module.ts index eb846ee..41950bc 100644 --- a/projects/mastolists/src/app/followings/followings-routing.module.ts +++ b/projects/mastolists/src/app/followings-list/followings-list-routing.module.ts @@ -1,11 +1,11 @@ import {RouterModule, Routes} from "@angular/router"; import {NgModule} from "@angular/core"; -import {FollowingsComponent} from "./followings/followings.component"; +import {ListComponent} from "./list/list.component"; const routes: Routes = [ { path: '', - component: FollowingsComponent + component: ListComponent } ]; @@ -13,5 +13,5 @@ const routes: Routes = [ imports: [RouterModule.forChild(routes)], exports: [RouterModule] }) -export class FollowingsRoutingModule { +export class FollowingsListRoutingModule { } diff --git a/projects/mastolists/src/app/followings/followings.module.ts b/projects/mastolists/src/app/followings-list/followings-list.module.ts similarity index 61% rename from projects/mastolists/src/app/followings/followings.module.ts rename to projects/mastolists/src/app/followings-list/followings-list.module.ts index 24651f6..bf3b1ce 100644 --- a/projects/mastolists/src/app/followings/followings.module.ts +++ b/projects/mastolists/src/app/followings-list/followings-list.module.ts @@ -1,23 +1,23 @@ import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; -import {FollowingsComponent} from './followings/followings.component'; +import {ListComponent} from './list/list.component'; import {SharedModule} from '../shared/shared.module'; -import {FollowingsRoutingModule} from './followings-routing.module'; +import {FollowingsListRoutingModule} from './followings-list-routing.module'; import {NbListModule, NbToggleModule} from "@nebular/theme"; @NgModule({ declarations: [ - FollowingsComponent + ListComponent ], imports: [ CommonModule, SharedModule, - FollowingsRoutingModule, + FollowingsListRoutingModule, // Nebula NbListModule, NbToggleModule, ] }) -export class FollowingsModule { +export class FollowingsListModule { } diff --git a/projects/mastolists/src/app/followings/followings/followings.component.html b/projects/mastolists/src/app/followings-list/list/list.component.html similarity index 100% rename from projects/mastolists/src/app/followings/followings/followings.component.html rename to projects/mastolists/src/app/followings-list/list/list.component.html diff --git a/projects/mastolists/src/app/followings/followings/followings.component.scss b/projects/mastolists/src/app/followings-list/list/list.component.scss similarity index 100% rename from projects/mastolists/src/app/followings/followings/followings.component.scss rename to projects/mastolists/src/app/followings-list/list/list.component.scss diff --git a/projects/mastolists/src/app/followings/followings/followings.component.spec.ts b/projects/mastolists/src/app/followings-list/list/list.component.spec.ts similarity index 58% rename from projects/mastolists/src/app/followings/followings/followings.component.spec.ts rename to projects/mastolists/src/app/followings-list/list/list.component.spec.ts index 05f85fb..3f8cd7b 100644 --- a/projects/mastolists/src/app/followings/followings/followings.component.spec.ts +++ b/projects/mastolists/src/app/followings-list/list/list.component.spec.ts @@ -1,18 +1,18 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FollowingsComponent } from './followings.component'; +import { ListComponent } from './list.component'; describe('FollowingsComponent', () => { - let component: FollowingsComponent; - let fixture: ComponentFixture; + let component: ListComponent; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ FollowingsComponent ] + declarations: [ ListComponent ] }) .compileComponents(); - fixture = TestBed.createComponent(FollowingsComponent); + fixture = TestBed.createComponent(ListComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/projects/mastolists/src/app/followings/followings/followings.component.ts b/projects/mastolists/src/app/followings-list/list/list.component.ts similarity index 88% rename from projects/mastolists/src/app/followings/followings/followings.component.ts rename to projects/mastolists/src/app/followings-list/list/list.component.ts index d8a5555..a58bb23 100644 --- a/projects/mastolists/src/app/followings/followings/followings.component.ts +++ b/projects/mastolists/src/app/followings-list/list/list.component.ts @@ -9,11 +9,11 @@ import {selectFilteredFollowingsWithLists, selectFollowings, selectFollowingsWit import {FiltersActions, ListActions, MastodonApiActions} from "../../shared/state/store/actions"; @Component({ - selector: 'app-followings', - templateUrl: './followings.component.html', - styleUrls: ['./followings.component.scss'] + selector: 'app-list', + templateUrl: './list.component.html', + styleUrls: ['./list.component.scss'] }) -export class FollowingsComponent { +export class ListComponent { followings$: Observable>; lists$: Observable>; diff --git a/projects/mastolists/src/app/followings-matrix/matrix/matrix.component.scss b/projects/mastolists/src/app/followings-matrix/matrix/matrix.component.scss index 83a7c12..03ff2d9 100644 --- a/projects/mastolists/src/app/followings-matrix/matrix/matrix.component.scss +++ b/projects/mastolists/src/app/followings-matrix/matrix/matrix.component.scss @@ -1,7 +1,7 @@ table { display: block; height: max(600px, calc(100vh - 300px)); - width: 1080px; + width: 100%; overflow-x: auto; overflow-y: auto; border: none; diff --git a/projects/mastolists/src/app/followings-table/followings-table-routing.module.ts b/projects/mastolists/src/app/followings-table/followings-table-routing.module.ts new file mode 100644 index 0000000..e6fac2b --- /dev/null +++ b/projects/mastolists/src/app/followings-table/followings-table-routing.module.ts @@ -0,0 +1,17 @@ +import {RouterModule, Routes} from "@angular/router"; +import {NgModule} from "@angular/core"; +import {TableComponent} from "./table/table.component"; + +const routes: Routes = [ + { + path: '', + component: TableComponent + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class FollowingsTableRoutingModule { +} diff --git a/projects/mastolists/src/app/followings-table/followings-table.module.ts b/projects/mastolists/src/app/followings-table/followings-table.module.ts new file mode 100644 index 0000000..aebb983 --- /dev/null +++ b/projects/mastolists/src/app/followings-table/followings-table.module.ts @@ -0,0 +1,22 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {TableComponent} from './table/table.component'; +import {SharedModule} from "../shared/shared.module"; +import {FollowingsTableRoutingModule} from "./followings-table-routing.module"; +import {NbUserModule} from "@nebular/theme"; + + +@NgModule({ + declarations: [ + TableComponent + ], + imports: [ + CommonModule, + SharedModule, + FollowingsTableRoutingModule, + // Nebular + NbUserModule, + ] +}) +export class FollowingsTableModule { +} diff --git a/projects/mastolists/src/app/followings-table/table/table.component.html b/projects/mastolists/src/app/followings-table/table/table.component.html new file mode 100644 index 0000000..82c5cbb --- /dev/null +++ b/projects/mastolists/src/app/followings-table/table/table.component.html @@ -0,0 +1,53 @@ + + +

Table View for Followings

+
+ +
+ + + + + + + + + + + + + + + + +
UsernameNotesFieldsListsActions
+ + + + + +
+ {{list.title}} + + Remove Account from list + +
+
+
+ + + Add Account to list + +
+
+
+
+ diff --git a/projects/mastolists/src/app/followings-table/table/table.component.scss b/projects/mastolists/src/app/followings-table/table/table.component.scss new file mode 100644 index 0000000..8d22133 --- /dev/null +++ b/projects/mastolists/src/app/followings-table/table/table.component.scss @@ -0,0 +1,25 @@ +table { + display: block; + height: max(600px, calc(100vh - 300px)); + width: 100%; + overflow-x: auto; + overflow-y: auto; + border: none; + + th { + border: 1pt solid #101426; + } + + td { + border: 1pt solid #101426; + } +} + +div.actions { + display: flex; + flex-direction: row; + + select { + margin-right: 5px; + } +} diff --git a/projects/mastolists/src/app/followings-table/table/table.component.spec.ts b/projects/mastolists/src/app/followings-table/table/table.component.spec.ts new file mode 100644 index 0000000..645d452 --- /dev/null +++ b/projects/mastolists/src/app/followings-table/table/table.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TableComponent } from './table.component'; + +describe('TableComponent', () => { + let component: TableComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ TableComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(TableComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/mastolists/src/app/followings-table/table/table.component.ts b/projects/mastolists/src/app/followings-table/table/table.component.ts new file mode 100644 index 0000000..8a5a426 --- /dev/null +++ b/projects/mastolists/src/app/followings-table/table/table.component.ts @@ -0,0 +1,58 @@ +import {Component} from '@angular/core'; +import {map, Observable} from "rxjs"; +import {Account} from "../../../../../mastodon-api/src/lib/interfaces/public/account"; +import {List} from "../../../../../mastodon-api/src/lib/interfaces/public/list"; +import {select, Store} from "@ngrx/store"; +import {selectFilteredFollowingsWithLists, selectLists} from "../../shared/state/store/selectors"; +import {ListActions} from "../../shared/state/store/actions"; + +interface DataGridRow { + id: string; + url: string; + displayName: string; + username: string; + avatar: string; + note: string; + fields: string; + lists: List[]; +} + +@Component({ + selector: 'app-table', + templateUrl: './table.component.html', + styleUrls: ['./table.component.scss'] +}) +export class TableComponent { + rows$: Observable; + lists$: Observable>; + + constructor(private store: Store) { + this.rows$ = this.store + .pipe( + select(selectFilteredFollowingsWithLists), + map((accounts: ReadonlyArray) => { + return accounts.map((account) => { + return { + id: account.id, + username: `@${account.username}`, + displayName: account.displayName, + url: account.url, + avatar: account.avatar, + note: account.note, + fields: account.fields.map(field => `${field.name}: ${field.value}`).join('
'), + lists: account.lists, + } as DataGridRow; + }); + }), + ); + this.lists$ = this.store.pipe(select(selectLists)); + } + + addAccountToSelectedList(accountId: string, listId: string) { + this.store.dispatch(ListActions.addAccountToList({accountId, listId})); + } + + removeAccountFromList(accountId: string, listId: string) { + this.store.dispatch(ListActions.removeAccountFromList({accountId, listId})); + } +} diff --git a/projects/mastolists/src/app/home/home/home.component.html b/projects/mastolists/src/app/home/home/home.component.html index 215b34b..5daae67 100644 --- a/projects/mastolists/src/app/home/home/home.component.html +++ b/projects/mastolists/src/app/home/home/home.component.html @@ -8,7 +8,7 @@
  • Authorize with your instance
  • Sync your lists and followings to local storage
  • -
  • Select the List view to add and remove users from lists
  • +
  • Select the List view to add and remove users from lists
  • ... or use the experimental Matrix view
diff --git a/projects/mastolists/src/app/sync/sync/sync.component.html b/projects/mastolists/src/app/sync/sync/sync.component.html index e91da75..5ba9103 100644 --- a/projects/mastolists/src/app/sync/sync/sync.component.html +++ b/projects/mastolists/src/app/sync/sync/sync.component.html @@ -40,7 +40,7 @@

Now you can:

    -
  • Select the List view to add and remove users from lists
  • +
  • Select the List view to add and remove users from lists
  • ... or use the experimental Matrix view
diff --git a/projects/mastolists/src/styles/themes.scss b/projects/mastolists/src/styles/themes.scss index ced7cd4..492a94f 100644 --- a/projects/mastolists/src/styles/themes.scss +++ b/projects/mastolists/src/styles/themes.scss @@ -9,7 +9,7 @@ $nb-themes: nb-register-theme( ( font-family-primary: 'Inter', font-family-secondary: 'Inter', - layout-content-width: 1200px, + layout-content-width: 100vw, ), dark, dark