Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Maintenance and Updates #198

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions .babelrc

This file was deleted.

3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://postgres:[email protected]:5432/postgres"
DATABASE_URL="postgresql://postgres:[email protected]:5432/postgres"
NEXTAUTH_SECRET= # run `openssl rand -base64 32` to generate your secret
33 changes: 9 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,30 @@ module.exports = {
es6: true,
},
parserOptions: { ecmaVersion: 8 }, // to enable features such as async/await
ignorePatterns: ['node_modules/*', '.next/*', '.out/*', '!.prettierrc.js'], // We don't want to lint generated files nor node_modules, but we want to lint .prettierrc.js (ignored by default by eslint)
extends: ['eslint:recommended'],
ignorePatterns: ['node_modules/*', '.next/*', '.out/*', '!.prettierrc.js'],
plugins: ['@typescript-eslint'],
extends: [
'next/core-web-vitals',
'plugin:@typescript-eslint/recommended',
'prettier',
],
overrides: [
// This configuration will apply only to TypeScript files
{
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
settings: { react: { version: 'detect' } },
env: {
browser: true,
node: true,
es6: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended', // TypeScript rules
'plugin:react/recommended', // React rules
'plugin:react-hooks/recommended', // React hooks rules
'plugin:jsx-a11y/recommended', // Accessibility rules
'plugin:prettier/recommended', // Prettier plugin
],
rules: {
// We will use TypeScript's types for component props instead
'react/prop-types': 'off',

// No need to import React when using Next.js
'react/react-in-jsx-scope': 'off',

// This rule is not compatible with Next.js's <Link /> components
'jsx-a11y/anchor-is-valid': 'off',

// Why would you want unused vars?
'@typescript-eslint/no-unused-vars': ['error'],

// I suggest this setting for requiring return types on functions only where useful
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',

'prettier/prettier': ['error', { endOfLine: 'auto' }, { usePrettierrc: true }], // Includes .prettierrc.js rules
},
},
],
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ prisma/dev.db
# sitemap - these get built automatically
public/sitemap.xml
public/robots.txt

# Sentry
.sentryclirc
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.18.2
2 changes: 0 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module.exports = {
// Change your rules accordingly to your coding style preferences.
// https://prettier.io/docs/en/options.html
semi: false,
trailingComma: 'es5',
singleQuote: true,
printWidth: 100,
tabWidth: 2,
useTabs: false,
}
27 changes: 21 additions & 6 deletions components/admin/AdminNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@chakra-ui/react'
import { CloseIcon, HamburgerIcon } from '@chakra-ui/icons'

import { signIn, signOut, useSession } from 'next-auth/client'
import { signIn, signOut, useSession } from 'next-auth/react'
import { RESPONSIVE_PADDING } from '../common/ContentBox'

const Links = [
Expand Down Expand Up @@ -52,7 +52,8 @@ interface NavLinkProps extends LinkDisplayProps {
}

const NavLink = ({ alwaysDisplay = false, ...props }: NavLinkProps) => {
const [session, loading] = useSession()
const { data: session, status } = useSession()
const loading = status === 'loading'

if (alwaysDisplay) {
return <LinkDisplay {...props} />
Expand All @@ -72,7 +73,7 @@ const NavLink = ({ alwaysDisplay = false, ...props }: NavLinkProps) => {

export default function AdminNav() {
const { isOpen, onOpen, onClose } = useDisclosure()
const [session] = useSession()
const { data: session } = useSession()

return (
<>
Expand All @@ -87,14 +88,24 @@ export default function AdminNav() {
<Flex alignItems={'center'} justifyContent={'space-between'}>
<IconButton
size={'md'}
icon={isOpen ? <CloseIcon color={'white'} /> : <HamburgerIcon color={'white'} />}
icon={
isOpen ? (
<CloseIcon color={'white'} />
) : (
<HamburgerIcon color={'white'} />
)
}
aria-label={'Open Menu'}
display={{ lg: 'none' }}
onClick={isOpen ? onClose : onOpen}
/>

<HStack spacing={8} alignItems={'center'}>
<HStack as={'nav'} spacing={4} display={{ base: 'none', lg: 'flex' }}>
<HStack
as={'nav'}
spacing={4}
display={{ base: 'none', lg: 'flex' }}
>
{Links.map((link) => (
<NavLink key={link.text} href={link.href} text={link.text} />
))}
Expand All @@ -105,7 +116,11 @@ export default function AdminNav() {
alignItems={{ base: 'flex-end', sm: 'center' }}
direction={{ base: 'column', sm: 'row' }}
>
<Text mb={{ base: 1, sm: 0 }} mr={{ sm: 4 }} fontSize={{ base: '0.75rem', sm: 'md' }}>
<Text
mb={{ base: 1, sm: 0 }}
mr={{ sm: 4 }}
fontSize={{ base: '0.75rem', sm: 'md' }}
>
{session?.user.email ?? ''}
</Text>
<NavLink
Expand Down
70 changes: 57 additions & 13 deletions components/admin/StoryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ interface UpdateStoryProps {
contentWarning: boolean
}

const updateStory = async ({ id, approved, deleted, contentWarning }: UpdateStoryProps) => {
const updateStory = async ({
id,
approved,
deleted,
contentWarning,
}: UpdateStoryProps) => {
const res = await fetch('/api/admin/update', {
method: 'PATCH',
headers: {
Expand Down Expand Up @@ -67,11 +72,19 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
const riding = ridings?.[0]?.riding

const { isOpen, onOpen, onClose } = useDisclosure()
const [{ deleted, approved, contentWarning }, setCardStatus] = useState({ ...rest })
const [{ deleted, approved, contentWarning }, setCardStatus] = useState({
...rest,
})
const [interacted, setInteracted] = useState(false)

const handleDeleteInteraction = async (props) => {
if (window.confirm(`Are you sure you want to ${props.deleted ? 'undelete' : 'delete'} this?`)) {
if (
window.confirm(
`Are you sure you want to ${
props.deleted ? 'undelete' : 'delete'
} this?`
)
) {
const { approved, deleted, ...rest } = await updateStory(props)
setCardStatus({ approved, deleted, ...rest })
setInteracted(approved || deleted)
Expand All @@ -92,7 +105,11 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
<Text mt={4} noOfLines={!filteredView || isOpen ? null : 4}>
{content}
</Text>
<Flex justifyContent={'flex-end'} pt={2} display={filteredView ? 'flex' : 'none'}>
<Flex
justifyContent={'flex-end'}
pt={2}
display={filteredView ? 'flex' : 'none'}
>
<Button
textAlign={'right'}
size={'sm'}
Expand All @@ -103,7 +120,12 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
</Button>
</Flex>
</Box>
<SimpleGrid columns={{ base: 1, md: 2 }} spacing={4} p={5} bg={'gray.100'}>
<SimpleGrid
columns={{ base: 1, md: 2 }}
spacing={4}
p={5}
bg={'gray.100'}
>
<Box>
<Label>Display Name and Postal Code</Label>
<Text>
Expand Down Expand Up @@ -133,14 +155,17 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
</Box>
<Box>
<Label>MPP and Riding</Label>
<Text>{riding ? `${riding.mppName}, ${riding.name}` : 'Unknown'}</Text>
<Text>
{riding ? `${riding.mppName}, ${riding.name}` : 'Unknown'}
</Text>
</Box>
<Box>
<Label>Submission Date</Label>
<Text>
{new Intl.DateTimeFormat('en-CA', { dateStyle: 'long', timeStyle: 'short' }).format(
createdAt
)}
{new Intl.DateTimeFormat('en-CA', {
dateStyle: 'long',
timeStyle: 'short',
}).format(createdAt)}
</Text>
</Box>
<Box>
Expand All @@ -150,7 +175,11 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
<Box>
<Label>ID and Link</Label>
<Text>
<SimpleLink href={`/story/${id}`} textDecoration={'underline'} target="_blank">
<SimpleLink
href={`/story/${id}`}
textDecoration={'underline'}
target="_blank"
>
{id}
</SimpleLink>
</Text>
Expand All @@ -173,7 +202,12 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
type="button"
bg={'white'}
onClick={() =>
handleDeleteInteraction({ id, approved: false, deleted: !deleted, contentWarning })
handleDeleteInteraction({
id,
approved: false,
deleted: !deleted,
contentWarning,
})
}
>
{deleted ? 'Undelete' : 'Delete'}
Expand All @@ -182,7 +216,12 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
colorScheme="blue"
type="button"
onClick={() =>
handleInteraction({ id, approved: !approved, deleted: false, contentWarning })
handleInteraction({
id,
approved: !approved,
deleted: false,
contentWarning,
})
}
>
{approved ? 'Unapprove' : 'Approve'}
Expand All @@ -193,7 +232,12 @@ export default function StoryCard({ story, filteredView }: StoryCardProps) {
type="button"
bg={'white'}
onClick={() =>
handleInteraction({ id, approved, deleted, contentWarning: !contentWarning })
handleInteraction({
id,
approved,
deleted,
contentWarning: !contentWarning,
})
}
>
{contentWarning ? 'Remove Content Warning' : 'Add Content Warning'}
Expand Down
14 changes: 12 additions & 2 deletions components/common/ContentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { Box, BoxProps, useTheme } from '@chakra-ui/react'

export const RESPONSIVE_PADDING = [4, null, 8]

export default function ContentBox({ children, py = RESPONSIVE_PADDING, ...props }: BoxProps) {
export default function ContentBox({
children,
py = RESPONSIVE_PADDING,
...props
}: BoxProps) {
const { breakpoints } = useTheme()

return (
<Box maxW={breakpoints.lg} m="auto" px={RESPONSIVE_PADDING} py={py} {...props}>
<Box
maxW={breakpoints.lg}
m="auto"
px={RESPONSIVE_PADDING}
py={py}
{...props}
>
{children}
</Box>
)
Expand Down
6 changes: 5 additions & 1 deletion components/common/CustomShareContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export default function CustomShareContainer({
onClick,
}: CustomShareContainerProps) {
return (
<button style={{ ...defaultStyling, ...style }} onClick={onClick} aria-label="share">
<button
style={{ ...defaultStyling, ...style }}
onClick={onClick}
aria-label="share"
>
{children}
</button>
)
Expand Down
7 changes: 6 additions & 1 deletion components/common/FloatingRibbon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Button as BaseButton, ButtonProps, Center, CenterProps } from '@chakra-ui/react'
import {
Button as BaseButton,
ButtonProps,
Center,
CenterProps,
} from '@chakra-ui/react'
import { RESPONSIVE_PADDING } from './ContentBox'

export default function FloatingRibbon({ children }: CenterProps) {
Expand Down
18 changes: 15 additions & 3 deletions components/common/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default function Footer() {
textAlign="left"
>
<Container centerContent maxW="container.sm">
<SimpleGrid columns={[2, 3]} width="100%" textAlign={['left', 'center']}>
<SimpleGrid
columns={[2, 3]}
width="100%"
textAlign={['left', 'center']}
>
<SimpleLink href="/" padding={1} marginBottom={1}>
Home
</SimpleLink>
Expand Down Expand Up @@ -47,7 +51,11 @@ export default function Footer() {
>
Analytics
</SimpleLink>
<SimpleLink href="mailto:[email protected]" padding={1} marginBottom={1}>
<SimpleLink
href="mailto:[email protected]"
padding={1}
marginBottom={1}
>
Email Us
</SimpleLink>
<SimpleLink
Expand All @@ -60,7 +68,11 @@ export default function Footer() {
</SimpleGrid>
<Text as="strong" paddingTop={4} mb={4}>
Made with love by Canadians{' '}
<span role="img" aria-label="heart" style={{ filter: 'brightness(0) invert(1)' }}>
<span
role="img"
aria-label="heart"
style={{ filter: 'brightness(0) invert(1)' }}
>
❤️
</span>
</Text>
Expand Down
Loading