From dcfa9c2b72218f4cdbea4c2f2928c95f0938c612 Mon Sep 17 00:00:00 2001 From: Kashargul <144968721+Kashargul@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:12:19 +0100 Subject: [PATCH] adds Search to smart vendors (#16587) --- tgui/packages/tgui/interfaces/SmartVend.tsx | 309 ++++++++++++++------ 1 file changed, 215 insertions(+), 94 deletions(-) diff --git a/tgui/packages/tgui/interfaces/SmartVend.tsx b/tgui/packages/tgui/interfaces/SmartVend.tsx index 7c8eeba29d3..29a2cf76713 100644 --- a/tgui/packages/tgui/interfaces/SmartVend.tsx +++ b/tgui/packages/tgui/interfaces/SmartVend.tsx @@ -1,8 +1,18 @@ -import { map } from 'common/collections'; import { BooleanLike } from 'common/react'; +import { createSearch } from 'common/string'; +import { useState } from 'react'; import { useBackend } from '../backend'; -import { Box, Button, NoticeBox, Section, Table } from '../components'; +import { + Box, + Button, + Dropdown, + Flex, + Input, + NoticeBox, + Section, + Table, +} from '../components'; import { Window } from '../layouts'; type Data = { @@ -14,8 +24,28 @@ type Data = { type content = { name: string; index: number; amount: number }; +const sortTypes = { + Alphabetical: (a: content, b: content) => a.name > b.name, + 'By amount': (a: content, b: content) => -(a.amount - b.amount), +}; + export const SmartVend = (props) => { - const { act, config, data } = useBackend(); + const { config, data } = useBackend(); + const [searchText, setSearchText] = useState(''); + const [sortOrder, setSortOrder] = useState('Alphabetical'); + const [descending, setDescending] = useState(false); + + function handleSearchText(value: string) { + setSearchText(value); + } + + function handleSortOrder(value: string) { + setSortOrder(value); + } + + function handleDescending(value: boolean) { + setDescending(value); + } const { secure, locked, contents } = data; @@ -39,100 +69,191 @@ export const SmartVend = (props) => { {(contents.length === 0 && ( Unfortunately, this {config.title} is empty. )) || ( - - - Item - - Amount - - - Dispense - - - {map(contents, (value: content, key) => ( - - - {value.name} - - - {value.amount} in stock - - - - - - - - - - - ))} -
+ <> + + + )} ); }; + +const SheetSearch = (props: { + searchText: string; + sortOrder: string; + descending: boolean; + onSearchText: Function; + onSortOrder: Function; + onDescending: Function; +}) => { + const { + searchText, + sortOrder, + descending, + onSearchText, + onSortOrder, + onDescending, + } = props; + return ( + + + + onSearchText(value)} + /> + + + onSortOrder(v)} + /> + + +