Skip to content

Commit

Permalink
app
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Aug 14, 2024
1 parent 0c79013 commit a13f5ff
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import env from "codeforlife/env"

export * from "codeforlife/env"

// Example of how to get an environment variable.
export const EXAMPLE = env.VITE_EXAMPLE ?? "DEFAULT_VALUE"
13 changes: 13 additions & 0 deletions src/app/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file serves as a central hub for re-exporting pre-typed Redux hooks.
// These imports are restricted elsewhere to ensure consistent
// usage of typed hooks throughout the application.
// We disable the ESLint rule here because this is the designated place
// for importing and re-exporting the typed versions of hooks.
/* eslint-disable @typescript-eslint/no-restricted-imports */
import { useDispatch, useSelector } from "react-redux"

import type { AppDispatch, RootState } from "./store"

// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
3 changes: 3 additions & 0 deletions src/app/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as yup from "yup"

export const fruitNameSchema = yup.string().max(50)
26 changes: 26 additions & 0 deletions src/app/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Action, ThunkAction } from "@reduxjs/toolkit"
import { combineSlices } from "@reduxjs/toolkit"
import { makeStore } from "codeforlife/utils/store"

import api from "../api"

// `combineSlices` automatically combines the reducers using
// their `reducerPath`s, therefore we no longer need to call `combineReducers`.
const reducer = combineSlices(api)

// Infer the `RootState` type from the root reducer
export type RootState = ReturnType<typeof reducer>

// TODO: create middleware for api errors.
// https://redux-toolkit.js.org/rtk-query/usage/error-handling#handling-errors-at-a-macro-level
const store = makeStore({ reducer, middlewares: [api.middleware] })

export default store
export type AppStore = typeof store
export type AppDispatch = AppStore["dispatch"]
export type AppThunk<ThunkReturnType = void> = ThunkAction<
ThunkReturnType,
RootState,
unknown,
Action
>
15 changes: 15 additions & 0 deletions src/app/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
type ThemeOptions,
createTheme,
responsiveFontSizes,
} from "@mui/material"
import { themeOptions as cflThemeOptions } from "codeforlife/theme"

// Unpack the base options to extend the theme
export const themeOptions: ThemeOptions = {
...cflThemeOptions,
}

const theme = responsiveFontSizes(createTheme(themeOptions))

export default theme

0 comments on commit a13f5ff

Please sign in to comment.