Git Product home page Git Product logo

notion's Introduction

Notion with Next.js 13

Setup

Repo and Prerequisites

Creating the repo

gh repo create                    # To create the repo
yarn dlx create-next-app@latest . # Inside the repo

Using node-modules with Yarn

Create a .yarnrc.yml file with the following contents:

nodeLinker: node-modules

Packages

Husky and lint-staged

Set up pre-commit action using Husky and lint-staged by running the following commands:

yarn dlx husky-init --yarn2 && yarn
yarn add -D lint-staged
// package.json
"scripts": {
  // ...
  "pre-commit": "lint-staged"
},
"lint-staged": {
  "**/*.{js,ts,jsx,tsx,css,html}": [
    "prettier --single-quote --write",
    "eslint --fix"
  ]
}
# .husky/pre-commit
yarn run pre-commit

shadcn/ui

yarn dlx shadcn-ui@latest init
yarn dlx shadcn-ui@latest add [component-name]

Trunk

After committing some changes for the first time, install the Trunk Client extension in VSCode then run the following command:

trunk init --vscode
trunk login

which will take you through initialising the required linters for the project. Logging in will allow you to use the full extent of Trunk.

Prettier

Create a .prettierrc.yml configuration file for Prettier:

trailingComma: es5
semi: false
singleQuote: true
jsxSingleQuote: true

Or any configurations you want, honestly.

Convex

Creates the convex directory, in which we keep our API functions, i.e. our queries and mutations.

yarn add convex
yarn dlx convex dev

Clerk

Create an application in the official Clerk website, selecting GitHub only as a sign-up option.

yarn add @clerk/nextjs

Copy the Clerk API keys to the .env.local file.

Connect Clerk to Convex by following the instructions here.

Folder Structure

  • Uses Route Groups, i.e. folders whose names are enclosed with parentheses, to create specific layouts for similar pages
  • Uses _components directory within a Route Group for group-specific components
  • Uses components directory in the project root directory for reusable components

Launching the Development Environment

yarn dlx convex dev # Will create .env.local
yarn dev

API

Using Convex you can create the schema, as well as use mutation and query to create the API.

// convex/schema.ts
import { defineSchema, defineTable } from 'convex/server'
import { v } from 'convex/values'

export default defineSchema({
  documents: defineTable({
    // add the fields using v to type them and make them optional
  })
    .index('by_user', [...])
})
// convex/documents.ts
import { v } from 'convex/values'

import { mutation, query } from './_generated/server'

export const create = mutation({
  args: {
    // the arguments needed to create the object
  },
  handler: async (ctx, args) => {

    // for auth check
    const identity = await ctx.auth.getUserIdentity()
    if (!identity) {
      throw new Error('Not authenticated')
    }

    // to interact with the connected DB
    const document = await ctx.db.insert('documents', {
      // enter the fields here
    })

    return document
  },

notion's People

Contributors

mhrdini avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.