Skip to content

Commit

Permalink
Merge pull request #128 from frankhereford/track-changes
Browse files Browse the repository at this point in the history
Create Moves model and start capturing moves into it
  • Loading branch information
frankhereford authored Nov 16, 2022
2 parents b0769ce + 9be4e1c commit 462b1dc
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 5 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release_on_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
branches:
- main

jobs:
release-on-push:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
steps:
- uses: rymndhng/[email protected]
with:
bump_version_scheme: minor
use_github_release_notes: true
- name: Check Output Parameters
run: |
echo "Got tag name ${{ steps.release.outputs.tag_name }}"
echo "Got release version ${{ steps.release.outputs.version }}"
- name: Checkout
uses: actions/checkout@v2

- name: Set version
id: package_version
uses: KageKirin/set-node-package-version@v0
with:
version: ${{ steps.release.outputs.version }}

- name: Commit new version
run: |
git commit -am "CI: update version from PR release"
git push https://${{ github.token }}@github.com/OWNER/REPO
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Stuff I learned

* 🏷️ GitHub release tags; we should bump versions on every PR via PR labels
* Via: https://github.com/marketplace/actions/tag-release-on-push-action
* 🌼 Daisy UI
* [Extendable](https://github.com/frankhereford/katamino/blob/main/tailwind.config.cjs#L5-L10)
* 💨 Tailwind CSS
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "katamino",
"version": "0.3.0",
"version": "0.4.0",
"private": true,
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
Expand Down
34 changes: 34 additions & 0 deletions prisma/migrations/20221115233313_add_moves_model/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Warnings:
- You are about to drop the column `last_update` on the `blocks` table. All the data in the column will be lost.
- You are about to drop the column `moves` on the `pentas` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "blocks" DROP COLUMN "last_update",
ADD COLUMN "lastUpdate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "pentas" DROP COLUMN "moves",
ADD COLUMN "moveCount" INTEGER NOT NULL DEFAULT 0;

-- CreateTable
CREATE TABLE "Move" (
"id" TEXT NOT NULL,
"pentaId" TEXT NOT NULL,
"blockId" TEXT NOT NULL,
"moveDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"visible" BOOLEAN NOT NULL DEFAULT false,
"translation" JSONB NOT NULL,
"rotation" JSONB NOT NULL,
"reflection" BOOLEAN NOT NULL,

CONSTRAINT "Move_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Move" ADD CONSTRAINT "Move_pentaId_fkey" FOREIGN KEY ("pentaId") REFERENCES "pentas"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Move" ADD CONSTRAINT "Move_blockId_fkey" FOREIGN KEY ("blockId") REFERENCES "blocks"("id") ON DELETE CASCADE ON UPDATE CASCADE;
19 changes: 17 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,23 @@ model Piece {
@@map(name: "pieces")
}

model Move {
id String @id @default(cuid())
pentaId String
blockId String
moveDate DateTime @default(now())
visible Boolean @default(false)
translation Json
rotation Json
reflection Boolean
penta Penta @relation(fields: [pentaId], references: [id], onDelete: Cascade)
block Block @relation(fields: [blockId], references: [id], onDelete: Cascade)
}

// a block belongs to a penta
model Block {
id String @id @default(cuid())
last_update DateTime @default(now()) @updatedAt
lastUpdate DateTime @default(now()) @updatedAt
pieceId String
pentaId String
visible Boolean @default(false)
Expand All @@ -44,6 +57,7 @@ model Block {
reflection Boolean
piece Piece @relation(fields: [pieceId], references: [id], onDelete: Cascade)
penta Penta @relation(fields: [pentaId], references: [id], onDelete: Cascade)
moves Move[]
@@map(name: "blocks")
}
Expand All @@ -54,12 +68,13 @@ model Penta {
userId String
availablePentaId String
completed Boolean @default(false)
moves Int @default(0)
moveCount Int @default(0)
columns Int
borderWidth Int @default(2)
blocks Block[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
availablePenta AvailablePenta @relation(fields: [availablePentaId], references: [id])
moves Move[]
@@map(name: "pentas")
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/components/Penta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function Penta(props: PentaProps) {
const completionBoard = Array2D.build((props.penta?.columns || 12), boardHeight, false)
const completionBlocks = _.cloneDeep(props.penta?.blocks); // do i really need this slow op?
// im letting my lazy typing come in here with this old code
const sortedCompletionBlocks = completionBlocks.sort((a: any, b: any) => a.last_update - b.last_update)
const sortedCompletionBlocks = completionBlocks.sort((a: any, b: any) => a.lastUpdate - b.lastUpdate)
sortedCompletionBlocks.forEach((block: any) => {
if (!block.visible) { return }
const shape = transformBlockShape(block, 0, true, 5)
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function Penta(props: PentaProps) {

const blocks = _.cloneDeep(props.penta?.blocks);
// im letting my lazy typing come in here with this old code
const sortedBlocks = blocks.sort((a: any, b: any) => a.last_update - b.last_update)
const sortedBlocks = blocks.sort((a: any, b: any) => a.lastUpdate - b.lastUpdate)
sortedBlocks.forEach((block: any) => {
if (!block.visible) { return }
const shape = transformBlockShape(block, props.penta?.borderWidth, true, props.penta?.columns)
Expand Down
28 changes: 28 additions & 0 deletions src/server/trpc/router/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ import { z } from "zod";

import { isBlockOwner } from "../../../utils/database";

async function saveMove(ctx: any, block: any) {
const move = await ctx.prisma.move.create({
data: {
block: {
connect: {
id: block.id
}
},
penta: {
connect: {
id: block.pentaId
}
},
visible: block.visible,
translation: block.translation || {},
rotation: block.rotation || {},
reflection: block.reflection
}
})
return move
}

export const blockRouter = router({

set_rotation: protectedProcedure
Expand Down Expand Up @@ -30,6 +52,9 @@ export const blockRouter = router({
}
}
});

await saveMove(ctx, block)

return block;
}),

Expand All @@ -56,6 +81,7 @@ export const blockRouter = router({
reflection: input.reflection
}
});
await saveMove(ctx, block)
return block;
}),

Expand All @@ -82,6 +108,7 @@ export const blockRouter = router({
translation: input.translation
}
});
await saveMove(ctx, block)
return block;
}),

Expand All @@ -108,6 +135,7 @@ export const blockRouter = router({
visible: input.visible ? input.visible : false
}
});
await saveMove(ctx, block)
return block;
}),

Expand Down

0 comments on commit 462b1dc

Please sign in to comment.