diff --git a/src/Components/Auth/LoginPage.tsx b/src/Components/Auth/LoginPage.tsx index 0f19c1e4..33112f05 100644 --- a/src/Components/Auth/LoginPage.tsx +++ b/src/Components/Auth/LoginPage.tsx @@ -1,7 +1,7 @@ import {useState, useRef} from 'react' import {Link} from 'react-router-dom' import ErrorText from '../Typography/ErrorText' -import InputText from '../Input/InputText' +import {TextInput} from '../Input/TextInput' import * as React from 'react' export function LoginPage(){ @@ -44,9 +44,9 @@ export function LoginPage(){
- updateFormValue(v)}/> + updateFormValue(v)}/> - updateFormValue(v)}/> + updateFormValue(v)}/>
diff --git a/src/Components/Auth/SignupPage.tsx b/src/Components/Auth/SignupPage.tsx index cc91c0d1..1e973654 100644 --- a/src/Components/Auth/SignupPage.tsx +++ b/src/Components/Auth/SignupPage.tsx @@ -1,7 +1,7 @@ import { useState, useRef } from 'react' import { Link } from 'react-router-dom' import ErrorText from '../Typography/ErrorText' -import InputText from '../Input/InputText' +import {TextInput} from '../Input/TextInput' import * as React from 'react' export function SignupPage() { @@ -45,13 +45,9 @@ export function SignupPage() {
submitForm(e)}>
- - - - - - - + + +
{errorMessage} diff --git a/src/Components/Input/InputText.tsx b/src/Components/Input/InputText.tsx deleted file mode 100644 index 227d3929..00000000 --- a/src/Components/Input/InputText.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import { useEffect, useState } from "react" -import * as React from "react" - -type InputTextProps = { - labelTitle?: string; - labelStyle?: string; - type?: string; - dataField?: string; - containerStyle?: string; - defaultValue: string; - placeholder?: string; - updateFormValue?: (value: string ) => void; -} - - -function InputText({labelTitle, labelStyle, type, dataField, containerStyle, defaultValue, placeholder, updateFormValue} : InputTextProps){ - - const [value, setValue] = useState(defaultValue) - - useEffect(() => { - setValue(defaultValue) - }, [defaultValue]) - - - const updateInputValue = (val : string) => { - setValue(val) - if(updateFormValue) - updateFormValue(val) - - } - - return( -
- {labelTitle ? - : " "} - updateInputValue(e.target.value)}className="tw-input tw-input-bordered tw-w-full " /> -
- ) -} - - -export default InputText \ No newline at end of file diff --git a/src/Components/Input/TextAreaInput.tsx b/src/Components/Input/TextAreaInput.tsx index a530b07f..55e4ecf0 100644 --- a/src/Components/Input/TextAreaInput.tsx +++ b/src/Components/Input/TextAreaInput.tsx @@ -15,30 +15,20 @@ type TextAreaProps = { -function TextAreaInput({ labelTitle, dataField, labelStyle, containerStyle, inputStyle, defaultValue, placeholder, updateFormValue }: TextAreaProps) { - - const [value, setValue] = useState(defaultValue) - - useEffect(() => { - setValue(defaultValue) - }, [defaultValue]) +export function TextAreaInput({ labelTitle, dataField, labelStyle, containerStyle, inputStyle, defaultValue, placeholder, updateFormValue }: TextAreaProps) { + + - const updateInputValue = (val: string) => { - setValue(val) - if (updateFormValue) - updateFormValue(val) - } return (
{labelTitle ? : ""} - +
) } -export default TextAreaInput \ No newline at end of file diff --git a/src/Components/Input/TextInput.tsx b/src/Components/Input/TextInput.tsx new file mode 100644 index 00000000..2732fb85 --- /dev/null +++ b/src/Components/Input/TextInput.tsx @@ -0,0 +1,29 @@ +import { useEffect, useState } from "react" +import * as React from "react" + +type InputTextProps = { + labelTitle?: string; + labelStyle?: string; + type?: string; + dataField?: string; + containerStyle?: string; + defaultValue?: string; + placeholder?: string; + updateFormValue?: (value: string ) => void; +} + + +export function TextInput({labelTitle, labelStyle, type, dataField, containerStyle, defaultValue, placeholder, updateFormValue} : InputTextProps){ + + return( +
+ {labelTitle ? + : " "} + updateFormValue&& updateFormValue(e.target.value)}className="tw-input tw-input-bordered tw-w-full " /> +
+ ) +} + + diff --git a/src/Components/Input/index.tsx b/src/Components/Input/index.tsx new file mode 100644 index 00000000..432f954c --- /dev/null +++ b/src/Components/Input/index.tsx @@ -0,0 +1,2 @@ +export {TextAreaInput} from "./TextAreaInput" +export {TextInput} from "./TextInput" \ No newline at end of file diff --git a/src/Components/Map/ItemForm.tsx b/src/Components/Map/ItemForm.tsx new file mode 100644 index 00000000..a1142370 --- /dev/null +++ b/src/Components/Map/ItemForm.tsx @@ -0,0 +1,7 @@ +import * as React from 'react' + +export const ItemForm = ({ children }:{children?: React.ReactNode}) => { + return ( +
{children}
+ ) +} diff --git a/src/Components/Map/ItemView.tsx b/src/Components/Map/ItemView.tsx new file mode 100644 index 00000000..5442d155 --- /dev/null +++ b/src/Components/Map/ItemView.tsx @@ -0,0 +1,7 @@ +import * as React from 'react' + +export const ItemView = ({ children }:{children?: React.ReactNode}) => { + return ( +
{children}
+ ) +} diff --git a/src/Components/Map/Layer.tsx b/src/Components/Map/Layer.tsx index daa3543f..0ec057c2 100644 --- a/src/Components/Map/Layer.tsx +++ b/src/Components/Map/Layer.tsx @@ -7,7 +7,7 @@ import { useTags } from './hooks/useTags' import { useAddItem, useItems, useResetItems } from './hooks/useItems' import { useEffect, useState } from 'react' import { useAddLayer } from './hooks/useLayers' -import ItemFormPopup, { ItemFormPopupProps } from './Subcomponents/ItemFormPopup' +import { ItemFormPopupProps, ItemFormPopup } from './Subcomponents/ItemFormPopup' export const Layer = (props: LayerProps) => { @@ -22,7 +22,7 @@ export const Layer = (props: LayerProps) => { // create a JS-Map with all Tags const tagMap = new Map(tags?.map(key => [key.id, key])); - + // returns all tags for passed item @@ -86,14 +86,38 @@ export const Layer = (props: LayerProps) => { } return ( - + + + + { + (props.children && React.Children.toArray(props.children).some(e => React.isValidElement(e) && typeof e.type !== "string" && e.type.name === "ItemForm") ? + React.Children.toArray(props.children).map((child) => + React.isValidElement(child) && typeof child.type !== "string" && child.type.name === "ItemView" ? + {child} + : "" + ) + : + <> + + ) + } + ); }) } {props.children} - {props.itemFormPopup && props.itemFormPopup.layer.name == props.name && - + {props.itemFormPopup && props.itemFormPopup.layer!.name == props.name && + (props.children && React.Children.toArray(props.children).some(e => React.isValidElement(e) && typeof e.type !== "string" && e.type.name === "ItemForm") ? + React.Children.toArray(props.children).map((child) => + React.isValidElement(child) && typeof child.type !== "string" && child.type.name === "ItemForm" ? + {child} + : "" + ) + : + <> + + ) } ) diff --git a/src/Components/Map/Subcomponents/ItemFormPopup.tsx b/src/Components/Map/Subcomponents/ItemFormPopup.tsx index 6d20d370..0ee85394 100644 --- a/src/Components/Map/Subcomponents/ItemFormPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemFormPopup.tsx @@ -1,21 +1,25 @@ import * as React from 'react' import { LatLng } from 'leaflet' import { Popup as LeafletPopup, useMap } from 'react-leaflet' -import { useEffect, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { useAddItem, useUpdateItem } from '../hooks/useItems' import { Geometry, LayerProps, Item, ItemsApi } from '../../../types' -import TextAreaInput from '../../Input/TextAreaInput' -import InputText from '../../Input/InputText' +import {TextAreaInput} from '../../Input/TextAreaInput' +import {TextInput} from '../../Input/TextInput' export interface ItemFormPopupProps { position: LatLng, layer: LayerProps, item?: Item, api?: ItemsApi, + children?: React.ReactNode, setItemFormPopup: React.Dispatch> } -export default function ItemFormPopup(props: ItemFormPopupProps) { +export function ItemFormPopup(props: ItemFormPopupProps) { + + const formRef = useRef(null); + const [spinner, setSpinner] = useState(false); @@ -25,30 +29,29 @@ export default function ItemFormPopup(props: ItemFormPopupProps) { const handleSubmit = async (evt: any) => { const formItem: Item = {} as Item; - Array.from(evt.target).forEach((input: HTMLFormElement) => { + Array.from(evt.target).forEach((input: HTMLInputElement) => { if (input.name) { - console.log(input.name + ": " + input.value); formItem[input.name] = input.value; } }); - formItem['position']=new Geometry(props.position.lng, props.position.lat); + formItem['position'] = new Geometry(props.position.lng, props.position.lat); evt.preventDefault(); setSpinner(true); if (props.item) { - formItem['id']=props.item.id; + formItem['id'] = props.item.id; await props.api?.updateItem!(formItem); - formItem['api']=props.api; - formItem['layer']=props.layer; + formItem['api'] = props.api; + formItem['layer'] = props.layer; await updateItem(formItem); setSpinner(false); map.closePopup(); } else { - formItem['id']=crypto.randomUUID(); + formItem['id'] = crypto.randomUUID(); await props.api?.createItem!(formItem); - formItem['api']=props.api; - formItem['layer']=props.layer; + formItem['api'] = props.api; + formItem['layer'] = props.layer; await addItem(formItem); setSpinner(false); map.closePopup(); @@ -57,17 +60,41 @@ export default function ItemFormPopup(props: ItemFormPopupProps) { } + const resetPopup = () => { + if (formRef.current) { + formRef.current.reset(); + } + } + + + + useEffect(() => { + resetPopup(); + }, [props.position]) + return ( { + setTimeout(function() { + resetPopup() + + }, 100); + } }} position={props.position}> - handleSubmit(e)}> + handleSubmit(e)}>
New {props.layer.name}
- - -
+ {props.children ? props.children : + <> + + + + } + +
+ +
) diff --git a/src/Components/Map/Subcomponents/ItemViewPopup.tsx b/src/Components/Map/Subcomponents/ItemViewPopup.tsx index 0b9e73cb..044ae844 100644 --- a/src/Components/Map/Subcomponents/ItemViewPopup.tsx +++ b/src/Components/Map/Subcomponents/ItemViewPopup.tsx @@ -1,13 +1,14 @@ import * as React from 'react' import { Popup as LeafletPopup, useMap } from 'react-leaflet' -import { Item} from '../../../types' +import { Item } from '../../../types' import { ItemFormPopupProps } from './ItemFormPopup' -import {HeaderView} from './HeaderView' +import { HeaderView } from './HeaderView' import StartEndView from './StartEndView' import { TextView } from './TextView' export interface ItemViewPopupProps { item: Item, + children?: React.ReactNode; setItemFormPopup?: React.Dispatch> } @@ -19,13 +20,14 @@ export const ItemViewPopup = (props: ItemViewPopupProps) => { return (
- -
- {item.start && item.end && - + + {props.children ? props.children : +
+ {item.start && item.end && + } + +
} - -
) diff --git a/src/Components/Map/index.tsx b/src/Components/Map/index.tsx index cb8e53bd..8e7abc0e 100644 --- a/src/Components/Map/index.tsx +++ b/src/Components/Map/index.tsx @@ -1,3 +1,6 @@ -export { UtopiaMap } from './UtopiaMap' +export { UtopiaMap } from './UtopiaMap'; export { Layer } from './Layer'; -export { Tags } from "./Tags"; \ No newline at end of file +export { Tags } from "./Tags"; +export {ItemViewPopup} from './Subcomponents/ItemViewPopup'; +export {ItemForm} from './ItemForm'; +export {ItemView} from './ItemView'; \ No newline at end of file diff --git a/src/Components/Profile/Settings.tsx b/src/Components/Profile/Settings.tsx index 6eb73c84..733a28e6 100644 --- a/src/Components/Profile/Settings.tsx +++ b/src/Components/Profile/Settings.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import {TitleCard} from '../Templates/TitleCard' -import InputText from '../Input/InputText' -import TextAreaInput from '../Input/TextAreaInput' +import {TextInput} from '../Input/TextInput' +import {TextAreaInput} from '../Input/TextAreaInput' import { toast } from 'react-toastify'; import {useNavigate} from 'react-router-dom' import * as React from 'react' @@ -62,7 +62,7 @@ export function Settings({useAuth}) {
- setName(v)} /> + setName(v)} />
setText(v)} inputStyle='tw-h-64'/> @@ -71,8 +71,8 @@ export function Settings({useAuth}) {
- setEmail(v)} /> - { + setEmail(v)} /> + { setPassword(v); setPasswordChanged(true); }} /> diff --git a/src/index.tsx b/src/index.tsx index aee240ca..4b34ee22 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,9 +1,10 @@ -export { UtopiaMap, Layer, Tags } from './Components/Map/index'; +export { UtopiaMap, Layer, Tags, ItemViewPopup, ItemForm, ItemView } from './Components/Map/index'; export {AppShell, Content, SideBar} from "./Components/AppShell" export {AuthProvider, useAuth, LoginPage, SignupPage} from "./Components/Auth" export {Settings} from './Components/Profile' export {Quests, Modal} from './Components/Gaming' export {TitleCard, CardPage} from './Components/Templates' +export {TextInput, TextAreaInput} from './Components/Input' import "./index.css" diff --git a/src/types.ts b/src/types.ts index 3eec3775..ac17a546 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ export interface UtopiaMapProps { export interface LayerProps { data?: Item[], - children?: React.ReactNode + children?: React.ReactNode, name: string, menuIcon: string, menuColor: string, @@ -28,16 +28,16 @@ export interface LayerProps { export class Item { id: string | number; - date_created?: string; - date_updated?: string | null; name: string; text: string; position: Geometry; - [key: string]: any; + date_created?: string; + date_updated?: string | null; start?: string; end?: string; tags?: number[]; - api?: ItemsApi + api?: ItemsApi; + [key: string]: any; constructor(id:string|number,name:string,text:string,position:Geometry, layer?: LayerProps, api?: ItemsApi){ this.id = id; this.name = name;