Skip to content

Commit

Permalink
WIP: account search
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelk committed Jan 12, 2021
1 parent 490109c commit 440d78e
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Subscription } from 'rxjs'
import { first, tap } from 'rxjs/operators'
import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
import { immutableAssign } from '@app/helpers'
import { Account, AccountService, VideoService } from '@app/shared/shared-main'
import { AbstractVideoList } from '@app/shared/shared-video-miniature'
import { VideoFilter } from '@shared/models'

@Component({
selector: 'my-account-search',
templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html',
styleUrls: [
'../../shared/shared-video-miniature/abstract-video-list.scss'
]
})
export class AccountSearchComponent extends AbstractVideoList implements OnInit, OnDestroy {
titlePage: string
loadOnInit = false

filter: VideoFilter = null

private account: Account
private accountSub: Subscription

constructor (
protected router: Router,
protected serverService: ServerService,
protected route: ActivatedRoute,
protected authService: AuthService,
protected userService: UserService,
protected notifier: Notifier,
protected confirmService: ConfirmService,
protected screenService: ScreenService,
protected storageService: LocalStorageService,
private accountService: AccountService,
private videoService: VideoService
) {
super()
}

ngOnInit () {
super.ngOnInit()

this.enableAllFilterIfPossible()

// Parent get the account for us
this.accountSub = this.accountService.accountLoaded
.pipe(first())
.subscribe(account => {
this.account = account

this.reloadVideos()
this.generateSyndicationList()
})
}

ngOnDestroy () {
if (this.accountSub) this.accountSub.unsubscribe()

super.ngOnDestroy()
}

getVideosObservable (page: number) {
const newPagination = immutableAssign(this.pagination, { currentPage: page })
const options = {
account: this.account,
videoPagination: newPagination,
sort: this.sort,
nsfwPolicy: this.nsfwPolicy,
videoFilter: this.filter
}

return this.videoService
.getAccountVideos(options)
.pipe(
tap(({ total }) => {
this.titlePage = $localize`${total} results on this account for TODO`
})
)
}

toggleModerationDisplay () {
this.filter = this.buildLocalFilter(this.filter, null)

this.reloadVideos()
}

generateSyndicationList () {}
}
34 changes: 22 additions & 12 deletions client/src/app/+accounts/accounts-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AccountsComponent } from './accounts.component'
import { AccountVideosComponent } from './account-videos/account-videos.component'
import { AccountAboutComponent } from './account-about/account-about.component'
import { AccountVideoChannelsComponent } from './account-video-channels/account-video-channels.component'
import { AccountSearchComponent } from './account-search/account-search.component'

const accountsRoutes: Routes = [
{
Expand All @@ -21,6 +22,24 @@ const accountsRoutes: Routes = [
redirectTo: 'video-channels',
pathMatch: 'full'
},
{
path: 'video-channels',
component: AccountVideoChannelsComponent,
data: {
meta: {
title: $localize`Account video channels`
}
}
},
{
path: 'about',
component: AccountAboutComponent,
data: {
meta: {
title: $localize`About account`
}
}
},
{
path: 'videos',
component: AccountVideosComponent,
Expand All @@ -35,20 +54,11 @@ const accountsRoutes: Routes = [
}
},
{
path: 'video-channels',
component: AccountVideoChannelsComponent,
path: 'search',
component: AccountSearchComponent,
data: {
meta: {
title: $localize`Account video channels`
}
}
},
{
path: 'about',
component: AccountAboutComponent,
data: {
meta: {
title: $localize`About account`
title: $localize`Search videos within account`
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/+accounts/accounts.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
</ng-template>

<list-overflow [items]="links" [itemTemplate]="linkTemplate"></list-overflow>

<simple-search-input (searchChanged)="searchChanged($event)" (enter)="'search'"></simple-search-input>
</div>
</div>

<div class="margin-content">
<router-outlet></router-outlet>
<router-outlet (activate)="onOutletLoaded($event)"></router-outlet>
</div>
</div>

Expand Down
12 changes: 12 additions & 0 deletions client/src/app/+accounts/accounts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Account, AccountService, DropdownAction, ListOverflowItem, VideoChannel
import { AccountReportComponent } from '@app/shared/shared-moderation'
import { User, UserRight } from '@shared/models'
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
import { AccountSearchComponent } from './account-search/account-search.component'

@Component({
templateUrl: './accounts.component.html',
Expand Down Expand Up @@ -99,6 +100,17 @@ export class AccountsComponent implements OnInit, OnDestroy {
return $localize`${count} subscribers`
}

onOutletLoaded (component: Component) {
if (component instanceof AccountSearchComponent) {
console.log('AccounSearchComponent')
}
console.log('not AccountSearchComponent')
}

searchChanged (search: string) {
console.log('search: ' + search)
}

private onAccount (account: Account) {
this.prependModerationActions = undefined

Expand Down
4 changes: 3 additions & 1 deletion client/src/app/+accounts/accounts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SharedVideoMiniatureModule } from '@app/shared/shared-video-miniature'
import { AccountAboutComponent } from './account-about/account-about.component'
import { AccountVideoChannelsComponent } from './account-video-channels/account-video-channels.component'
import { AccountVideosComponent } from './account-videos/account-videos.component'
import { AccountSearchComponent } from './account-search/account-search.component'
import { AccountsRoutingModule } from './accounts-routing.module'
import { AccountsComponent } from './accounts.component'

Expand All @@ -27,7 +28,8 @@ import { AccountsComponent } from './accounts.component'
AccountsComponent,
AccountVideosComponent,
AccountVideoChannelsComponent,
AccountAboutComponent
AccountAboutComponent,
AccountSearchComponent
],

exports: [
Expand Down
1 change: 1 addition & 0 deletions client/src/app/shared/shared-main/misc/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './help.component'
export * from './list-overflow.component'
export * from './top-menu-dropdown.component'
export * from './simple-search-input.component'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<my-global-icon iconName="search" aria-label="Search" role="button" (click)="showInput()"></my-global-icon>

<input
#searchVideos
name="search-videos"
type="text"
[(ngModel)]="search"
(ngModelChange)="searchChange"
i18n-placeholder placeholder="Search videos"
(focusout)="focusLost()"
(keyup.enter)="navigate()"
[hidden]="!shown"
>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import '_variables';
@import '_mixins';

my-global-icon {
height: 18px;
position: relative;
top: -2px;

opacity: .6;
color: pvar(--mainForegroundColor);
}

input {
@include peertube-input-text(150px);

height: 24px; // maximum height for the account/video-channels links
padding-left: 10px;
background-color: transparent;
border: none;

&::placeholder {
font-size: 15px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { Subject } from 'rxjs'
import { debounceTime, distinctUntilChanged } from 'rxjs/operators'

@Component({
selector: 'simple-search-input',
templateUrl: './simple-search-input.component.html',
styleUrls: [ './simple-search-input.component.scss' ]
})
export class SimpleSearchInputComponent implements OnInit {
@ViewChild("searchVideos") input: ElementRef

@Input() enter: string

@Output() searchChanged = new EventEmitter<string>()

search = ''
shown: boolean

private searchSubject= new Subject<string>()

constructor (
private router: Router,
private route: ActivatedRoute
) {}

ngOnInit () {
this.searchSubject
.pipe(
debounceTime(400),
distinctUntilChanged()
)
.subscribe(value => this.searchChanged.emit(value))

this.searchSubject.next(this.search)
}

showInput () {
this.shown = true
setTimeout(()=> {
this.input.nativeElement.focus()
})
}

focusLost () {
if (this.search !== '') return
this.shown = false
}

searchChange () {
this.searchChanged.emit(this.search)
}

navigate () {
this.router.navigate(['./search'], { relativeTo: this.route })
}
}
4 changes: 3 additions & 1 deletion client/src/app/shared/shared-main/shared-main.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ActionDropdownComponent, ButtonComponent, DeleteButtonComponent, EditBu
import { DateToggleComponent } from './date'
import { FeedComponent } from './feeds'
import { LoaderComponent, SmallLoaderComponent } from './loaders'
import { HelpComponent, ListOverflowComponent, TopMenuDropdownComponent } from './misc'
import { HelpComponent, ListOverflowComponent, TopMenuDropdownComponent, SimpleSearchInputComponent } from './misc'
import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users'
import { RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video'
import { VideoCaptionService } from './video-caption'
Expand Down Expand Up @@ -83,6 +83,7 @@ import { VideoChannelService } from './video-channel'
HelpComponent,
ListOverflowComponent,
TopMenuDropdownComponent,
SimpleSearchInputComponent,

UserQuotaComponent,
UserNotificationsComponent
Expand Down Expand Up @@ -132,6 +133,7 @@ import { VideoChannelService } from './video-channel'
HelpComponent,
ListOverflowComponent,
TopMenuDropdownComponent,
SimpleSearchInputComponent,

UserQuotaComponent,
UserNotificationsComponent
Expand Down
5 changes: 5 additions & 0 deletions client/src/sass/include/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@
font-size: 130%;
}
}

list-overflow {
display: inline-block;
width: max-content;
}
}
}

Expand Down

0 comments on commit 440d78e

Please sign in to comment.