Reorder categories (#12)

* feat: add next category id column

* feat: reorder categories (front)

* refactor: remove dead code & some optimization

* feat(wip): add order column + sql request + trigger

* refactor: fix warnings

* fix: syntax error in migration

* feat: create sql query (category reorder)

* feat: use prisma generated types instead

* feat: create some react context with hooks

* refactor: move a lot of code from home page to
dedicated components

* refactor: extend generated prisma types

* refactor: use hooks and move links footer in dedicated component

* refactor: fix bad types used

* fix: warnings caused by setState loop

* feat: use nextid instead of order column

* fix: reorder categories (front)

* fix: sort categories by nextId

* feat: prevent send update request if cat.id equal target.id

* fix: reorganization applied even if there is no change

* chore: remove unused en var

* feat: check if nextid category exist

* chore: sql query for migration

* refactor: remove useless code and prevent sending request when category not moving

* fix: redorder categories when sending request
This commit is contained in:
Sonny
2023-12-14 00:15:58 +01:00
committed by GitHub
parent 406bf281b0
commit ad682faa9e
57 changed files with 1016 additions and 572 deletions

View File

@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `category` ADD COLUMN `nextId` INTEGER NULL;

View File

@@ -0,0 +1,10 @@
-- set default next id for each category based on LEAD(id) (LEAD -> Next)
UPDATE Category AS c
JOIN (
SELECT
id,
LEAD(id) OVER (PARTITION BY authorId ORDER BY id) AS nextCategoryId
FROM Category
) AS n ON c.id = n.id
SET c.nextId = n.nextCategoryId;

View File

@@ -33,6 +33,8 @@ model Category {
author User @relation(fields: [authorId], references: [id])
authorId Int
nextId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt