-
Notifications
You must be signed in to change notification settings - Fork 1
Frontend Development
Ethan Cavill edited this page Jul 9, 2024
·
1 revision
This guide provides an overview of the technologies used in our frontend, their structure, and the development cycle. The goal is to help you understand the architecture and workflow of our frontend development.
- Next.js: A React framework for server-side rendering and generating static websites.
- React: Library for building user interfaces.
- TailwindCSS: Utility-first CSS framework for styling.
- GraphQL Code Generator: Generates TypeScript types and hooks from GraphQL queries and mutations.
- urql: GraphQL client for React.
-
GraphQL APIs
- Define GraphQL queries and mutations.
- Example Mutation:
mutation CreateStudyCategory($studyCategory: StudyCategoryInput!) { createStudyCategory(studyCategory: $studyCategory) { id title } }
- Example Update Mutation:
mutation UpdateStudyCategory($id: ID!, $studyCategory: StudyCategoryInput!) { updateStudyCategory(id: $id, studyCategory: $studyCategory) { id title isActive } }
- Use generated hooks in components:
const [createStudyCategory] = useCreateStudyCategoryMutation(); const [updateStudyCategory] = useUpdateStudyCategoryMutation();
-
Generate Types (GraphQL Codegen)
- GraphQL Code Generator takes the defined queries and mutations in your frontend and generates corresponding TypeScript types and hooks.
- It fetches the GraphQL schema from the backend using introspection, which involves sending a query to the backend to get the schema definition in JSON format.
- It scans and parses the .graphql files in your frontend to extract the operations and their corresponding fields and variables.
- Run the codegen script to generate TypeScript types:
npm run codegen
- The generated types and hooks are output in a file, typically `graphql-types.ts`.
-
State Management
- Use Jotai or other state management libraries.
- Example:
import { atom, useAtom } from 'jotai'; const userAtom = atom(null); const [user, setUser] = useAtom(userAtom);
-
Styling with TailwindCSS
- Use utility classes for styling.
- Example:
<button className="bg-indigo-600 text-white py-2 px-4 rounded"> Sign in </button>
- For more details, refer to the TailwindCSS Documentation.
-
Using Toasts and Modals
- Toasts: Use for displaying notifications.
- Example:
const { addToast } = useToast(); addToast({ type: 'success', content: 'Operation successful.' });
- Modals: Use for displaying dialog boxes.
- Example:
const { showModal, hideModal } = useModalContext(); showModal({ type: 'default', title: 'Modal Title', content: <YourComponent />, }); hideModal();
- GraphQL Testing Playground: Use the GraphQL testing playground available at http://localhost:8000/graphql
- Frontend: Access the frontend at http://localhost/
This guide provides a succinct overview of our frontend development architecture and workflow. For detailed implementation, please refer to the specific files and documentation within the repository. Happy coding!