diff --git a/app/lib/affinities.tsx b/app/lib/affinities.tsx new file mode 100644 index 0000000..9480936 --- /dev/null +++ b/app/lib/affinities.tsx @@ -0,0 +1,3 @@ +export class Affinities { + [key:string]: number; +} \ No newline at end of file diff --git a/app/ui/components/form/affinitySlider.tsx b/app/ui/components/form/affinitySlider.tsx new file mode 100644 index 0000000..da82ff9 --- /dev/null +++ b/app/ui/components/form/affinitySlider.tsx @@ -0,0 +1,34 @@ +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]); + + const label = (value: number) => { + if (value < 0.2) { + return 'Nemesis'; + } else if (value < 0.5) { + return 'Enemies'; + } else if (value < 0.9) { + return 'Bad vibes'; + } else if (value < 1.1) { + return 'Neutral'; + } else if (value < 1.5) { + return 'Good vibes'; + } else if (value < 1.8) { + return 'Good friends'; + } else { + return 'Besties'; + } + } + + return ( + <> + setValue(e.value)} className='w-80 bg-gray-400' /> + + { label(value) } + + + ) +} \ No newline at end of file diff --git a/app/ui/components/group-form-dialog.tsx b/app/ui/components/group-form-dialog.tsx index d652a13..2a78b67 100644 --- a/app/ui/components/group-form-dialog.tsx +++ b/app/ui/components/group-form-dialog.tsx @@ -2,18 +2,20 @@ 'use client'; +import { AbstractApi } from '@/app/api/abstract-api'; +import { Group, GroupSerializer } from '@/app/lib/group'; import { classNames } from '@/app/ui/components/button'; -import { Dialog } from 'primereact/dialog'; import { ColorPicker } from 'primereact/colorpicker'; +import { Dialog } from 'primereact/dialog'; import { Dropdown } from 'primereact/dropdown'; import { FloatLabel } from 'primereact/floatlabel'; import { InputText } from 'primereact/inputtext'; -import { useState } from 'react'; -import { Group, GroupSerializer } from '@/app/lib/group'; -import { ApiError } from 'next/dist/server/api-utils'; -import { AbstractApi } from '@/app/api/abstract-api'; +import { useEffect, useState } from 'react'; +import AffinitySlider from './form/affinitySlider'; +import { Affinities } from '@/app/lib/affinities'; +import { getSlug } from '@/app/lib/utils'; -export default function GroupFormDialog({groups, onCreate, onHide, group, visible }: { +export default function GroupFormDialog({ groups, onCreate, onHide, group, visible }: { groups: Group[], onCreate?: () => void, onHide: () => void, @@ -25,6 +27,19 @@ export default function GroupFormDialog({groups, onCreate, onHide, group, visibl const [icon, setIcon] = useState(group?.icon || ''); const [color, setColor] = useState(group?.color || ''); const [parentId, setParentId] = useState(group?.parentId || ''); + const [affinities, setAffinities] = useState({}); + + useEffect(() => { + if (group?.id === undefined) { + setAffinities({}); + } else { + fetch(`/api/${getSlug()}/groups/${group?.id}/affinities`) + .then((response) => response.json()) + .then((data) => { + setAffinities(data); + }); + } + }, []); const api = new AbstractApi(); const serializer = new GroupSerializer(); @@ -90,6 +105,18 @@ export default function GroupFormDialog({groups, onCreate, onHide, group, visibl {group?.id !== undefined ? 'Update' : 'Create'} + +
+ Describe the affinity with the rest of the groups + + { + groups.map((group) => +
+ {group.name} + +
) + } +
); diff --git a/app/ui/groups/table.tsx b/app/ui/groups/table.tsx index 41af307..4088cfa 100644 --- a/app/ui/groups/table.tsx +++ b/app/ui/groups/table.tsx @@ -2,13 +2,12 @@ 'use client'; -import { Group, GroupSerializer } from '@/app/lib/group'; -import TableOfContents from '../components/table-of-contents'; -import { MapPinIcon, PencilIcon, TrashIcon } from '@heroicons/react/24/outline'; import { AbstractApi } from '@/app/api/abstract-api'; -import { TreeTable } from 'primereact/treetable'; +import { Group, GroupSerializer } from '@/app/lib/group'; +import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline'; import { Column } from 'primereact/column'; import { TreeNode } from 'primereact/treenode'; +import { TreeTable } from 'primereact/treetable'; export default function GroupsTable({ groups, onUpdate, onEdit }: { groups: Group[],