Skip to content

コード保存/読込機能を追加#29

Merged
Haruto-Imai merged 5 commits intomainfrom
feature/save-code
Nov 14, 2025
Merged

コード保存/読込機能を追加#29
Haruto-Imai merged 5 commits intomainfrom
feature/save-code

Conversation

@Haruto-Imai
Copy link
Contributor

  • 盤面保存機能に関する変数、型、関数などに"Board"の文字を追加しました。
  • 盤面保存/読込機能をほぼそのまま流用し、コード保存/読込機能を追加しました。

@@ -1,6 +1,6 @@
import { json } from "@sveltejs/kit";
import { prisma } from "@/lib/prisma.server.ts";
import { createPreview } from "@/lib/board-preview.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

見落としてたけどこれ @/lib/board-preview.ts の方が適切

});

export async function POST({ request }) {
let requestData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これをやると暗黙に any 型 (型チェックスキップ) になるので、型アノテーションは必ずつけてね (board のほうも)

type Code = v.InferOutput<typeof CodeSchema>;


let requestData: Code | undefined = undefined;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここではまだ unknown

let requestData: unknown;

id Int @id @default(autoincrement())
createdAt DateTime @default(now())
codeData String
codeName String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

オブジェクトのプロパティにはそのオブジェクト自体の名前を入れないでね。

class Car {
  // bad
  carName: string
  // good
  name: string
}

const car = new Car();
// bad
car.carName
// good
car.name

boardPreview Json
}

model CodeState {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは BoardState にも言えるけど、データベースに保存される段階ではもうデータであって状態じゃないので、単純に Board Code という命名がいいと思う

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(これはデータは状態になりえないということを暗黙に意味するものではない)

if (code) {
editingCode = code;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これよりも長くなりそうだったら Reactive Class に分割するのも検討して良さそう

https://svelte.dev/docs/svelte/$state#Classes

{/if}

<div class="modal-action">
<button class="btn" onclick={() => (loadCodeState = { state: "closed" })}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この部分も、長くなりそうだったらコンポネントを分割してね

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 13, 2025

Deploying life-code with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8bb1d31
Status: ✅  Deploy successful!
Preview URL: https://94a4f798.life-code.pages.dev
Branch Preview URL: https://feature-save-code.life-code.pages.dev

View logs

Copy link
Contributor

@aster-void aster-void left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動作確認はできてないけどコードは良さそう

@Haruto-Imai Haruto-Imai merged commit 8a60e4c into main Nov 14, 2025
3 of 4 checks passed
@Haruto-Imai Haruto-Imai deleted the feature/save-code branch November 14, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments