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

[WIP] The Big Apollo Refactor #890

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4e7a72e
Upgrade Node
robin-macpherson May 30, 2024
fa95303
Add all languages to UILanguage enum + migration
robin-macpherson May 30, 2024
662cf66
Use all languages in langCodeToUiLanguage
robin-macpherson May 30, 2024
0b9d0b8
Create journalyMiddleware.ts
robin-macpherson May 30, 2024
4f0eaab
Wrap app root in ApolloProvider
robin-macpherson May 30, 2024
2e5043c
First page refactor removing withApollo
robin-macpherson May 30, 2024
1f969d7
Write `getUiLanguage` fn + refactor page using it
robin-macpherson May 30, 2024
a6561fd
Factor `getUiLanguage` out
robin-macpherson May 30, 2024
739c275
Refactor About page
robin-macpherson May 30, 2024
b65fcd5
Refactor Home page
robin-macpherson May 30, 2024
f2964ec
Refactor Login page
robin-macpherson May 30, 2024
3f07717
Refactor NUM_POSTS_PER_MY_POSTS_PAGE into constant
robin-macpherson Jun 6, 2024
3c2dc48
Move getUiLanguage.ts to utils
robin-macpherson Jun 6, 2024
84b3a3a
Clean up refactored getUiLanguage code
robin-macpherson Jun 6, 2024
a3e9590
Write `getCurrentUserId` util
robin-macpherson Jun 6, 2024
720afc9
Add a note to improve our tokens
robin-macpherson Jun 6, 2024
bda8a22
Simple page conversions
robin-macpherson Jun 6, 2024
7a0b8d6
Refactor post-related pages
robin-macpherson Jun 6, 2024
9791305
A bit of cleanup
robin-macpherson Jun 27, 2024
a9f2a08
Handle most of the remaining pages
robin-macpherson Jun 27, 2024
49c642b
Clean up the old apollo.tsx file
robin-macpherson Jun 27, 2024
73e637e
Fix up the final pages!
robin-macpherson Jun 27, 2024
7a22557
Got stuck in the muck... no fun my feed page
robin-macpherson Jul 11, 2024
ddf7eaf
Fixed issue with my feed SSR but why remains a bit of a mystery
Lanny Jul 15, 2024
6a81abd
Update translation files for simpler Profile str
robin-macpherson Jul 18, 2024
9e1397d
Update all GQL query objects to have Ids
robin-macpherson Jul 18, 2024
bcd8505
A bunch of cleanup
robin-macpherson Jul 18, 2024
fbcc666
Make the account settings page work!
robin-macpherson Jul 18, 2024
3d39b23
Some last fixes and cleanup
robin-macpherson Jul 18, 2024
1bb4bfc
Fix all the type issues!
robin-macpherson Jul 23, 2024
11ce6f1
Upgrade Next from 13.3.4 to 14.2.5
robin-macpherson Jul 23, 2024
58c09e9
Update j-db-client version due to merged code
robin-macpherson Sep 10, 2024
319c5f3
Merge branch 'master' into the-big-apollo-refactor
robin-macpherson Sep 10, 2024
19155ab
Merge remote-tracking branch 'origin' into the-big-apollo-refactor
robin-macpherson Sep 19, 2024
232fb63
Bump j-db-client version for J-Mail
robin-macpherson Sep 19, 2024
bd3399a
Upgrade `next-18next` and try to make it work
robin-macpherson Sep 19, 2024
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/gallium
lts/iron
1 change: 1 addition & 0 deletions docs/0-creating-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

When creating a new page, make sure to require a namespace for translations. This ensures that only the translations that are needed are sent along with that page.

// TODO: update to remove withApollo
```jsx
const MyPage: NextPage = () => {
/* ... */
Expand Down
4 changes: 2 additions & 2 deletions docs/1-internationalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ When using translations in a React component, default to using the [useTranslati

```jsx
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

export function MyComponent() {
const { t } = useTranslation()
Expand All @@ -32,7 +32,7 @@ For simple interpolation, follow this pattern:

```jsx
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

export function MyComponent() {
const { t } = useTranslation()
Expand Down
2 changes: 1 addition & 1 deletion packages/j-db-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@journaly/j-db-client",
"version": "13.22.0",
"version": "13.23.0",
"description": "Journaly's internal database client.",
"main": "dist/index",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.


ALTER TYPE "UILanguage" ADD VALUE 'CHINESE_SIMPLIFIED';
ALTER TYPE "UILanguage" ADD VALUE 'CHINESE_TRADITIONAL';
ALTER TYPE "UILanguage" ADD VALUE 'ITALIAN';
ALTER TYPE "UILanguage" ADD VALUE 'PORTUGUESE_BRAZILIAN';
4 changes: 4 additions & 0 deletions packages/j-db-client/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ enum UILanguage {
ENGLISH
GERMAN
SPANISH
CHINESE_SIMPLIFIED
CHINESE_TRADITIONAL
ITALIAN
PORTUGUESE_BRAZILIAN
}

enum BadgeType {
Expand Down
14 changes: 7 additions & 7 deletions packages/j-mail/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/j-mail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"typescript": "4.2.4"
},
"dependencies": {
"@journaly/j-db-client": "^13.22.0",
"@journaly/j-db-client": "^13.23.0",
"@types/nodemailer": "^6.4.0",
"aws-sdk": "^2.737.0",
"date-fns": "^2.16.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { UserBadgeFragmentFragment as Badge, BadgeType } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import theme from '@/theme'

type Props = {
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/Dashboard/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LanguageSelect from './LanguageSelect'
import TopicSelect from './TopicSelect'
import useToggle from '@/hooks/useToggle'
import useUILanguage from '@/hooks/useUILanguage'
import { Router, useTranslation } from '@/config/i18n'
import { Router, useTranslation } from 'next-i18next'
import PremiumFeatureModal from '@/components/Modals/PremiumFeatureModal'

export type PostQueryVarsType = {
Expand Down Expand Up @@ -143,7 +143,7 @@ const Filters: React.FC<Props> = ({
}))
resetPagination()
}, [resetPagination])

const toggleMyLanguagesFilter = useCallback(() => {
setPostQueryVars((prevState) => ({
...prevState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import MultiSelect from '@/components/MultiSelect'
import { LanguagesQuery } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type Props = {
languagesData: LanguagesQuery | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Filters/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState } from 'react'
import _ from 'lodash'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type Props = {
defaultValue: string
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Filters/TopicSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import MultiSelect from '@/components/MultiSelect'
import { Topic } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type Props = {
topics: Topic[] | undefined
Expand Down
38 changes: 21 additions & 17 deletions packages/web/components/Dashboard/MyFeed/MyFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from 'next/router'
import { toast } from 'react-toastify'
import _ from 'lodash'

import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { gtag } from '@/components/GoogleAnalytics'
import Pagination from '@/components/Pagination'
import LoadingWrapper from '@/components/LoadingWrapper'
Expand All @@ -17,24 +17,33 @@ import {

import PostCard from '../PostCard'
import FeedHeader from './FeedHeader'
import Filters from '../Filters'
import { PostQueryVarsType } from '../Filters'
import Filters, { PostQueryVarsType } from '@/components/Dashboard/Filters'
import { makeReference, useApolloClient } from '@apollo/client'

const NUM_POSTS_PER_PAGE = 9

type Props = {
currentUser: UserType
initialSearchFilters: InitialSearchFilters | null
initialSearchFilters: PostQueryVarsType | null
}

export type InitialSearchFilters = {
languages: number[]
topics: number[]
needsFeedback: boolean
hasInteracted: boolean
savedPosts: boolean
search: string
export const constructPostQueryVars = (
postQueryVars: PostQueryVarsType | null,
currentPage: number,
) => {
const variables = {
first: NUM_POSTS_PER_PAGE,
skip: (currentPage - 1) * NUM_POSTS_PER_PAGE,
status: PostStatus.Published,
languages: postQueryVars?.languages || [],
topics: postQueryVars?.topics || [],
followedAuthors: postQueryVars?.followedAuthors || false,
needsFeedback: postQueryVars?.needsFeedback || false,
hasInteracted: postQueryVars?.hasInteracted || false,
search: postQueryVars?.search || '',
savedPosts: postQueryVars?.savedPosts || false,
}
return variables
}

const MyFeed: React.FC<Props> = ({ currentUser, initialSearchFilters }) => {
Expand Down Expand Up @@ -79,12 +88,7 @@ const MyFeed: React.FC<Props> = ({ currentUser, initialSearchFilters }) => {

// fetch posts for the feed!
const { loading, error, data } = usePostsQuery({
variables: {
first: NUM_POSTS_PER_PAGE,
skip: (currentPage - 1) * NUM_POSTS_PER_PAGE,
status: PostStatus.Published,
...postQueryVars,
},
variables: constructPostQueryVars(postQueryVars, currentPage),
})

const posts = data?.posts?.posts
Expand Down
1 change: 0 additions & 1 deletion packages/web/components/Dashboard/MyFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default } from './MyFeed'
export type { InitialSearchFilters } from './MyFeed'
13 changes: 6 additions & 7 deletions packages/web/components/Dashboard/MyPosts/MyPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import {
User as UserType,
usePostsQuery,
} from '@/generated/graphql'
import { useTranslation, Trans } from '@/config/i18n'
import { useTranslation, Trans } from 'next-i18next'
import TranslationLink from '@/components/TranslationLink'
import LoadingSpinner from '@/components/Icons/LoadingSpinner'
import PostCard from '../PostCard'
import theme from '@/theme'
import Filters, { PostQueryVarsType } from '@/components/Dashboard/Filters'
import Pagination from '@/components/Pagination'

const NUM_POSTS_PER_PAGE = 10
import { NUM_POSTS_PER_MY_POSTS_PAGE } from '@/constants'

type Props = {
currentUser: UserType
Expand All @@ -40,8 +39,8 @@ const MyPosts: React.FC<Props> = ({ currentUser, status }) => {
})
const { loading, data, error } = usePostsQuery({
variables: {
first: NUM_POSTS_PER_PAGE,
skip: (currentPage - 1) * NUM_POSTS_PER_PAGE,
first: NUM_POSTS_PER_MY_POSTS_PAGE,
skip: (currentPage - 1) * NUM_POSTS_PER_MY_POSTS_PAGE,
status,
authorId: currentUser.id,
...postQueryVars,
Expand All @@ -51,7 +50,7 @@ const MyPosts: React.FC<Props> = ({ currentUser, status }) => {
const posts = (data?.posts?.posts as PostType[]) || []
const count = data?.posts?.count || 0
const showPosts = !loading && posts.length > 0
const showPagination = count > NUM_POSTS_PER_PAGE
const showPagination = count > NUM_POSTS_PER_MY_POSTS_PAGE
const showEmptyState = !loading && posts.length === 0
const pageTitle = t('pageTitle')

Expand Down Expand Up @@ -92,7 +91,7 @@ const MyPosts: React.FC<Props> = ({ currentUser, status }) => {
<Pagination
currentPage={currentPage}
total={count}
numPerPage={NUM_POSTS_PER_PAGE}
numPerPage={NUM_POSTS_PER_MY_POSTS_PAGE}
title={pageTitle}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useState, useEffect, useRef } from 'react'
import Link from 'next/link'
import classNames from 'classnames'

import { Router, useTranslation } from '@/config/i18n'
import { Router, useTranslation } from 'next-i18next'
import { navConstants } from './nav-constants'
import theme from '@/theme'
import {
Expand Down
4 changes: 1 addition & 3 deletions packages/web/components/Dashboard/Post/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Button, { ButtonVariant } from '@/components/Button'
import theme from '@/theme'
import PostBodyStyles from '@/components/PostBodyStyles'
import InlineFeedbackPopover, { PendingThreadData } from '@/components/InlineFeedbackPopover'
import { Router, useTranslation } from '@/config/i18n'
import { Router, useTranslation } from 'next-i18next'
import PostHeader from '@/components/PostHeader'
import ConfirmationModal from '@/components/Modals/ConfirmationModal'
import PremiumFeatureModal from '@/components/Modals/PremiumFeatureModal'
Expand Down Expand Up @@ -543,9 +543,7 @@ const Post = ({ post, currentUser, refetch }: PostProps) => {
},
},
update(cache, { data }) {
console.log('before')
if (data?.updatePost) {
console.log('after')
cache.modify({
id: cache.identify(makeReference('ROOT_QUERY')),
fields: {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/PostAuthorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useUnfollowUserMutation,
useFollowingUsersQuery,
} from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { languageNameWithDialect } from '@/utils/languages'
import Button, { ButtonVariant } from '@/components/Button'
import LevelGauge from '@/components/LevelGauge'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/PostComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useDeletePostCommentMutation,
PostCommentFragmentFragment as PostCommentType,
} from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

import EditableMarkdown from '@/components/EditableMarkdown'
import Button, { ButtonSize, ButtonVariant } from '@/components/Button'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/PostComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PostPageQueryVariables,
LanguageLevel,
} from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

import theme from '@/theme'
import PostComment from './PostComment'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostClapFragmentFragment as PostClapType } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { isChildOf } from '@/utils'

// Elements whose boundaries a comment can cross
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/PostCard/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import Link from 'next/link'
import classNames from 'classnames'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { formatShortDate } from '@/utils/date'
import {
PostStatus as PostStatusType,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/PostList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useTranslation, Trans } from '@/config/i18n'
import { useTranslation, Trans } from 'next-i18next'
import {
PostCardFragmentFragment as PostType,
UserWithLanguagesFragmentFragment as UserType,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'

import theme from '@/theme'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
ProfileUserFragmentFragment as UserType,
PostCardFragmentFragment as PostCardType,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState } from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FacebookIcon from '@/components/Icons/FacebookIcon'
import InstagramIcon from '@/components/Icons/InstagramIcon'
import YoutubeIcon from '@/components/Icons/YoutubeIcon'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/ProfileStats.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useMemo, useCallback } from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import chroma from 'chroma-js'

import differenceInCalendarWeeks from 'date-fns/differenceInCalendarWeeks'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/BioForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'react-toastify'
import { sanitize } from '@/utils'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FormError from '@/components/FormError'
import SettingsForm from '@/components/Dashboard/Settings/SettingsForm'
import SettingsFieldset from '@/components/Dashboard/Settings/SettingsFieldset'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { useRouter } from 'next/router'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import theme from '@/theme'

const Breadcrumbs: React.FC = () => {
Expand Down
Loading
Loading