cleanup: fix eslint errors

This commit is contained in:
Jordan Knott 2020-04-10 15:31:12 -05:00
parent dc4792f7c2
commit 6b41461a6a
25 changed files with 109 additions and 106 deletions

3
web/.eslintignore Normal file
View File

@ -0,0 +1,3 @@
src/shared/generated/*.tsx
src/shared/generated/*.ts
src/react-app-env.d.ts

View File

@ -3,6 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@apollo/react-common": "^3.1.4",
"@apollo/react-hooks": "^3.1.3", "@apollo/react-hooks": "^3.1.3",
"@fortawesome/fontawesome-svg-core": "^1.2.27", "@fortawesome/fontawesome-svg-core": "^1.2.27",
"@fortawesome/free-brands-svg-icons": "^5.12.1", "@fortawesome/free-brands-svg-icons": "^5.12.1",

View File

@ -1,12 +1,12 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
import { setAccessToken } from 'shared/utils/accessToken'; import { setAccessToken } from 'shared/utils/accessToken';
import NormalizeStyles from './NormalizeStyles';
import BaseStyles from './BaseStyles';
import Routes from './Routes';
import Navbar from 'shared/components/Navbar'; import Navbar from 'shared/components/Navbar';
import GlobalTopNavbar from 'App/TopNavbar'; import GlobalTopNavbar from 'App/TopNavbar';
import styled from 'styled-components'; import styled from 'styled-components';
import NormalizeStyles from './NormalizeStyles';
import BaseStyles from './BaseStyles';
import Routes from './Routes';
const history = createBrowserHistory(); const history = createBrowserHistory();

View File

@ -1,7 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import styled from 'styled-components/macro'; import styled from 'styled-components/macro';
import { useQuery, useMutation } from '@apollo/react-hooks';
import gql from 'graphql-tag';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { import {
useFindProjectQuery, useFindProjectQuery,
@ -120,7 +118,7 @@ const Project = () => {
const { loading, data } = useFindProjectQuery({ const { loading, data } = useFindProjectQuery({
variables: { projectId }, variables: { projectId },
onCompleted: newData => { onCompleted: newData => {
let newListsData: State = { tasks: {}, columns: {} }; const newListsData: State = { tasks: {}, columns: {} };
newData.findProject.taskGroups.forEach((taskGroup: TaskGroup) => { newData.findProject.taskGroups.forEach((taskGroup: TaskGroup) => {
newListsData.columns[taskGroup.taskGroupID] = { newListsData.columns[taskGroup.taskGroupID] = {
taskGroupID: taskGroup.taskGroupID, taskGroupID: taskGroup.taskGroupID,
@ -166,16 +164,13 @@ const Project = () => {
}; };
const onCardCreate = (taskGroupID: string, name: string) => { const onCardCreate = (taskGroupID: string, name: string) => {
const taskGroupTasks = Object.values(listsData.tasks).filter((task: Task) => task.taskGroupID === taskGroupID); const taskGroupTasks = Object.values(listsData.tasks).filter((task: Task) => task.taskGroupID === taskGroupID);
var position = 65535; let position = 65535;
console.log(taskGroupID);
console.log(taskGroupTasks);
if (taskGroupTasks.length !== 0) { if (taskGroupTasks.length !== 0) {
const [lastTask] = taskGroupTasks.sort((a: any, b: any) => a.position - b.position).slice(-1); const [lastTask] = taskGroupTasks.sort((a: any, b: any) => a.position - b.position).slice(-1);
console.log(`last tasks position ${lastTask.position}`);
position = Math.ceil(lastTask.position) * 2 + 1; position = Math.ceil(lastTask.position) * 2 + 1;
} }
createTask({ variables: { taskGroupID: taskGroupID, name: name, position: position } }); createTask({ variables: { taskGroupID, name, position } });
}; };
const onQuickEditorOpen = (e: ContextMenuEvent) => { const onQuickEditorOpen = (e: ContextMenuEvent) => {
const currentTask = Object.values(listsData.tasks).find(task => task.taskID === e.taskID); const currentTask = Object.values(listsData.tasks).find(task => task.taskID === e.taskID);
@ -211,16 +206,16 @@ const Project = () => {
</MainContent> </MainContent>
{quickCardEditor.isOpen && ( {quickCardEditor.isOpen && (
<QuickCardEditor <QuickCardEditor
isOpen={true} isOpen
taskID={quickCardEditor.task ? quickCardEditor.task.taskID : ''} taskID={quickCardEditor.task ? quickCardEditor.task.taskID : ''}
taskGroupID={quickCardEditor.task ? quickCardEditor.task.taskGroupID : ''} taskGroupID={quickCardEditor.task ? quickCardEditor.task.taskGroupID : ''}
cardTitle={quickCardEditor.task ? quickCardEditor.task.name : ''} cardTitle={quickCardEditor.task ? quickCardEditor.task.name : ''}
onCloseEditor={() => setQuickCardEditor(initialQuickCardEditorState)} onCloseEditor={() => setQuickCardEditor(initialQuickCardEditorState)}
onEditCard={(listId: string, cardId: string, cardName: string) => onEditCard={(_listId: string, cardId: string, cardName: string) => {
updateTaskName({ variables: { taskID: cardId, name: cardName } }) updateTaskName({ variables: { taskID: cardId, name: cardName } });
} }}
onOpenPopup={() => console.log()} onOpenPopup={() => console.log()}
onArchiveCard={(listId: string, cardId: string) => deleteTask({ variables: { taskID: cardId } })} onArchiveCard={(_listId: string, cardId: string) => deleteTask({ variables: { taskID: cardId } })}
labels={[]} labels={[]}
top={quickCardEditor.top} top={quickCardEditor.top}
left={quickCardEditor.left} left={quickCardEditor.left}

View File

@ -13,6 +13,7 @@ import App from './App';
// https://able.bio/AnasT/apollo-graphql-async-access-token-refresh--470t1c8 // https://able.bio/AnasT/apollo-graphql-async-access-token-refresh--470t1c8
let forward$;
let isRefreshing = false; let isRefreshing = false;
let pendingRequests: any = []; let pendingRequests: any = [];
@ -21,56 +22,57 @@ const resolvePendingRequests = () => {
pendingRequests = []; pendingRequests = [];
}; };
const resolvePromise = (resolve: () => void) => {
pendingRequests.push(() => resolve());
};
const resetPendingRequests = () => {
pendingRequests = [];
};
const setRefreshing = (newVal: boolean) => {
isRefreshing = newVal;
};
const errorLink = onError(({ graphQLErrors, networkError, operation, forward }) => { const errorLink = onError(({ graphQLErrors, networkError, operation, forward }) => {
if (graphQLErrors) { if (graphQLErrors) {
for (const err of graphQLErrors) { for (const err of graphQLErrors) {
switch (err!.extensions!.code) { if (err.extensions && err.extensions.code) {
switch (err.extensions.code) {
case 'UNAUTHENTICATED': case 'UNAUTHENTICATED':
// error code is set to UNAUTHENTICATED
// when AuthenticationError thrown in resolver
let forward$;
if (!isRefreshing) { if (!isRefreshing) {
isRefreshing = true; setRefreshing(true);
forward$ = fromPromise( forward$ = fromPromise(
getNewToken() getNewToken()
.then((response: any) => { .then((response: any) => {
// Store the new tokens for your auth link
setAccessToken(response.accessToken); setAccessToken(response.accessToken);
resolvePendingRequests(); resolvePendingRequests();
return response.accessToken; return response.accessToken;
}) })
.catch((error: any) => { .catch(() => {
pendingRequests = []; resetPendingRequests();
// TODO // TODO
// Handle token refresh errors e.g clear stored tokens, redirect to login, ... // Handle token refresh errors e.g clear stored tokens, redirect to login, ...
return; return undefined;
}) })
.finally(() => { .finally(() => {
isRefreshing = false; setRefreshing(false);
}), }),
).filter(value => Boolean(value)); ).filter(value => Boolean(value));
} else { } else {
// Will only emit once the Promise is resolved forward$ = fromPromise(new Promise(resolvePromise));
forward$ = fromPromise(
new Promise(resolve => {
pendingRequests.push(() => resolve());
}),
);
} }
return forward$.flatMap(() => forward(operation)); return forward$.flatMap(() => forward(operation));
default: default:
// pass // pass
} }
} }
} }
}
if (networkError) { if (networkError) {
console.log(`[Network error]: ${networkError}`); console.log(`[Network error]: ${networkError}`);
// if you would also like to retry automatically on
// network errors, we recommend that you use
// apollo-link-retry
} }
return undefined;
}); });
const requestLink = new ApolloLink( const requestLink = new ApolloLink(
@ -78,10 +80,10 @@ const requestLink = new ApolloLink(
new Observable((observer: any) => { new Observable((observer: any) => {
let handle: any; let handle: any;
Promise.resolve(operation) Promise.resolve(operation)
.then((operation: any) => { .then((op: any) => {
const accessToken = getAccessToken(); const accessToken = getAccessToken();
if (accessToken) { if (accessToken) {
operation.setContext({ op.setContext({
headers: { headers: {
Authorization: `Bearer ${accessToken}`, Authorization: `Bearer ${accessToken}`,
}, },
@ -98,7 +100,9 @@ const requestLink = new ApolloLink(
.catch(observer.error.bind(observer)); .catch(observer.error.bind(observer));
return () => { return () => {
if (handle) handle.unsubscribe(); if (handle) {
handle.unsubscribe();
}
}; };
}), }),
); );
@ -106,11 +110,14 @@ const requestLink = new ApolloLink(
const client = new ApolloClient({ const client = new ApolloClient({
link: ApolloLink.from([ link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => { onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) => graphQLErrors.forEach(({ message, locations, path }) =>
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`), console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`),
); );
if (networkError) console.log(`[Network error]: ${networkError}`); }
if (networkError) {
console.log(`[Network error]: ${networkError}`);
}
}), }),
errorLink, errorLink,
requestLink, requestLink,

View File

@ -1,7 +1,7 @@
import React, { useRef } from 'react'; import React, { useRef } from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import LabelColors from 'shared/constants/labelColors'; import LabelColors from 'shared/constants/labelColors';
import Card from './index'; import Card from '.';
export default { export default {
component: Card, component: Card,

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import CardComposer from './index'; import CardComposer from '.';
export default { export default {
component: CardComposer, component: CardComposer,

View File

@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import useOnEscapeKeyDown from 'shared/hooks/onEscapeKeyDown'; import useOnEscapeKeyDown from 'shared/hooks/onEscapeKeyDown';
import { faTimes } from '@fortawesome/free-solid-svg-icons'; import { faTimes } from '@fortawesome/free-solid-svg-icons';
import TextareaAutosize from 'react-autosize-textarea'; import useOnOutsideClick from 'shared/hooks/onOutsideClick';
import { import {
CardComposerWrapper, CardComposerWrapper,
@ -15,7 +15,6 @@ import {
ComposerControlsSaveSection, ComposerControlsSaveSection,
ComposerControlsActionsSection, ComposerControlsActionsSection,
} from './Styles'; } from './Styles';
import useOnOutsideClick from 'shared/hooks/onOutsideClick';
type Props = { type Props = {
isOpen: boolean; isOpen: boolean;

View File

@ -1,8 +1,7 @@
import React, { createRef, useState } from 'react'; import React, { createRef, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { action } from '@storybook/addon-actions';
import DropdownMenu from './index'; import DropdownMenu from '.';
export default { export default {
component: DropdownMenu, component: DropdownMenu,

View File

@ -3,7 +3,7 @@ import { action } from '@storybook/addon-actions';
import Card from 'shared/components/Card'; import Card from 'shared/components/Card';
import CardComposer from 'shared/components/CardComposer'; import CardComposer from 'shared/components/CardComposer';
import LabelColors from 'shared/constants/labelColors'; import LabelColors from 'shared/constants/labelColors';
import List, { ListCards } from './index'; import List, { ListCards } from '.';
export default { export default {
component: List, component: List,

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import Lists from './index';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import Lists from '.';
export default { export default {
component: Lists, component: Lists,

View File

@ -9,3 +9,5 @@ export const Container = styled.div`
overflow-y: hidden; overflow-y: hidden;
padding-bottom: 8px; padding-bottom: 8px;
`; `;
export default Container;

View File

@ -1,9 +1,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { DragDropContext, Droppable, Draggable, DropResult } from 'react-beautiful-dnd'; import { DragDropContext, Droppable, Draggable, DropResult } from 'react-beautiful-dnd';
import List, { ListCards } from 'shared/components/List'; import List, { ListCards } from 'shared/components/List';
import Card from 'shared/components/Card'; import Card from 'shared/components/Card';
import { Container } from './Styles';
import CardComposer from 'shared/components/CardComposer'; import CardComposer from 'shared/components/CardComposer';
import { import {
isPositionChanged, isPositionChanged,
@ -12,6 +10,8 @@ import {
getAfterDropDraggableList, getAfterDropDraggableList,
} from 'shared/utils/draggables'; } from 'shared/utils/draggables';
import { Container } from './Styles';
interface Columns { interface Columns {
[key: string]: TaskGroup; [key: string]: TaskGroup;
} }
@ -28,13 +28,6 @@ type Props = {
onQuickEditorOpen: (e: ContextMenuEvent) => void; onQuickEditorOpen: (e: ContextMenuEvent) => void;
}; };
type OnDragEndProps = {
draggableId: any;
source: any;
destination: any;
type: any;
};
const Lists = ({ columns, tasks, onCardDrop, onListDrop, onCardCreate, onQuickEditorOpen }: Props) => { const Lists = ({ columns, tasks, onCardDrop, onListDrop, onCardCreate, onQuickEditorOpen }: Props) => {
const onDragEnd = ({ draggableId, source, destination, type }: DropResult) => { const onDragEnd = ({ draggableId, source, destination, type }: DropResult) => {
if (typeof destination === 'undefined') return; if (typeof destination === 'undefined') return;
@ -137,7 +130,7 @@ const Lists = ({ columns, tasks, onCardDrop, onListDrop, onCardCreate, onQuickEd
setCurrentComposer(''); setCurrentComposer('');
onCardCreate(column.taskGroupID, name); onCardCreate(column.taskGroupID, name);
}} }}
isOpen={true} isOpen
/> />
)} )}
</ListCards> </ListCards>

View File

@ -1,9 +1,9 @@
import React, { useState } from 'react'; import React from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import NormalizeStyles from 'App/NormalizeStyles'; import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles'; import BaseStyles from 'App/BaseStyles';
import styled from 'styled-components'; import styled from 'styled-components';
import Login from './index'; import Login from '.';
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

View File

@ -1,9 +1,8 @@
import React, { useState } from 'react'; import React from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import NormalizeStyles from 'App/NormalizeStyles'; import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles'; import BaseStyles from 'App/BaseStyles';
import styled from 'styled-components'; import Modal from '.';
import Modal from './index';
export default { export default {
component: Modal, component: Modal,

View File

@ -6,7 +6,7 @@ import useOnEscapeKeyDown from 'shared/hooks/onEscapeKeyDown';
import { ScrollOverlay, ClickableOverlay, StyledModal } from './Styles'; import { ScrollOverlay, ClickableOverlay, StyledModal } from './Styles';
const $root: HTMLElement = document.getElementById('root')!; const $root: HTMLElement = document.getElementById('root')!; // eslint-disable-line @typescript-eslint/no-non-null-assertion
type ModalProps = { type ModalProps = {
width: number; width: number;

View File

@ -2,8 +2,8 @@ import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import NormalizeStyles from 'App/NormalizeStyles'; import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles'; import BaseStyles from 'App/BaseStyles';
import { Home, Stack, Users, Question } from 'shared/icons'; import { Home } from 'shared/icons';
import Navbar, { ActionButton, ButtonContainer, PrimaryLogo } from './index'; import Navbar, { ActionButton, ButtonContainer, PrimaryLogo } from '.';
export default { export default {
component: Navbar, component: Navbar,

View File

@ -1,8 +1,8 @@
import React, { createRef, useState } from 'react'; import React, { useState } from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import LabelColors from 'shared/constants/labelColors'; import LabelColors from 'shared/constants/labelColors';
import MenuTypes from 'shared/constants/menuTypes'; import MenuTypes from 'shared/constants/menuTypes';
import PopupMenu from './index'; import PopupMenu from '.';
export default { export default {
component: PopupMenu, component: PopupMenu,

View File

@ -1,7 +1,6 @@
import React, { useState } from 'react'; import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { action } from '@storybook/addon-actions'; import ProjectGridItem from '.';
import ProjectGridItem from './';
export default { export default {
component: ProjectGridItem, component: ProjectGridItem,

View File

@ -1,9 +1,8 @@
import React from 'react'; import React from 'react';
import NormalizeStyles from 'App/NormalizeStyles'; import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles'; import BaseStyles from 'App/BaseStyles';
import Sidebar from './index';
import Navbar from 'shared/components/Navbar'; import Navbar from 'shared/components/Navbar';
import Sidebar from '.';
export default { export default {
component: Sidebar, component: Sidebar,

View File

@ -1,6 +1,6 @@
import styled from 'styled-components'; import styled from 'styled-components';
export const Container = styled.div` const Container = styled.div`
position: fixed; position: fixed;
z-index: 99; z-index: 99;
top: 0px; top: 0px;
@ -13,3 +13,5 @@ export const Container = styled.div`
background: rgb(244, 245, 247); background: rgb(244, 245, 247);
border-right: 1px solid rgb(223, 225, 230); border-right: 1px solid rgb(223, 225, 230);
`; `;
export default Container;

View File

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { Container } from './Styles'; import Container from './Styles';
const Sidebar = () => { const Sidebar = () => {
return <Container></Container>; return <Container />;
}; };
export default Sidebar; export default Sidebar;

View File

@ -2,9 +2,8 @@ import React, { useState } from 'react';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import NormalizeStyles from 'App/NormalizeStyles'; import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles'; import BaseStyles from 'App/BaseStyles';
import styled from 'styled-components';
import Modal from 'shared/components/Modal'; import Modal from 'shared/components/Modal';
import TaskDetails from './'; import TaskDetails from '.';
export default { export default {
component: TaskDetails, component: TaskDetails,
@ -35,9 +34,9 @@ export const Default = () => {
name: 'Hello, world', name: 'Hello, world',
position: 1, position: 1,
labels: [], labels: [],
description: description, description,
}} }}
onTaskDescriptionChange={(task, desc) => setDescription(desc)} onTaskDescriptionChange={(_task, desc) => setDescription(desc)}
/> />
); );
}} }}

View File

@ -1,11 +1,9 @@
import React, { createRef, useState } from 'react'; import React, { useState } from 'react';
import NormalizeStyles from 'App/NormalizeStyles'; import NormalizeStyles from 'App/NormalizeStyles';
import BaseStyles from 'App/BaseStyles'; import BaseStyles from 'App/BaseStyles';
import TopNavbar from './index';
import { action } from '@storybook/addon-actions'; import { action } from '@storybook/addon-actions';
import DropdownMenu from 'shared/components/DropdownMenu'; import DropdownMenu from 'shared/components/DropdownMenu';
import TopNavbar from '.';
export default { export default {
component: TopNavbar, component: TopNavbar,

View File

@ -20,6 +20,14 @@
ts-invariant "^0.4.4" ts-invariant "^0.4.4"
tslib "^1.10.0" tslib "^1.10.0"
"@apollo/react-common@^3.1.4":
version "3.1.4"
resolved "https://registry.yarnpkg.com/@apollo/react-common/-/react-common-3.1.4.tgz#ec13c985be23ea8e799c9ea18e696eccc97be345"
integrity sha512-X5Kyro73bthWSCBJUC5XYQqMnG0dLWuDZmVkzog9dynovhfiVCV4kPSdgSIkqnb++cwCzOVuQ4rDKVwo2XRzQA==
dependencies:
ts-invariant "^0.4.4"
tslib "^1.10.0"
"@apollo/react-hooks@^3.1.3": "@apollo/react-hooks@^3.1.3":
version "3.1.3" version "3.1.3"
resolved "https://registry.yarnpkg.com/@apollo/react-hooks/-/react-hooks-3.1.3.tgz#ad42c7af78e81fee0f30e53242640410d5bd0293" resolved "https://registry.yarnpkg.com/@apollo/react-hooks/-/react-hooks-3.1.3.tgz#ad42c7af78e81fee0f30e53242640410d5bd0293"