Skip to content

Commit

Permalink
Invoke simulate FeFeatureType instead of subId (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
TuTiDore authored Mar 5, 2023
1 parent 194fd9c commit 69100b8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
8 changes: 1 addition & 7 deletions src/features/Toys/Feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { Disclosure } from "@headlessui/react";

export function Feature({
toyId,
toySubId,
feature,
}: {
toyId: number;
toySubId: number;
feature: FeVCToyFeature;
}) {
return (
Expand All @@ -35,11 +33,7 @@ export function Feature({
</div>
</Disclosure.Button>
<Disclosure.Panel>
<FeatureForm
toyId={toyId}
toySubId={toySubId}
toyFeature={feature}
/>
<FeatureForm toyId={toyId} toyFeature={feature} />
</Disclosure.Panel>
</>
)}
Expand Down
4 changes: 1 addition & 3 deletions src/features/Toys/FeatureForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import useSimulate from "../../hooks/useSimulate";

type ToyFeatureFormProps = {
toyId: number;
toySubId: number;
toyFeature: FeVCToyFeature;
};

export default function FeatureForm({
toyId,
toySubId,
toyFeature,
}: ToyFeatureFormProps) {
const { feature_levels: initLevels, ...initFeature } = toyFeature;
Expand Down Expand Up @@ -76,7 +74,7 @@ export default function FeatureForm({
}

const { simulate, simulateHandler, simulateLevel, simulateLevelHandler } =
useSimulate(toyId, toySubId, toyFeature.feature_index);
useSimulate(toyId, toyFeature.feature_index, toyFeature.feature_type);

return (
<div className="grid grid-cols-[minmax(6rem,_1fr)_1fr_minmax(6rem,_3fr)_1fr] text-sm text-justify gap-y-1 p-4">
Expand Down
6 changes: 1 addition & 5 deletions src/features/Toys/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ export default function Toys() {
key={`${toy.toy_id} ${feature.feature_type} ${feature.feature_index}`}
>
<hr className="border-1 border-zinc-800 m-1 border-opacity-75" />
<Feature
toyId={toy.toy_id}
toySubId={toy.sub_id}
feature={feature}
/>
<Feature toyId={toy.toy_id} feature={feature} />
</div>
))}
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useSimulate.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { invoke } from "@tauri-apps/api";
import type { ChangeEvent } from "react";
import { useEffect, useState } from "react";
import type { FeVCFeatureType } from "../../src-tauri/bindings/FeVCFeatureType";
import { DEBOUNCE_TIME, SIMULATE_TOY_FEATURE } from "../data/constants";

export default function useSimulate(
toyId: number,
toySubId: number,
featureIndex: number
featureIndex: number,
featureType: FeVCFeatureType
) {
const [simulate, setSimulate] = useState(false);
const [simulateLevel, setSimulateLevel] = useState(0.5);
Expand All @@ -33,8 +34,8 @@ export default function useSimulate(
async function invokeSimulation(floatLevel: number) {
await invoke(SIMULATE_TOY_FEATURE, {
toyId,
toySubId,
featureIndex,
featureType,
floatLevel,
});
}
Expand Down

0 comments on commit 69100b8

Please sign in to comment.