Allow configuring affinity between groups #161

Merged
bustikiller merged 6 commits from group-affinities into main 2024-12-28 18:56:18 +00:00
2 changed files with 3 additions and 6 deletions
Showing only changes of commit d307ff6927 - Show all commits

View File

@ -1,9 +1,6 @@
import { Slider } from 'primereact/slider';
import React, { useEffect, useState } from 'react';
export default function AffinitySlider({ initialValue, onChange }: { initialValue: number, onChange?: (value: number) => void }) {
const [value, setValue] = useState(initialValue);
useEffect(() => {setValue(initialValue)}, [initialValue]);
export default function AffinitySlider({value , onChange }: { value: number, onChange: (value: number) => void }) {
const label = (value: number) => {
if (value < 0.2) {
@ -25,7 +22,7 @@ export default function AffinitySlider({ initialValue, onChange }: { initialValu
return (
<>
<Slider value={value} min={0} max={2} step={.1} onChange={(e) =>setValue(e.value)} className='w-80 bg-gray-400' />
<Slider value={value} min={0} max={2} step={.1} onChange={(e) =>onChange(e.value)} className='w-80 bg-gray-400' />
<span className="px-4 w-1/5">
{ label(value) }
</span>

View File

@ -113,7 +113,7 @@ export default function GroupFormDialog({ groups, onCreate, onHide, group, visib
groups.map((group) =>
<div key={group.id} className="flex flex-row hover:bg-gray-300 px-3 py-2 items-center">
<span className="w-1/3 text-right px-4">{group.name}</span>
<AffinitySlider initialValue={group.id && affinities[group.id] || 2} />
<AffinitySlider value={group.id && affinities[group.id] || 2} onChange={(value) => setAffinities({...affinities, [group.id || "default"]:value})} />
</div>)
}
</div>