Skip to content

Commit

Permalink
feat: 髪色の変更もDBに保存されるように
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-shobon committed Nov 4, 2024
1 parent 243fd4f commit 5fa3771
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
76 changes: 49 additions & 27 deletions app/components/ModelConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,65 @@ interface ModelConfigProps {
characterSetting: CharacterSetting;
onModelSelect?: (model: Model) => void;
onAccessorySelect?: (accessory: Accessory) => void;
onHairColorChange?: (color: string) => void;
}

export function ModelConfig({
characterSetting,
onModelSelect,
onAccessorySelect,
onHairColorChange,
}: ModelConfigProps) {
return (
<div className="mx-auto w-full max-w-screen-sm sm:px-4">
<div className="flex justify-between">
{MODEL_LIST.map((model) => (
<label key={model}>
<input
type="radio"
name="model"
value={model}
checked={model === characterSetting.character}
onChange={() => onModelSelect?.(model)}
/>
<span>{model}</span>
</label>
))}
<div className="mx-auto grid w-full max-w-screen-sm gap-y-4 px-4">
<div className="flex gap-4">
<span className="flex-shrink-0">モデル:</span>
<div className="flex flex-grow flex-wrap justify-between gap-2">
{MODEL_LIST.map((model) => (
<label key={model}>
<input
type="radio"
name="model"
value={model}
checked={model === characterSetting.character}
onChange={() => onModelSelect?.(model)}
/>
<span>{model}</span>
</label>
))}
</div>
</div>

<div className="flex justify-between">
{ACCESSORY_LIST.map((accessory) => (
<label key={accessory}>
<input
type="radio"
name="accessory"
value={accessory}
checked={accessory === characterSetting.accessory}
onChange={() => onAccessorySelect?.(accessory)}
/>
<span>{accessory}</span>
</label>
))}
<div className="flex gap-4">
<span className="flex-shrink-0">アクセサリー:</span>
<div className="flex flex-grow flex-wrap justify-between gap-2">
{ACCESSORY_LIST.map((accessory) => (
<label key={accessory}>
<input
type="radio"
name="accessory"
value={accessory}
checked={accessory === characterSetting.accessory}
onChange={() => onAccessorySelect?.(accessory)}
/>
<span>{accessory}</span>
</label>
))}
</div>
</div>

<div>
<label className="flex gap-4">
<span className="flex-shrink-0">髪の色:</span>
<input
type="color"
value={characterSetting.hair}
onChange={(e) => {
// TODO: 色の更新処理が頻繁に呼び出されてしまうため、debounceする
onHairColorChange?.(e.target.value);
}}
/>
</label>
</div>

{/* モデル選択ボタン */}
Expand Down
8 changes: 8 additions & 0 deletions app/routes/_auth.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export default function Page(): ReactNode {
});
};

const handleHairColorChange = (color: string) => {
updateCharacterSetting({
...myProfile.characterSetting,
hair: color,
});
};

return (
<div className="min-h-dvh w-full" style={{ viewTransitionName: "main" }}>
<main className="grid w-full gap-y-4">
Expand All @@ -33,6 +40,7 @@ export default function Page(): ReactNode {
characterSetting={myProfile.characterSetting}
onModelSelect={handleModelSelect}
onAccessorySelect={handleAccessorySelect}
onHairColorChange={handleHairColorChange}
/>
</main>
</div>
Expand Down

0 comments on commit 5fa3771

Please sign in to comment.