Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"react/prop-types": "off",
"comma-dangle": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": ["error"]
"@typescript-eslint/no-use-before-define": ["error"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"]
}
}
2 changes: 1 addition & 1 deletion components/AddRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fields = [
}
]

const AddRule = ({ onAddRule }) => {
const AddRule = () => {
const formRef = useRef()
const [error, setError] = useState(null)
const router = useRouter()
Expand Down
8 changes: 7 additions & 1 deletion components/Footer.js → components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react'
import { Flex, Box, Link } from 'ooni-components'
import styled from 'styled-components'

Expand All @@ -16,7 +17,12 @@ const FooterColumn = styled(Flex).attrs({
mx: 3
})``

const FooterItem = ({ label, link }) => (
type FooterItemProps = {
label: React.ReactNode,
link: string
}

const FooterItem: React.FunctionComponent<FooterItemProps> = ({ label, link }) => (
<Link my={1} mx={3} color='gray2' href={link}>{label}</Link>
)

Expand Down
10 changes: 7 additions & 3 deletions components/Layout.js → components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import * as React from 'react'
import NextHead from 'next/head'
import styled from 'styled-components'
import { Container, Flex } from 'ooni-components'
Expand All @@ -11,14 +11,18 @@ const PageWrapper = styled(Flex)`
min-height: 100vh;
`

const Layout = ({ title = '', children }) => {
type LayoutProps = {
title: string,
children: React.ReactNode
}
const Layout: React.FunctionComponent<LayoutProps> = ({ title = '', children }) => {
return (
<>
<NextHead>
<title>{title}</title>
</NextHead>
<PageWrapper>
<NavBar title={title} />
<NavBar />
<Container sx={{ flex: 1, width: '100%' }}>
{children}
</Container>
Expand Down
2 changes: 1 addition & 1 deletion components/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const Button = styled.button`
// Dynamic button
// * Starts editing a row
// * Switches to a two button component to confirm or cancel a row edit operation.
const EditButton = ({ resetRow, onRowUpdate, row: { index, values, state: { isEditing, dirty }, setState } }) => {
const EditButton = ({ resetRow, onRowUpdate, row: { index, values, state: { isEditing, /* dirty */ }, setState } }) => {
const onEdit = useCallback(() => {
// TODO: Don't edit if another row is still being edited
setState(state => ({ ...state, isEditing: true }))
Expand Down
12 changes: 6 additions & 6 deletions components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import styled, { keyframes } from 'styled-components'

const rotate = (dir) => keyframes`
const rotate = (dir: number) => keyframes`
from {
transform: rotate(0deg);
}
Expand All @@ -19,12 +19,12 @@ const Spinner = styled.div<SpinnerProps>`
animation: ${props => rotate(props.$dir)} ${props => 2 / props.speed}s linear infinite;
`

interface LoadingProps {
readonly size?: number;
readonly speed?: number;
readonly dir?: number;
type LoadingProps = {
size?: number;
speed?: number;
dir?: number;
}
const Loading: React.FC<LoadingProps> = ({ size = 64, speed = 1, dir = 1 }) => (
const Loading: React.FunctionComponent<LoadingProps> = ({ size = 64, speed = 1, dir = 1 }) => (
<Spinner speed={speed} $dir={dir}>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
38 changes: 27 additions & 11 deletions components/LoginForm.js → components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,39 @@ const StyledInputContainer = styled(Box).attrs({
}
`

export const LoginModal = ({ isShowing, hide, onLogin }) =>
<Modal show={isShowing} onHideClick={hide}>
<LoginForm onLogin={onLogin} />
</Modal>
type LoginFormData = {
email_address: string,
nickname: string
}

export const LoginForm = ({ onLogin }) => {
const [submitting, setSubmitting] = useState(false)
const [loginError, setError] = useState(null)
type LoginFormProps = {
onLogin: Function
}

const { handleSubmit, register, formState, reset } = useForm({
export const LoginForm: React.FunctionComponent<LoginFormProps> = ({ onLogin }) => {
const [submitting, setSubmitting] = useState(false)
const [loginError, setError] = useState<string | null>(null)
const { handleSubmit, register, formState, reset } = useForm<LoginFormData>({
mode: 'onTouched',
})

const { errors, isValid, isDirty } = formState

const onSubmit = useCallback((data) => {
const onSubmit = useCallback((data: LoginFormData) => {
const { email_address, nickname } = data
const registerApi = async (email_address, nickname) => {
const registerApi = async (email_address: string, nickname: string) => {
try {
await registerUser(email_address, nickname)
if (typeof onLogin === 'function') {
onLogin()
}
} catch (e) {
setError(e.message)
// Reset form to mark `isDirty` as false
reset({}, { keepValues: true })
console.error(e)
if (e instanceof Error) {
setError(e.message)
}
} finally {
setSubmitting(false)
}
Expand Down Expand Up @@ -119,4 +125,14 @@ export const LoginForm = ({ onLogin }) => {
)
}

type LoginModalProps = {
isShowing: boolean,
hide: Function,
onLogin: Function
}
export const LoginModal: React.FunctionComponent<LoginModalProps> = ({ isShowing, hide, onLogin }) =>
<Modal show={isShowing} onHideClick={hide}>
<LoginForm onLogin={onLogin} />
</Modal>

export default LoginForm
145 changes: 0 additions & 145 deletions components/lib/api.js

This file was deleted.

Loading