-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,227 additions
and
90 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
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,148 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { Card, Form, Header, Icon, Modal, Segment } from 'semantic-ui-react'; | ||
|
||
import { ItemActions } from '../client/actions/item'; | ||
import t from '../client/lang'; | ||
import { ItemType } from '../shared/enums'; | ||
import { ServerNote } from '../shared/types'; | ||
import { Markdown } from './misc'; | ||
import { ModalWithBack } from './misc/BackSupport'; | ||
import MarkdownEditor from './misc/MarkdownEditor'; | ||
|
||
export function NoteForm({ | ||
data, | ||
onData, | ||
}: { | ||
data?: Partial<ServerNote>; | ||
onData?: (data: Partial<ServerNote>) => void; | ||
}) { | ||
const [formData, setFormData] = useState<Partial<ServerNote>>(data ?? {}); | ||
|
||
const onSubmit = useCallback( | ||
(e) => { | ||
e.preventDefault(); | ||
onData?.(formData); | ||
}, | ||
[formData] | ||
); | ||
|
||
return ( | ||
<Segment basic> | ||
<Header>{data ? t`Edit note` : t`Create new note`}</Header> | ||
<Form onSubmit={onSubmit}> | ||
<Form.Input | ||
fluid | ||
label={t`Title`} | ||
placeholder={t`Title`} | ||
value={formData?.title ?? ''} | ||
onChange={(e) => { | ||
setFormData({ ...formData, title: e.target.value }); | ||
}} | ||
/> | ||
<Form.Field> | ||
<label>{t`Content`}</label> | ||
<MarkdownEditor | ||
content={formData?.content ?? ''} | ||
onChange={(v) => { | ||
setFormData({ ...formData, content: v }); | ||
}} | ||
/> | ||
</Form.Field> | ||
<Form.Button primary type="submit"> | ||
Submit | ||
</Form.Button> | ||
</Form> | ||
</Segment> | ||
); | ||
} | ||
|
||
export default function Note({ | ||
data: initalData, | ||
onUpdated, | ||
}: { | ||
data?: Partial<ServerNote>; | ||
onUpdated?: (data: Partial<ServerNote>) => void; | ||
}) { | ||
const [open, setOpen] = useState(false); | ||
const [editOpen, setEditOpen] = useState(false); | ||
const [data, setData] = useState(initalData ?? {}); | ||
|
||
useEffect(() => { | ||
setData(initalData ?? {}); | ||
}, [initalData]); | ||
|
||
let content = data?.content ?? ''; | ||
|
||
if (content.length > 100) { | ||
// cut off at 200 characters and add ellipsis | ||
content = content.slice(0, 200) + '...'; | ||
} | ||
|
||
return ( | ||
<> | ||
<ModalWithBack | ||
closeIcon | ||
open={open} | ||
onOpen={() => setOpen(true)} | ||
onClose={() => setOpen(false)}> | ||
<Modal.Header>{data?.title}</Modal.Header> | ||
<Modal.Content> | ||
<Markdown>{data?.content}</Markdown> | ||
</Modal.Content> | ||
</ModalWithBack> | ||
<ModalWithBack | ||
open={editOpen} | ||
onOpen={() => setEditOpen(true)} | ||
onClose={() => setEditOpen(false)} | ||
closeIcon | ||
content={ | ||
<NoteForm | ||
data={data} | ||
onData={(v) => { | ||
ItemActions.updateItem(data?.id, v, { | ||
item_type: ItemType.Note, | ||
item: v, | ||
}).then(() => onUpdated?.(v)); | ||
setEditOpen(false); | ||
}} | ||
/> | ||
} | ||
/> | ||
<Card | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setOpen(true); | ||
}}> | ||
<Card.Content> | ||
<Card.Header> | ||
{data?.title} | ||
<Icon | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
setEditOpen(true); | ||
}} | ||
name="pencil" | ||
link | ||
size="small" | ||
className="float-right" | ||
/> | ||
</Card.Header> | ||
{/* <Card.Meta>Friends of Elliot</Card.Meta> */} | ||
<Card.Description> | ||
<span | ||
style={{ | ||
whiteSpace: 'pre-wrap', | ||
}}> | ||
{content} | ||
</span> | ||
</Card.Description> | ||
</Card.Content> | ||
</Card> | ||
</> | ||
); | ||
} | ||
|
||
export function NoteGroup(props: React.ComponentProps<typeof Card.Group>) { | ||
return <Card.Group {...props} />; | ||
} |
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,30 @@ | ||
.editor { | ||
margin: 0; | ||
-webkit-appearance: none; | ||
-webkit-tap-highlight-color: rgba(255, 255, 255, 0); | ||
padding: 0.91666667em 1.16666667em; | ||
background: #FFFFFF; | ||
border: 1px solid rgba(34, 36, 38, 0.15); | ||
border-top-color: rgba(34, 36, 38, 0.15); | ||
border-right-color: rgba(34, 36, 38, 0.15); | ||
border-bottom-color: rgba(34, 36, 38, 0.15); | ||
border-left-color: rgba(34, 36, 38, 0.15); | ||
outline: none; | ||
color: #212121; | ||
border-radius: 4px; | ||
box-shadow: 0 0 0 0 transparent inset; | ||
transition: color 0.1s ease, border-color 0.1s ease; | ||
font-size: 1em; | ||
line-height: 1.2857; | ||
resize: vertical; | ||
min-height: 6em; | ||
} | ||
|
||
.editor p.is_editor_empty:first-child::before { | ||
color: #adb5bd; | ||
content: attr(data-placeholder); | ||
float: left; | ||
height: 0; | ||
pointer-events: none; | ||
} | ||
|
Oops, something went wrong.