Skip to content

Commit

Permalink
Improve project structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
octet-stream committed Feb 28, 2024
1 parent ee7b3b6 commit 35844ba
Show file tree
Hide file tree
Showing 155 changed files with 271 additions and 269 deletions.
2 changes: 1 addition & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
"ts-node/register/transpile-only",
"reflect-metadata",
"./src/server/lib/env.ts",
"./src/server/__helper__/polyfills.ts"
"./src/server/__helpers__/polyfills.ts"
],
environmentVariables: {
"TS_NODE_PROJECT": "tsconfig.ava.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {forwardRef, useMemo} from "react"
import Link from "next/link"
import cn from "clsx"

import {isInternalUrl} from "lib/util/isInternalUrl"
import {isInternalUrl} from "lib/utils/isInternalUrl"

import {ExternalAnchor} from "component/Anchor/ExternalAnchor"
import {ExternalAnchor} from "components/Anchor/ExternalAnchor"

interface Props extends ComponentPropsWithoutRef<"a"> {
href: string
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {useEvent} from "react-use-event-hook"
import {useRef, createElement} from "react"
import type {FC, ReactNode} from "react"

import type {MaybePromise} from "lib/type/MaybePromise"
import type {MaybePromise} from "lib/types/MaybePromise"

import type {ModalRef, BaseModalProps} from "component/Modal"
import {Modal, ModalPanel, ModalTitle} from "component/Modal"
import {Button} from "component/Button"
import type {ModalRef, BaseModalProps} from "components/Modal"
import {Modal, ModalPanel, ModalTitle} from "components/Modal"
import {Button} from "components/Button"

interface ConfirmButtonProps {
confirm(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Plus} from "lucide-react"

import cn from "clsx"

import {Button} from "component/Button"
import {Button} from "components/Button"

interface Props extends Omit<ComponentPropsWithoutRef<"button">, "type" | "color"> { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {FC, ReactNode} from "react"
import {useEvent} from "react-use-event-hook"
import {Dialog} from "@headlessui/react"

import type {MaybeUndefined} from "lib/type/MaybeUndefined"
import type {MaybeUndefined} from "lib/types/MaybeUndefined"

import {ModalContext} from "./ModalContext"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/component/NoteCard.tsx → src/components/NoteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import type {FC} from "react"
import cn from "clsx"
import Link from "next/link"

import {NoteStatus} from "server/trpc/type/common/NoteStatus"
import {NoteStatus} from "server/trpc/types/common/NoteStatus"

import {patchNodeStatus} from "lib/util/patchNoteStatus"
import {patchNodeStatus} from "lib/utils/patchNoteStatus"
import {client} from "lib/trpc/client"

import {Card} from "component/Card"
import {useNoteStateSnapshot, useNoteStateProxy} from "context/NoteStateContext"
import {Card} from "components/Card"
import {useNoteStateSnapshot, useNoteStateProxy} from "contexts/NoteStateContext"

interface Props { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import type {FC} from "react"

import cn from "clsx"

import {NoteStatus} from "server/trpc/type/common/NoteStatus"
import {NoteStatus} from "../server/trpc/types/common/NoteStatus"

import {patchNodeStatus} from "lib/util/patchNoteStatus"
import {client} from "lib/trpc/client"
import {patchNodeStatus} from "../lib/utils/patchNoteStatus"
import {client} from "../lib/trpc/client"

import {
useNoteStateSnapshot,
useNoteStateProxy
} from "context/NoteStateContext"
} from "../contexts/NoteStateContext"

interface Props {
className?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {FC} from "react"

import cn from "clsx"

import {useNoteStateSnapshot} from "context/NoteStateContext"
import {useNoteStateSnapshot} from "contexts/NoteStateContext"

import {PauseButton} from "./PauseButton"
import {PlayButton} from "./PlayButton"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Pause} from "lucide-react"

import {NoteStatus} from "server/trpc/type/common/NoteStatus"
import {NoteStatus} from "server/trpc/types/common/NoteStatus"

import {createControlButton} from "./createControlButton"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Play} from "lucide-react"

import {NoteStatus} from "server/trpc/type/common/NoteStatus"
import {NoteStatus} from "server/trpc/types/common/NoteStatus"

import {createControlButton} from "./createControlButton"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Square} from "lucide-react"

import {NoteStatus} from "server/trpc/type/common/NoteStatus"
import {NoteStatus} from "server/trpc/types/common/NoteStatus"

import {createControlButton} from "./createControlButton"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type {ComponentPropsWithoutRef} from "react"
import type {LucideIcon} from "lucide-react"
import {toast} from "react-hot-toast"

import {NoteStatus} from "server/trpc/type/common/NoteStatus"
import {NoteStatus} from "server/trpc/types/common/NoteStatus"

import {client} from "lib/trpc/client"
import {patchNodeStatus} from "lib/util/patchNoteStatus"
import {patchNodeStatus} from "lib/utils/patchNoteStatus"

import {useNoteStateProxy, useNoteStateSnapshot} from "context/NoteStateContext"
import {useNoteStateProxy, useNoteStateSnapshot} from "contexts/NoteStateContext"

import cn from "clsx"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type {FC} from "react"

import isString from "lodash/isString"

import {NoteCreateInput} from "server/trpc/type/input/NoteCreateInput"
import type {INoteCreateInput} from "server/trpc/type/input/NoteCreateInput"
import {NoteCreateInput} from "server/trpc/types/note/NoteCreateInput"
import type {INoteCreateInput} from "server/trpc/types/note/NoteCreateInput"

import {client} from "lib/trpc/client"

import {useNotesStateProxy} from "context/NotesStateContext"
import {useNotesStateProxy} from "contexts/NotesStateContext"

import {createNoteModal} from "../createNoteModal"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {OpenModalButton} from "component/Modal"
import type {OpenModalButton} from "components/Modal"

import {FloatingButton} from "component/FloatingButton"
import {FloatingButton} from "components/FloatingButton"

export const Open: OpenModalButton = ({open}) => (
<FloatingButton onClick={open} aria-label="Create a note" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type {FC} from "react"

import merge from "lodash/merge"

import {NoteUpdateInput} from "server/trpc/type/input/NoteUpdateInput"
import type {INoteUpdateInput} from "server/trpc/type/input/NoteUpdateInput"
import {NoteUpdateInput} from "server/trpc/types/note/NoteUpdateInput"
import type {INoteUpdateInput} from "server/trpc/types/note/NoteUpdateInput"

import {client} from "lib/trpc/client"

import {useNoteStateProxy, useNoteStateSnapshot} from "context/NoteStateContext"
import {useNoteStateProxy, useNoteStateSnapshot} from "contexts/NoteStateContext"

import {createNoteModal} from "../createNoteModal"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Pencil} from "lucide-react"

import type {OpenModalButton} from "component/Modal"
import type {OpenModalButton} from "components/Modal"

export const Open: OpenModalButton = ({open}) => (
<button type="button" aria-label="Edit the note" onClick={open}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import TextArea from "react-textarea-autosize"
import isEmpty from "lodash/isEmpty"
import omitBy from "lodash/omitBy"

import {INoteCreateInput} from "server/trpc/type/input/NoteCreateInput"
import {INoteCreateInput} from "server/trpc/types/note/NoteCreateInput"

import type {ModalRef, BaseModalProps} from "component/Modal"
import {Modal, ModalPanel, ModalTitle} from "component/Modal"
import {Button} from "component/Button"
import type {ModalRef, BaseModalProps} from "components/Modal"
import {Modal, ModalPanel, ModalTitle} from "components/Modal"
import {Button} from "components/Button"

type BlockReturnHandler = KeyboardEventHandler<HTMLTextAreaElement>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable react/prop-types */

import type {CancelButton} from "component/ConfirmationDialog"
import type {CancelButton} from "components/ConfirmationDialog"

import {Button} from "component/Button"
import {Button} from "components/Button"

export const Cancel: CancelButton = ({close}) => (
<Button onClick={close} variant="primary" aria-label="Cancel">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable react/prop-types */

import type {ConfirmButton} from "component/ConfirmationDialog"
import type {ConfirmButton} from "components/ConfirmationDialog"

import {Button} from "component/Button"
import {Button} from "components/Button"

export const Confirm: ConfirmButton = ({confirm}) => (
<Button onClick={confirm} variant="secondary" color="red" aria-label="Confirm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type {FC} from "react"

import {client} from "lib/trpc/client"

import {useNoteStateSnapshot} from "context/NoteStateContext"
import {useNoteStateSnapshot} from "contexts/NoteStateContext"

import {ConfirmationDialog} from "component/ConfirmationDialog"
import {ConfirmationDialog} from "components/ConfirmationDialog"

import {Open} from "./Open"
import {Cancel} from "./Cancel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {Trash} from "lucide-react"

import type {OpenModalButton} from "component/Modal"
import type {OpenModalButton} from "components/Modal"

export const Open: OpenModalButton = ({open}) => (
<button type="button" onClick={open} aria-label="Remove the note">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {FC, ReactNode} from "react"
import {useRef} from "react"

import type {ONotesPageOutput} from "server/trpc/type/output/NotesPageOutput"
import type {ONotesPageOutput} from "../server/trpc/types/note/NotesPageOutput"

import {NotesStateContextProvider} from "./NotesStateContext"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ONoteOutput} from "server/trpc/type/output/NoteOutput"
import type {ONoteOutput} from "../server/trpc/types/note/NoteOutput"

import {createStateContext} from "lib/context/createStateContext"
import {createStateContext} from "../lib/contexts/createStateContext"

export const {
StateContext: NoteStateContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ONotesPageOutput} from "server/trpc/type/output/NotesPageOutput"
import type {ONotesPageOutput} from "../server/trpc/types/note/NotesPageOutput"

import {createStateContext} from "lib/context/createStateContext"
import {createStateContext} from "../lib/contexts/createStateContext"

export const {
StateContext: NotesStateContext,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useMemo, useContext, createContext} from "react"
import type {FC, ReactNode, Context} from "react"
import {proxy, useSnapshot} from "valtio"

import {MaybeUndefined} from "lib/type/MaybeUndefined"
import {MaybeUndefined} from "../types/MaybeUndefined"

type UseSnapshotOptions = Parameters<typeof useSnapshot>[1]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import {useRouter} from "next/router"
import {useMemo} from "react"

import isEmpty from "lodash/isEmpty"

export function useSearchParams(): URLSearchParams | null {
const router = useRouter()

return useMemo<URLSearchParams | null>(() => {
const {searchParams} = new URL(router.asPath, "https://localhost")

if (isEmpty([...searchParams])) {
if (!searchParams.size) {
return null
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/trpc/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {httpBatchLink, createTRPCProxyClient} from "@trpc/client"

import Superjson from "superjson"

import {serverAddress} from "lib/util/serverAddress"
import {serverAddress} from "../utils/serverAddress"

import type {Router} from "server/trpc/router"
import type {Router} from "../../server/trpc/router"

export const client = createTRPCProxyClient<Router>({
transformer: Superjson,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/trpc/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Caller} from "server/trpc/router"
import {router} from "server/trpc/router"
import {createCaller as routerCreateCaller} from "../../server/trpc/router"
import type {Caller} from "../../server/trpc/router"

interface CallerImplementation<TResult, TArgs extends readonly unknown[]> {
(trpc: Caller, ...args: TArgs): TResult
Expand All @@ -19,7 +19,7 @@ interface DecoratedCaller<TResult, TArgs extends readonly unknown[]> {
export function createCaller<TResult, TArgs extends readonly unknown[]>(
caller: CallerImplementation<TResult, TArgs>
): DecoratedCaller<TResult, TArgs> {
const trpc = router.createCaller({})
const trpc = routerCreateCaller({})

return function decoratedCaller(...args: TArgs): TResult {
return caller(trpc, ...args)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
differenceInHours
} from "date-fns"

import type {RawDate} from "lib/type/RawDate"
import type {RawDate} from "lib/types/RawDate"

import {formatTime, TIME_FORMAT} from "./formatTime"

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {stringify} from "superjson"
import type {
PageDataProps,
SerializedPageDataProps
} from "lib/type/PageDataProps"
} from "lib/types/PageDataProps"

export interface GetPageDataStaticProps {
<
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import merge from "lodash/merge"
import pick from "lodash/pick"

import type {PickKeys} from "lib/type/PickKeys"
import type {PickKeys} from "lib/types/PickKeys"

import type {ONoteBaseOutput} from "server/trpc/type/output/NoteBaseOutput"
import type {ONoteBaseOutput} from "server/trpc/types/note/NoteBaseOutput"

type Statuses = PickKeys<ONoteBaseOutput, "status" | "isCompleted" | "isInProgress" | "isRejected" | "isPaused">

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {FC} from "react"

import Link from "next/link"

import {BaseLayout} from "layout/BaseLayout"
import {BaseLayout} from "../layouts/BaseLayout"

const NotFound: FC = () => (
<BaseLayout>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type {FC} from "react"
import Head from "next/head"
import isString from "lodash/isString"

import "style/tailwind.css"
import "style/global.css"
import "styles/tailwind.css"
import "styles/global.css"

import type {SerializedPageDataProps} from "lib/type/PageDataProps"
import type {SerializedPageDataProps} from "../lib/types/PageDataProps"

interface PageProps extends SerializedPageDataProps { }

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createNextApiHandler} from "@trpc/server/adapters/next"

import {createContext} from "server/trpc/context"
import {router} from "server/trpc/router"
import {createContext} from "../../../server/trpc/context"
import {router} from "../../../server/trpc/router"

export default createNextApiHandler({router, createContext})
Loading

0 comments on commit 35844ba

Please sign in to comment.