add api react library

This commit is contained in:
lukas 2021-08-24 21:58:29 +02:00
parent 4f6025759f
commit 3fab933f8c
8 changed files with 21 additions and 63 deletions

View File

@ -21,11 +21,11 @@ func Init() {
AddActorsHandlers()
AddTvshowHandlers()
gws.AddAPINode("video", VideoNode)
gws.AddAPINode("tags", TagNode)
gws.AddAPINode("settings", SettingsNode)
gws.AddAPINode("actor", ActorNode)
gws.AddAPINode("tvshow", TVShowNode)
gws.AddAPINode("video", VideoNode, true)
gws.AddAPINode("tags", TagNode, true)
gws.AddAPINode("settings", SettingsNode, true)
gws.AddAPINode("actor", ActorNode, true)
gws.AddAPINode("tvshow", TVShowNode, true)
// serverinit is blocking
gws.ServerInit(func(id string) (oauth.CustomClientInfo, error) {

View File

@ -4,6 +4,6 @@ go 1.16
require (
github.com/go-sql-driver/mysql v1.5.0
github.com/gowebsecure/goWebSecure-go v0.1.0-beta.0
github.com/gowebsecure/goWebSecure-go v0.1.0-beta.1
nhooyr.io/websocket v1.8.7
)

View File

@ -45,8 +45,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gowebsecure/goWebSecure-go v0.1.0-beta.0 h1:sRtAUayLicrau6qYD6gBpnXpmpz5pkbOJsHk3vy18LU=
github.com/gowebsecure/goWebSecure-go v0.1.0-beta.0/go.mod h1:uEM+/1LS6hSBby7VKx2cHZ9btvQ/LC4K3HWKgqDRPs0=
github.com/gowebsecure/goWebSecure-go v0.1.0-beta.1 h1:lMaNWyk5udtOAc8U+mUo2FTgNqRwT+Aj5mxDfP5qtx0=
github.com/gowebsecure/goWebSecure-go v0.1.0-beta.1/go.mod h1:uEM+/1LS6hSBby7VKx2cHZ9btvQ/LC4K3HWKgqDRPs0=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=

View File

@ -20,7 +20,8 @@
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"typescript": "^4.3.5",
"gowebsecure": "0.1.1-beta.2"
"gowebsecure": "0.1.1-beta.2",
"gowebsecure-react": "0.1.0-beta.3"
},
"scripts": {
"start": "react-scripts start",
@ -39,7 +40,7 @@
"text-summary"
]
},
"proxy": "http://127.0.0.1:8081",
"proxy": "http://127.0.0.1:8080",
"homepage": "/",
"browserslist": {
"production": [

View File

@ -1,48 +0,0 @@
import React from 'react';
import {callAPI} from 'gowebsecure';
interface Props<T> {
onLoad?: JSX.Element;
render: (data: T, actions: {refresh: () => void}) => JSX.Element;
node: string;
action: string;
params?: {[_: string]: string | number | boolean | object};
}
interface State {
loaded: boolean;
}
export default class APIComponent<T> extends React.Component<Props<T>, State> {
state = {
loaded: false
};
data: T | undefined;
render(): JSX.Element {
if (this.state.loaded && this.data !== undefined) {
return this.props.render(this.data, {refresh: () => this.loadData()});
} else {
return this.props.onLoad ? this.props.onLoad : <></>;
}
}
componentDidMount(): void {
this.loadData();
}
componentDidUpdate(prevProps: Readonly<Props<T>>): void {
if (prevProps.params !== this.props.params) {
this.loadData();
}
}
private loadData(): void {
this.setState({loaded: false});
callAPI(this.props.node, {action: this.props.action, ...this.props.params}, (result: T) => {
this.data = result;
this.setState({loaded: true});
});
}
}

View File

@ -12,8 +12,8 @@ import {APINode, VideoTypes} from '../../types/ApiTypes';
import {DefaultTags} from '../../types/GeneralTypes';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import {faSortDown} from '@fortawesome/free-solid-svg-icons';
import APIComponent from '../../elements/APIComponent';
import {TagType} from '../../types/VideoTypes';
import {APILoader} from 'gowebsecure-react';
// eslint-disable-next-line no-shadow
export enum SortBy {
@ -54,7 +54,7 @@ export class HomePage extends React.Component<Props, state> {
<SearchHandling />
</Route>
<Route path='/'>
<APIComponent
<APILoader
render={(data: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}): JSX.Element => (
<>
<PageTitle title='Home Page' subtitle={this.state.subtitle + ' - ' + data.Videos.length}>
@ -79,7 +79,7 @@ export class HomePage extends React.Component<Props, state> {
</form>
</PageTitle>
<SideBar>
<APIComponent
<APILoader
render={(sidebardata: VideoTypes.startDataType): JSX.Element => (
<>
<SideBarTitle>Infos:</SideBarTitle>

View File

@ -6,8 +6,8 @@ import PageTitle from '../../elements/PageTitle/PageTitle';
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
import {TagType} from '../../types/VideoTypes';
import {APINode, VideoTypes} from '../../types/ApiTypes';
import APIComponent from '../../elements/APIComponent';
import KeyComponent from '../../elements/KeyComponent';
import {APILoader} from 'gowebsecure-react';
interface GetRandomMoviesType {
Videos: VideoTypes.VideoUnloadedType[];
@ -24,7 +24,7 @@ class RandomPage extends React.Component {
return (
<div>
<PageTitle title='Random Videos' subtitle={this.LoadNR + 'pcs'} />
<APIComponent
<APILoader
render={(data: GetRandomMoviesType, actions): JSX.Element => (
<KeyComponent listenKey='s' onKey={actions.refresh}>
<SideBar>

View File

@ -6049,6 +6049,11 @@ got@^9.6.0:
to-readable-stream "^1.0.0"
url-parse-lax "^3.0.0"
gowebsecure-react@0.1.0-beta.3:
version "0.1.0-beta.3"
resolved "https://registry.yarnpkg.com/gowebsecure-react/-/gowebsecure-react-0.1.0-beta.3.tgz#f614761c6d31550718d5455b219065f7dafd7664"
integrity sha512-8Vefh/VGuJIjcD0LbMcbmAv33DhyVALxgz2j8N5Q2Hjpvm6R20CIt2xRtJeHFDqbXcmfn2Z6rda0yQJ/6OFi6g==
gowebsecure@0.1.1-beta.2:
version "0.1.1-beta.2"
resolved "https://registry.yarnpkg.com/gowebsecure/-/gowebsecure-0.1.1-beta.2.tgz#3b9aaa1f83af9a7c2423da8e0ee605dc018d463b"