mirror of https://github.com/stashapp/stash.git
Add check version functionality (#296)
This commit is contained in:
parent
63cc97d199
commit
dda36f6b09
|
@ -1,9 +1,10 @@
|
|||
import React from "react";
|
||||
import { Table, Spinner } from "react-bootstrap";
|
||||
import { Button, Table, Spinner } from "react-bootstrap";
|
||||
import { StashService } from "src/core/StashService";
|
||||
|
||||
export const SettingsAboutPanel: React.FC = () => {
|
||||
const { data, error, loading } = StashService.useVersion();
|
||||
const { data: dataLatest, error: errorLatest, loading: loadingLatest, refetch, networkStatus } = StashService.useLatestVersion();
|
||||
|
||||
function maybeRenderTag() {
|
||||
if (!data || !data.version || !data.version.version) {
|
||||
|
@ -17,6 +18,44 @@ export const SettingsAboutPanel: React.FC = () => {
|
|||
);
|
||||
}
|
||||
|
||||
function maybeRenderLatestVersion() {
|
||||
if (!dataLatest || !dataLatest.latestversion || !dataLatest.latestversion.shorthash || !dataLatest.latestversion.url) { return; }
|
||||
if (!data || !data.version || !data.version.hash) {
|
||||
return (
|
||||
<>{dataLatest.latestversion.shorthash}</>
|
||||
);
|
||||
}
|
||||
|
||||
if (data.version.hash !== dataLatest.latestversion.shorthash) {
|
||||
return (
|
||||
<>
|
||||
<strong>{dataLatest.latestversion.shorthash} [NEW] </strong><a href={dataLatest.latestversion.url}>Download</a>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>{dataLatest.latestversion.shorthash}</>
|
||||
);
|
||||
}
|
||||
|
||||
function renderLatestVersion() {
|
||||
if (!data || !data.version || !data.version.version) { return; } //if there is no "version" latest version check is obviously not supported
|
||||
return (
|
||||
<Table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Latest Version Build Hash: </td>
|
||||
<td>{maybeRenderLatestVersion()} </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><Button onClick={() => refetch()}>Check for new version</Button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
||||
function renderVersion() {
|
||||
if (!data || !data.version) {
|
||||
return;
|
||||
|
@ -43,8 +82,10 @@ export const SettingsAboutPanel: React.FC = () => {
|
|||
<>
|
||||
<h4>About</h4>
|
||||
{!data || loading ? <Spinner animation="border" variant="light" /> : ""}
|
||||
{error ? <span>error.message</span> : ""}
|
||||
{!!error ? <span>{error.message}</span> : undefined}
|
||||
{!!errorLatest ? <span>{errorLatest.message}</span> : undefined}
|
||||
{renderVersion()}
|
||||
{!dataLatest || loadingLatest || networkStatus === 4 ? <Spinner animation="border" variant="light" /> : <>{renderLatestVersion()}</>}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -275,6 +275,8 @@ export class StashService {
|
|||
public static useVersion() {
|
||||
return GQL.useVersionQuery();
|
||||
}
|
||||
public static useLatestVersion() { return GQL.useLatestVersionQuery({ notifyOnNetworkStatusChange: true, errorPolicy: 'ignore' }); }
|
||||
|
||||
|
||||
public static useConfiguration() {
|
||||
return GQL.useConfigurationQuery();
|
||||
|
|
|
@ -7,7 +7,7 @@ import * as ApolloReactHooks from '@apollo/react-hooks';
|
|||
export type Maybe<T> = T | null;
|
||||
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
// Generated in 2020-01-21T19:57:40+01:00
|
||||
// Generated in 2020-01-23T14:20:33+01:00
|
||||
|
||||
/** All built-in and custom scalars, mapped to their actual values */
|
||||
export type Scalars = {
|
||||
|
@ -548,6 +548,8 @@ export type Query = {
|
|||
allTags: Array<Tag>,
|
||||
/** Version */
|
||||
version: Version,
|
||||
/** LatestVersion */
|
||||
latestversion: ShortVersion,
|
||||
};
|
||||
|
||||
|
||||
|
@ -788,6 +790,8 @@ export type SceneFilterType = {
|
|||
rating?: Maybe<IntCriterionInput>,
|
||||
/** Filter by resolution */
|
||||
resolution?: Maybe<ResolutionEnum>,
|
||||
/** Filter by duration (in seconds) */
|
||||
duration?: Maybe<IntCriterionInput>,
|
||||
/** Filter to only include scenes which have markers. `true` or `false` */
|
||||
has_markers?: Maybe<Scalars['String']>,
|
||||
/** Filter to only include scenes missing this property */
|
||||
|
@ -1012,6 +1016,12 @@ export enum ScrapeType {
|
|||
Url = 'URL'
|
||||
}
|
||||
|
||||
export type ShortVersion = {
|
||||
__typename?: 'ShortVersion',
|
||||
shorthash: Scalars['String'],
|
||||
url: Scalars['String'],
|
||||
};
|
||||
|
||||
export enum SortDirectionEnum {
|
||||
Asc = 'ASC',
|
||||
Desc = 'DESC'
|
||||
|
@ -1739,6 +1749,17 @@ export type VersionQuery = (
|
|||
) }
|
||||
);
|
||||
|
||||
export type LatestVersionQueryVariables = {};
|
||||
|
||||
|
||||
export type LatestVersionQuery = (
|
||||
{ __typename?: 'Query' }
|
||||
& { latestversion: (
|
||||
{ __typename?: 'ShortVersion' }
|
||||
& Pick<ShortVersion, 'shorthash' | 'url'>
|
||||
) }
|
||||
);
|
||||
|
||||
export type FindPerformersQueryVariables = {
|
||||
filter?: Maybe<FindFilterType>,
|
||||
performer_filter?: Maybe<PerformerFilterType>
|
||||
|
@ -3750,6 +3771,45 @@ export function useVersionLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHook
|
|||
export type VersionQueryHookResult = ReturnType<typeof useVersionQuery>;
|
||||
export type VersionLazyQueryHookResult = ReturnType<typeof useVersionLazyQuery>;
|
||||
export type VersionQueryResult = ApolloReactCommon.QueryResult<VersionQuery, VersionQueryVariables>;
|
||||
export const LatestVersionDocument = gql`
|
||||
query LatestVersion {
|
||||
latestversion {
|
||||
shorthash
|
||||
url
|
||||
}
|
||||
}
|
||||
`;
|
||||
export type LatestVersionComponentProps = Omit<ApolloReactComponents.QueryComponentOptions<LatestVersionQuery, LatestVersionQueryVariables>, 'query'>;
|
||||
|
||||
export const LatestVersionComponent = (props: LatestVersionComponentProps) => (
|
||||
<ApolloReactComponents.Query<LatestVersionQuery, LatestVersionQueryVariables> query={LatestVersionDocument} {...props} />
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* __useLatestVersionQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useLatestVersionQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useLatestVersionQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useLatestVersionQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useLatestVersionQuery(baseOptions?: ApolloReactHooks.QueryHookOptions<LatestVersionQuery, LatestVersionQueryVariables>) {
|
||||
return ApolloReactHooks.useQuery<LatestVersionQuery, LatestVersionQueryVariables>(LatestVersionDocument, baseOptions);
|
||||
}
|
||||
export function useLatestVersionLazyQuery(baseOptions?: ApolloReactHooks.LazyQueryHookOptions<LatestVersionQuery, LatestVersionQueryVariables>) {
|
||||
return ApolloReactHooks.useLazyQuery<LatestVersionQuery, LatestVersionQueryVariables>(LatestVersionDocument, baseOptions);
|
||||
}
|
||||
export type LatestVersionQueryHookResult = ReturnType<typeof useLatestVersionQuery>;
|
||||
export type LatestVersionLazyQueryHookResult = ReturnType<typeof useLatestVersionLazyQuery>;
|
||||
export type LatestVersionQueryResult = ApolloReactCommon.QueryResult<LatestVersionQuery, LatestVersionQueryVariables>;
|
||||
export const FindPerformersDocument = gql`
|
||||
query FindPerformers($filter: FindFilterType, $performer_filter: PerformerFilterType) {
|
||||
findPerformers(filter: $filter, performer_filter: $performer_filter) {
|
||||
|
|
Loading…
Reference in New Issue