-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved required_files in project view
- Loading branch information
Showing
4 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
frontend/app/[locale]/components/general/RequiredFilesList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
"use client" | ||
|
||
import {IconButton, List, ListItem, ListItemText, TextField, Typography, Button} from "@mui/material"; | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import React, {useState} from "react"; | ||
import Box from "@mui/material/Box"; | ||
|
||
interface ItemsListProps { | ||
items: string[], | ||
setItems: (value: (((prevState: any[]) => any[]) | any[])) => void, | ||
input_placeholder: string, | ||
empty_list_placeholder:string, | ||
button_text: string | ||
} | ||
|
||
const ItemsList = ({items, setItems, input_placeholder, empty_list_placeholder, button_text}: ItemsListProps) => { | ||
const [newItem, setNewItem] = useState('') | ||
const [noInput, setNoInput] = useState(false) | ||
|
||
const handleDelete = (index: number) => { | ||
const newFields = [...items]; | ||
newFields.splice(index, 1); | ||
setItems(newFields); | ||
} | ||
|
||
const addNewFile = () => { | ||
if (newItem !== '') { | ||
const newItems = [...items]; | ||
newItems.push(newItem) | ||
setItems(newItems); | ||
setNewItem(''); | ||
setNoInput(false); | ||
console.log(items); | ||
} else { | ||
setNoInput(true); | ||
} | ||
} | ||
|
||
return ( | ||
<Box> | ||
{items.length === 0 ? ( | ||
<Typography variant={"body1"} color={"text.disabled"} sx={{padding: 1}}>{empty_list_placeholder}</Typography> | ||
) : ( | ||
<List | ||
sx={{ | ||
width: '100%', | ||
maxWidth: 360, | ||
bgcolor: 'background.paper', | ||
maxHeight: 150, | ||
overflow: 'auto', | ||
}} | ||
> | ||
{items.map((field, index) => ( | ||
<ListItem | ||
key={index} | ||
secondaryAction={ | ||
<IconButton | ||
edge="end" | ||
aria-label="delete" | ||
onClick={() => handleDelete(index)} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
} | ||
> | ||
<ListItemText | ||
primary={field} | ||
/> | ||
</ListItem> | ||
))} | ||
</List> | ||
) | ||
} | ||
<Box | ||
display={'flex'} | ||
flexDirection={'row'} | ||
justifyContent={'flex-start'} | ||
> | ||
<TextField | ||
value={newItem} | ||
onChange={(event) => setNewItem(event.target.value)} | ||
variant="outlined" | ||
size="small" | ||
error={noInput} | ||
placeholder={input_placeholder} | ||
sx={{ | ||
width: 'fit-content', | ||
}} | ||
/> | ||
<Button | ||
onClick={() => addNewFile()} | ||
variant={'contained'} | ||
color={'secondary'} | ||
sx={{ | ||
width: 'fit-content', | ||
color: 'secondary.contrastText', | ||
marginX: 1 | ||
}} | ||
> | ||
<Typography>{button_text}</Typography> | ||
</Button> | ||
</Box> | ||
</Box> | ||
); | ||
} | ||
|
||
export default ItemsList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters