small refinment

This commit is contained in:
arc-alex
2023-12-13 17:31:33 +01:00
parent d763f3f6b9
commit 0024b02638
4 changed files with 62 additions and 48 deletions
@@ -2,6 +2,8 @@ import { ChangeEvent, useEffect, useRef, useState } from 'react';
import { import {
Button, Button,
Input, Input,
InputGroup,
InputRightAddon,
Modal, Modal,
ModalBody, ModalBody,
ModalCloseButton, ModalCloseButton,
@@ -193,53 +195,64 @@ export default function SheetsModal(props: SheetsModalProps) {
{sheetState.auth ? <div>You are authenticated</div> : <div>You are not authenticated</div>} {sheetState.auth ? <div>You are authenticated</div> : <div>You are not authenticated</div>}
<div> <div>
<label htmlFor='sheetid'>Sheet ID </label> <label htmlFor='sheetid'>Sheet ID </label>
<Input <InputGroup size='sm'>
type='text' <Input
ref={sheetid} type='text'
id='sheetid' ref={sheetid}
width='240px' id='sheetid'
size='sm' width='240px'
textAlign='right' textAlign='right'
variant='ontime-filled-on-light' variant='ontime-filled-on-light'
/> />
{sheetState.id ? <IoCheckmarkCircleOutline /> : <IoCloseCircleOutline />} <InputRightAddon>
{sheetState.id ? <IoCheckmarkCircleOutline color='green' /> : <IoCloseCircleOutline color='red' />}
</InputRightAddon>
</InputGroup>
<br /> <br />
<label htmlFor='worksheet'>Worksheet </label> <label htmlFor='worksheet'>Worksheet </label>
<Input <InputGroup size='sm'>
type='text' <Input
ref={worksheet} type='text'
id='worksheet' ref={worksheet}
width='240px' id='worksheet'
size='sm' width='240px'
textAlign='right' textAlign='right'
variant='ontime-filled-on-light' variant='ontime-filled-on-light'
/> />
{sheetState.worksheet ? <IoCheckmarkCircleOutline /> : <IoCloseCircleOutline />} <InputRightAddon>
{sheetState.worksheet ? (
<IoCheckmarkCircleOutline color='green' />
) : (
<IoCloseCircleOutline color='red' />
)}
</InputRightAddon>
</InputGroup>
</div>
<br />
<div>
<Button
disabled={!sheetState.worksheet}
variant='ontime-subtle-on-light'
padding='0 2em'
onClick={handlePullData}
rightIcon={<IoArrowDownCircleOutline />}
>
Pull Rundown
</Button>
<Button
disabled={!sheetState.worksheet}
variant='ontime-subtle-on-light'
padding='0 2em'
onClick={handlePushData}
rightIcon={<IoArrowUpCircleOutline />}
>
Push Rundown
</Button>
</div> </div>
</> </>
)} )}
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
{!rundown && (
<div>
<Button
variant='ontime-subtle-on-light'
padding='0 2em'
onClick={handlePullData}
rightIcon={<IoArrowDownCircleOutline />}
>
Pull data
</Button>
<Button
variant='ontime-subtle-on-light'
padding='0 2em'
onClick={handlePushData}
rightIcon={<IoArrowUpCircleOutline />}
>
Push data
</Button>
</div>
)}
<Button variant='ontime-ghost-on-light'>Reset</Button> <Button variant='ontime-ghost-on-light'>Reset</Button>
{!rundown && ( {!rundown && (
<Button variant='ontime-filled' padding='0 2em' onClick={handelSave}> <Button variant='ontime-filled' padding='0 2em' onClick={handelSave}>
@@ -508,13 +508,14 @@ export async function uploadGoogleSheetClientFile(req, res) {
/** /**
* @returns link to sheet auth url * @returns link to sheet auth url
* @method GET
*/ */
export async function sheetAuthUrl(req, res) { export async function sheetAuthUrl(req, res) {
const successful = await Sheet.openAuthServer(); const authUrl = await Sheet.openAuthServer();
if (successful === false) { if (!authUrl) {
res.status(500).send('bad'); res.status(500).send('Unable to start auth server');
} else { } else {
res.status(200).send(successful); res.status(200).send(authUrl);
} }
} }
+3 -3
View File
@@ -261,7 +261,7 @@ class sheet {
* @returns {Promise<string | false>} - returns url to serve on success * @returns {Promise<string | false>} - returns url to serve on success
* @throws * @throws
*/ */
public async openAuthServer(): Promise<string | false> { public async openAuthServer(): Promise<string | null> {
//TODO: this only works on local networks //TODO: this only works on local networks
if (sheet.authUrl) { if (sheet.authUrl) {
clearTimeout(this.authServerTimeout); clearTimeout(this.authServerTimeout);
@@ -278,13 +278,13 @@ class sheet {
logger.error(LogOrigin.Server, `${err}`), logger.error(LogOrigin.Server, `${err}`),
); );
if (!creadFile) { if (!creadFile) {
return false; return null;
} }
const keyFile = JSON.parse(creadFile); const keyFile = JSON.parse(creadFile);
const keys = keyFile.installed || keyFile.web; const keys = keyFile.installed || keyFile.web;
if (!keys.redirect_uris || keys.redirect_uris.length === 0) { if (!keys.redirect_uris || keys.redirect_uris.length === 0) {
logger.error(LogOrigin.Server, `${invalidRedirectUri}`); logger.error(LogOrigin.Server, `${invalidRedirectUri}`);
return false; return null;
} }
// create an oAuth client to authorize the API call // create an oAuth client to authorize the API call
@@ -7,4 +7,4 @@ export type GoogleSheetState = {
auth: boolean; auth: boolean;
id: boolean; id: boolean;
worksheet: boolean; worksheet: boolean;
}; };