Add notifier to plugin helpers (#2627)
* Add notifier to client PeerTubeHelpers plugin * Add doc for notifier PeerTubeHelpers * Add getBaseClientScriptsRoute to client PeerTubeHelpers plugin * Add doc for getBaseClientScriptsRoute PeerTubeHelpers * Remove unused helper Co-authored-by: kimsible <kimsible@users.noreply.github.com>
This commit is contained in:
parent
bb152476c8
commit
74c2dece42
|
@ -12,7 +12,7 @@ import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plu
|
||||||
import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type'
|
import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type'
|
||||||
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
|
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
|
||||||
import { HttpClient } from '@angular/common/http'
|
import { HttpClient } from '@angular/common/http'
|
||||||
import { AuthService } from '@app/core/auth'
|
import { AuthService, Notifier } from '@app/core'
|
||||||
import { RestExtractor } from '@app/shared/rest'
|
import { RestExtractor } from '@app/shared/rest'
|
||||||
import { PluginType } from '@shared/models/plugins/plugin.type'
|
import { PluginType } from '@shared/models/plugins/plugin.type'
|
||||||
import { PublicServerSetting } from '@shared/models/plugins/public-server.setting'
|
import { PublicServerSetting } from '@shared/models/plugins/public-server.setting'
|
||||||
|
@ -60,6 +60,7 @@ export class PluginService implements ClientHook {
|
||||||
constructor (
|
constructor (
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
|
private notifier: Notifier,
|
||||||
private server: ServerService,
|
private server: ServerService,
|
||||||
private zone: NgZone,
|
private zone: NgZone,
|
||||||
private authHttp: HttpClient,
|
private authHttp: HttpClient,
|
||||||
|
@ -272,6 +273,8 @@ export class PluginService implements ClientHook {
|
||||||
return this.authService.isLoggedIn()
|
return this.authService.isLoggedIn()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
notifier: this.notifier,
|
||||||
|
|
||||||
translate: (value: string) => {
|
translate: (value: string) => {
|
||||||
return this.translationsObservable
|
return this.translationsObservable
|
||||||
.pipe(map(allTranslations => allTranslations[npmName]))
|
.pipe(map(allTranslations => allTranslations[npmName]))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
|
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
|
||||||
|
import { Notifier } from '@app/core'
|
||||||
|
|
||||||
export type RegisterClientOptions = {
|
export type RegisterClientOptions = {
|
||||||
registerHook: (options: RegisterClientHookOptions) => void
|
registerHook: (options: RegisterClientHookOptions) => void
|
||||||
|
@ -13,5 +14,7 @@ export type RegisterClientHelpers = {
|
||||||
|
|
||||||
getSettings: () => Promise<{ [ name: string ]: string }>
|
getSettings: () => Promise<{ [ name: string ]: string }>
|
||||||
|
|
||||||
|
notifier: Notifier
|
||||||
|
|
||||||
translate: (toTranslate: string) => Promise<string>
|
translate: (toTranslate: string) => Promise<string>
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ The `ping` route can be accessed using:
|
||||||
|
|
||||||
### Client helpers (themes & plugins)
|
### Client helpers (themes & plugins)
|
||||||
|
|
||||||
### Plugin static route
|
#### Plugin static route
|
||||||
|
|
||||||
To get your plugin static route:
|
To get your plugin static route:
|
||||||
|
|
||||||
|
@ -206,6 +206,16 @@ const baseStaticUrl = peertubeHelpers.getBaseStaticRoute()
|
||||||
const imageUrl = baseStaticUrl + '/images/chocobo.png'
|
const imageUrl = baseStaticUrl + '/images/chocobo.png'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Notifier
|
||||||
|
|
||||||
|
To notify the user with the PeerTube ToastModule:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { notifier } = peertubeHelpers
|
||||||
|
notifier.success('Success message content.')
|
||||||
|
notifier.error('Error message content.')
|
||||||
|
```
|
||||||
|
|
||||||
#### Translate
|
#### Translate
|
||||||
|
|
||||||
You can translate some strings of your plugin (PeerTube will use your `translations` object of your `package.json` file):
|
You can translate some strings of your plugin (PeerTube will use your `translations` object of your `package.json` file):
|
||||||
|
|
Loading…
Reference in New Issue