Skip to content

Commit

Permalink
Merge pull request #643 from brianlovin/refactor-project-structure
Browse files Browse the repository at this point in the history
Refactor project structure
  • Loading branch information
brianlovin committed May 8, 2020
2 parents 7b8a215 + 4b8357b commit 6c1d8c4
Show file tree
Hide file tree
Showing 32 changed files with 103 additions and 143 deletions.
1 change: 0 additions & 1 deletion src/components/Bookmarks/AddBookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function AddBookmark() {
},
onError({ message }) {
const clean = message.replace('GraphQL error:', '')
console.warn(clean)
setError(clean)
setUrl('')
},
Expand Down
1 change: 0 additions & 1 deletion src/components/Bookmarks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function BookmarkListItem(props: ListItemProps) {
},
onError({ message }) {
const clean = message.replace('GraphQL error:', '')
console.warn(clean)
setError(clean)
},
})
Expand Down
10 changes: 8 additions & 2 deletions src/components/DesignDetailMedia/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React, { useState } from 'react'
import VisibilitySensor from 'react-visibility-sensor'
import { DesignDetail } from '~/types'
import Markdown from '~/components/MarkdownRenderer'
import { DetailContainer, DetailTitle, MediaContainer, Video } from './style'

type Props = {
export interface DesignDetail {
title: string
description: string
media: Array<string>
orientation?: 'landscape'
}

interface Props {
detail: DesignDetail
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/DesignDetailView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from 'react'
import Link from 'next/link'
import { getDateObject } from '~/lib/getDateObject'
import {
H3,
Subheading,
LargeSubheading,
A,
Rarr,
} from '~/components/Typography'
import { DesignDetailsPost } from '~/types'
import DesignDetailsGrid from '~/components/DesignDetailsGrid'
import DesignDetailMedia from '~/components/DesignDetailMedia'
import Markdown from '~/components/MarkdownRenderer'
import Picture from '../Picture'
import Grid from '../Grid'
import { format } from 'timeago.js'
import { DesignDetailsPost } from '~/pages/design-details/[slug]'

interface Props {
post: DesignDetailsPost
Expand All @@ -22,9 +22,9 @@ interface Props {
export default function DesignDetailView(props: Props) {
const { post } = props

const { month, year, day } = getDateObject(post.createdAt)
const datestring = `${month} ${day}, ${year}`
const subheading = `${datestring} · ${post.details.length} details`
const subheading = `Posted ${format(post.createdAt)} · ${
post.details.length
} details`

return (
<Grid
Expand Down
4 changes: 2 additions & 2 deletions src/components/DesignDetailsCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react'
import ReactVisibilitySensor from 'react-visibility-sensor'
import Link from 'next/link'
import { DesignDetailsPost } from '~/types'
import {
Title,
Container,
Expand All @@ -13,8 +12,9 @@ import {
Circle,
} from './style'
import Picture from '~/components/Picture'
import { DesignDetailsPost } from '~/pages/design-details/[slug]'

type Props = {
interface Props {
post: DesignDetailsPost
}

Expand Down
26 changes: 24 additions & 2 deletions src/components/SubscriptionButtons/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import * as React from 'react'
import { ConfigPodcast } from '~/types'
import { SubscriptionsContainer, SubscriptionAvatar } from './style'

type Props = {
interface ConfigPodcast {
id: number
name: string
slug: string
description: string
simplecastId: number
artworkUrl: string
iTunesUrl: string
overcastUrl: string
pocketCastsUrl: string
rssFeedUrl: string
googlePodcastsUrl: string
castroUrl: string
breakerUrl: string
spotifyUrl: string
applePodcastId: string
twitterUsername: string
colors: {
text: string
button: string
}
}

interface Props {
podcast: ConfigPodcast
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/withApollo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { ApolloProvider } from '@apollo/client'
import { initApolloClient } from '~/graphql/api'
import { initApolloClient } from '~/graphql/services/apollo'

/*
This wrapper helps to provide Apollo functionality during SSR, while rehydrating
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 4 additions & 29 deletions src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
import { getBookmarks } from '~/graphql/resolvers/bookmarks'
import { getPosts, getPost } from '~/graphql/resolvers/overthought'
import { getEpisodes } from '~/graphql/resolvers/podcast'
import { getRepos } from '~/graphql/resolvers/repos'
import { isMe } from '~/graphql/resolvers/isMe'
import { login, logout } from '~/graphql/resolvers/mutations/auth'
import {
addBookmark,
editBookmark,
deleteBookmark,
addBookmarkReaction,
} from '~/graphql/resolvers/mutations/bookmarks'
import { requiresMe } from '~/graphql/authorization'
import Query from '~/graphql/resolvers/queries'
import Mutation from '~/graphql/resolvers/mutations'

export default {
Query: {
bookmarks: getBookmarks,
episodes: getEpisodes,
posts: getPosts,
post: getPost,
repos: getRepos,
isMe: isMe,
},
Mutation: {
login: login,
logout: logout,
addBookmark: requiresMe(addBookmark),
editBookmark: requiresMe(editBookmark),
deleteBookmark: requiresMe(deleteBookmark),
addBookmarkReaction: addBookmarkReaction,
},
Query,
Mutation,
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { URL } from 'url'
import { UserInputError } from 'apollo-server-micro'
import firebase from '~/graphql/api/firebase'
import firebase from '~/graphql/services/firebase'
import getBookmarkMetaData from './getBookmarkMetaData'

function isValidUrl(string) {
Expand Down
17 changes: 17 additions & 0 deletions src/graphql/resolvers/mutations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { login, logout } from '~/graphql/resolvers/mutations/auth'
import {
addBookmark,
editBookmark,
deleteBookmark,
addBookmarkReaction,
} from '~/graphql/resolvers/mutations/bookmarks'
import { requiresMe } from '~/graphql/helpers/requiresMe'

export default {
login: login,
logout: logout,
addBookmark: requiresMe(addBookmark),
editBookmark: requiresMe(editBookmark),
deleteBookmark: requiresMe(deleteBookmark),
addBookmarkReaction: addBookmarkReaction,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import firebase from '~/graphql/api/firebase'
import firebase from '~/graphql/services/firebase'

export async function getBookmarks() {
const data = []
Expand Down
14 changes: 14 additions & 0 deletions src/graphql/resolvers/queries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getBookmarks } from '~/graphql/resolvers/queries/bookmarks'
import { getPosts, getPost } from '~/graphql/resolvers/queries/overthought'
import { getEpisodes } from '~/graphql/resolvers/queries/podcast'
import { getRepos } from '~/graphql/resolvers/queries/repos'
import { isMe } from '~/graphql/resolvers/queries/isMe'

export default {
bookmarks: getBookmarks,
episodes: getEpisodes,
posts: getPosts,
post: getPost,
repos: getRepos,
isMe: isMe,
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ghost } from '~/graphql/api/ghost'
import { ghost } from '~/graphql/services/ghost'

export async function getPosts(_, { first = 'all' }) {
return await ghost.posts
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 0 additions & 51 deletions src/lib/getDateObject.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/api/bookmarks/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import twilio from 'twilio'
const MessagingResponse = twilio.twiml.MessagingResponse
import { URL } from 'url'

import db from '~/graphql/api/firebase'
import db from '~/graphql/services/firebase'

const stringIsAValidUrl = (s) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApolloServer } from 'apollo-server-micro'
import typeDefs from '~/graphql/typeDefs'
import resolvers from '~/graphql/resolvers'
import context from '~/graphql/context'
import withCookies from '~/graphql/api/withCookies'
import withCookies from '~/graphql/helpers/withCookies'

const apolloServer = new ApolloServer({
typeDefs,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/bookmarks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import BookmarksList from '~/components/Bookmarks'
import { GET_BOOKMARKS } from '~/graphql/queries'
import { useAuth } from '~/hooks/useAuth'
import AddBookmark from '~/components/Bookmarks/AddBookmark'
import { initApolloClient } from '~/graphql/api'
import { initApolloClient } from '~/graphql/services/apollo'
import { withApollo } from '~/components/withApollo'
import Grid from '~/components/Grid'

Expand Down Expand Up @@ -51,6 +51,8 @@ export async function getStaticProps() {
*/
const apolloStaticCache = client.cache.extract()
return {
// because this data is slightly more dynamic, update it every hour
unstable_revalidate: 60 * 60,
props: {
apolloStaticCache,
},
Expand Down
13 changes: 11 additions & 2 deletions src/pages/design-details/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import { NextSeo } from 'next-seo'
import Page, { SectionHeading } from '~/components/Page'
import { H1, Subheading } from '~/components/Typography'
import designDetailsPosts from '~/data/appDissections'
import { DesignDetailsPost } from '~/types'
import DesignDetailView from '~/components/DesignDetailView'
import DesignDetailsGrid from '~/components/DesignDetailsGrid'
import { DesignDetail as PostType } from '~/components/DesignDetailMedia'

type Props = {
export interface DesignDetailsPost {
slug: string
title: string
description: string
createdAt: string
details: Array<PostType>
tint: string
}

interface Props {
post: DesignDetailsPost
}

Expand Down
4 changes: 3 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PodcastEpisodesList from '~/components/PodcastEpisodesList'
import FigmaPlugins from '~/components/FigmaPlugins'
import { GET_HOME } from '~/graphql/queries'
import { Post, Episode, Repo } from '~/graphql/types.generated'
import { initApolloClient } from '~/graphql/api'
import { initApolloClient } from '~/graphql/services/apollo'
import Grid from '~/components/Grid'

interface Props {
Expand Down Expand Up @@ -278,6 +278,8 @@ export async function getStaticProps() {
const client = await initApolloClient({})
const { data } = await client.query({ query: GET_HOME })
return {
// because this data is slightly more dynamic, update it every hour
unstable_revalidate: 60 * 60,
props: {
data,
apolloStaticCache: client.cache.extract(),
Expand Down
4 changes: 3 additions & 1 deletion src/pages/overthought/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GET_POST, GET_POSTS } from '~/graphql/queries'
import Page from '~/components/Page'
import PostContainer from '~/components/Overthought/Post'
import NotFound from '~/components/Overthought/NotFound'
import { initApolloClient } from '~/graphql/api'
import { initApolloClient } from '~/graphql/services/apollo'

interface Props {
slug: string
Expand Down Expand Up @@ -48,6 +48,8 @@ export async function getStaticProps({ params: { slug } }) {
})

return {
// because this data is slightly more dynamic, update it every hour
unstable_revalidate: 60 * 60,
props: {
slug,
data: {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/overthought/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import OverthoughtSubscribeBox from '~/components/Overthought/Subscribe'
import SEO from '~/components/Overthought/SEO'
import OverthoughtList from '~/components/Overthought/List'
import { GET_POSTS } from '~/graphql/queries'
import { initApolloClient } from '~/graphql/api'
import { initApolloClient } from '~/graphql/services/apollo'
import Grid from '~/components/Grid'

interface Props {
Expand Down Expand Up @@ -45,6 +45,8 @@ export async function getStaticProps() {
const client = await initApolloClient({})
const { data } = await client.query({ query: GET_POSTS })
return {
// because this data is slightly more dynamic, update it every hour
unstable_revalidate: 60 * 60,
props: {
data,
},
Expand Down
Loading

1 comment on commit 6c1d8c4

@vercel
Copy link

@vercel vercel bot commented on 6c1d8c4 May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.