-
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.
new: You can now define canned messages in configuration
* Implement templates for messages
- Loading branch information
Showing
15 changed files
with
292 additions
and
48 deletions.
There are no files selected for viewing
28 changes: 13 additions & 15 deletions
28
html/src/Components/MarkdownEditor/FullHeightTextArea.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 |
---|---|---|
@@ -1,26 +1,24 @@ | ||
import { Textarea, TextareaProps } from "@mantine/core"; | ||
import { ChangeEvent, useState } from "react"; | ||
import { Textarea } from "@mantine/core"; | ||
|
||
import classes from './FullHeightTextArea.module.css'; | ||
import { useUncontrolled } from "@mantine/hooks"; | ||
|
||
// interface FullHeightTextAreaProps extends TextareaProps { | ||
// value: string | number | readonly string[]; | ||
// label: string; | ||
// onChange: ChangeEventHandler<HTMLTextAreaElement>; | ||
// } | ||
export function FullHeightTextArea(props: TextareaProps) { | ||
interface FullHeightTextAreaProps { | ||
value?: string; | ||
onChange?: (value: string) => void; | ||
} | ||
export function FullHeightTextArea(props: FullHeightTextAreaProps) { | ||
const { value, onChange } = props; | ||
const [_value, setValue] = useState<string | number | readonly string[] | undefined>(value); | ||
|
||
function notifyChange(v: ChangeEvent<HTMLTextAreaElement>) { | ||
setValue(v.target.value) | ||
onChange && onChange(v) | ||
} | ||
const [_value, handleChange] = useUncontrolled({ | ||
value, | ||
onChange, | ||
}); | ||
|
||
return ( | ||
<Textarea {...props} resize="vertical" value={_value} | ||
<Textarea w="100%" flex="1" label="Message" description="This markdown will be displayed to the user" resize="vertical" value={_value} | ||
classNames={{root: classes.root, wrapper: classes.wrapper, input: classes.input}} | ||
onChange={(v) => { notifyChange(v) }} | ||
onChange={(e) => { handleChange(e.currentTarget.value) }} | ||
/> | ||
) | ||
} |
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
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,49 @@ | ||
import { H } from "@/APIClient"; | ||
import { Message } from "@/hupload"; | ||
import { ActionIcon, ActionIconProps, Menu, rem } from "@mantine/core"; | ||
import { IconListCheck } from "@tabler/icons-react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
interface TemplatesMenuProps { | ||
onChange: (message: string) => void; | ||
} | ||
|
||
export function TemplatesMenu(props:TemplatesMenuProps&ActionIconProps) { | ||
// Initialize state | ||
const [messages, setMessages] = useState<string[]>([]) | ||
|
||
// effects | ||
useEffect(() => { | ||
H.get('/messages').then((res) => { | ||
setMessages(res as string[]) | ||
}) | ||
},[]) | ||
|
||
const selectMessage = (index: number) => { | ||
H.get('/messages/'+index).then((res) => { | ||
const m = res as Message | ||
props.onChange(m.message) | ||
}) | ||
} | ||
|
||
if (messages.length === 0) { | ||
return | ||
} | ||
|
||
return ( | ||
<Menu withArrow withinPortal={false}> | ||
<Menu.Target> | ||
<ActionIcon size="xs" id="template" variant={"subtle"} m={rem(3)} radius="xl" style={{position:"absolute", top:0, right: 25}}> | ||
<IconListCheck style={{ width: rem(16), height: rem(16) }} stroke={1.5} /> | ||
</ActionIcon> | ||
</Menu.Target> | ||
<Menu.Dropdown> | ||
{messages.map((m, i) => ( | ||
<Menu.Item key={i+1} onClick={() => {selectMessage(i+1)}}> | ||
{m} | ||
</Menu.Item> | ||
))} | ||
</Menu.Dropdown> | ||
</Menu> | ||
); | ||
} |
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
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
Oops, something went wrong.