Skip to content

Commit

Permalink
Use constants wherever navigate is called
Browse files Browse the repository at this point in the history
  • Loading branch information
0xi4o committed Aug 14, 2024
1 parent 14ceb16 commit cb9ef55
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
7 changes: 7 additions & 0 deletions app/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ export const ARLS_OPTIONS: SqliteQueryOptions = {
logExplainQueryPlan: true,
logQueryExecutionTime: true,
}

export const ROUTES = {
EDITOR: {
BASE: '/editor',
NEW_POST: '/editor/posts',
},
}
3 changes: 2 additions & 1 deletion app/lib/providers/aurelius.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Timer, useTimer } from 'react-use-precision-timer'
import { useNavigate } from '@remix-run/react'

import { useQuery } from '@evolu/react'
import { ROUTES } from '~/lib/constants'
import { useKeyboardShortcuts } from '~/lib/hooks'
import { EditorShortcuts } from '~/lib/types'
import { SettingsRow, settingsQuery } from '~/services/evolu/client'
Expand Down Expand Up @@ -69,7 +70,7 @@ const AureliusProvider = ({ children }: AureliusProviderProps) => {

const createNewPost = () => {
handleSplashOpen(false)
navigate('/editor/posts')
navigate(ROUTES.EDITOR.NEW_POST)
}

const handlePreferencesOpen = (open: boolean) => {
Expand Down
22 changes: 4 additions & 18 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useState } from 'react'

import { useFetcher, useLoaderData, useNavigate } from '@remix-run/react'
import { useLoaderData, useNavigate } from '@remix-run/react'

import * as S from '@effect/schema/Schema'
import invariant from 'tiny-invariant'
import Editor from '~/components/common/editor'
import { ROUTES } from '~/lib/constants'
import { arls } from '~/services/arls'
import { NonEmptyString100 } from '~/services/evolu/schema'

Expand All @@ -19,7 +20,6 @@ export const clientLoader = async () => {
}

const Index = () => {
const fetcher = useFetcher()
const { writing } = useLoaderData<typeof clientLoader>()
const navigate = useNavigate()

Expand All @@ -39,23 +39,9 @@ const Index = () => {
}, [])

const onReset = () => {
navigate(`/editor/posts`)
navigate(ROUTES.EDITOR.NEW_POST)
}

useEffect(() => {
if (
fetcher.state === 'idle' &&
fetcher.data &&
// @ts-expect-error: BS error. It's there. Check how to type fetcher.data.
fetcher.data.message === 'ok' &&
// @ts-expect-error: BS error. It's there. Check how to type fetcher.data.
fetcher.data.redirectTo.trim() !== ''
) {
// @ts-expect-error: BS error. It's there. Check how to type fetcher.data.
navigate(fetcher.data.redirectTo)
}
}, [fetcher])

return (
<Editor
data={{
Expand Down
29 changes: 29 additions & 0 deletions app/routes/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ const About = () => {
</li>
</ul>
</div>
{/*<div className='flex w-full flex-col items-start gap-4 leading-loose text-white'>*/}
{/* <span>*/}
{/* And a special thanks to the following people for*/}
{/* helping me test Aurelius and providing valuable*/}
{/* feedback:*/}
{/* </span>*/}
{/* <ul>*/}
{/* <li>*/}
{/* <a*/}
{/* href='https://www.instagram.com/reflex__god_/'*/}
{/* target='_blank'*/}
{/* rel='noreferrer'*/}
{/* className='text-primary underline'*/}
{/* >*/}
{/* Sreenivasan*/}
{/* </a>{' '}*/}
{/* </li>*/}
{/* <li>*/}
{/* <a*/}
{/* href='https://www.instagram.com/raj.rk98/'*/}
{/* target='_blank'*/}
{/* rel='noreferrer'*/}
{/* className='text-primary underline'*/}
{/* >*/}
{/* Rajkumar*/}
{/* </a>{' '}*/}
{/* </li>*/}
{/* </ul>*/}
{/*</div>*/}
</div>
</div>
</DefaultLayout>
Expand Down
3 changes: 2 additions & 1 deletion app/routes/editor.$effort.$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as S from '@effect/schema/Schema'
import { ExtractRow, Query, String1000 } from '@evolu/common'
import invariant from 'tiny-invariant'
import Editor from '~/components/common/editor'
import { ROUTES } from '~/lib/constants'
import { EditorData } from '~/lib/types'
import { Arls, TableQueryBuilder, arls } from '~/services/arls'
import { EffortsTable } from '~/services/evolu/database'
Expand Down Expand Up @@ -111,7 +112,7 @@ const Writing = () => {
)

const onReset = () => {
navigate(`/editor/${effort.slug as string}`)
navigate(`${ROUTES.EDITOR.BASE}/${effort.slug as string}`)
}

return (
Expand Down
3 changes: 2 additions & 1 deletion app/routes/editor.$effort_.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { String1000 } from '@evolu/common'
import GithubSlugger from 'github-slugger'
import invariant from 'tiny-invariant'
import Editor from '~/components/common/editor'
import { ROUTES } from '~/lib/constants'
import { EditorData } from '~/lib/types'
import { checkSlugUniqueness } from '~/lib/utils'
import { Arls, arls } from '~/services/arls'
Expand Down Expand Up @@ -93,7 +94,7 @@ const NewWriting = () => {
)

const onReset = () => {
navigate(`/editor/${effort.slug as string}`)
navigate(`${ROUTES.EDITOR.BASE}/${effort.slug as string}`)
}

useEffect(() => {
Expand Down

0 comments on commit cb9ef55

Please sign in to comment.