-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
1 parent
0b6dd1a
commit ea477bf
Showing
10 changed files
with
227 additions
and
54 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,15 @@ | ||
/** | ||
* Player-written medical note. | ||
*/ | ||
/datum/medical_note | ||
/// Player that wrote the note | ||
var/author | ||
/// Details of the note | ||
var/content | ||
/// Station timestamp | ||
var/time | ||
|
||
/datum/medical_note/New(author = "Anonymous", content = "No details provided.") | ||
src.author = author | ||
src.content = content | ||
src.time = station_time_timestamp() |
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
129 changes: 129 additions & 0 deletions
129
tgui/packages/tgui/interfaces/MedicalRecords/NoteKeeper.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,129 @@ | ||
import { useBackend, useLocalState } from 'tgui/backend'; | ||
import { | ||
BlockQuote, | ||
Box, | ||
Button, | ||
Icon, | ||
LabeledList, | ||
Section, | ||
Tabs, | ||
TextArea, | ||
Tooltip, | ||
} from 'tgui/components'; | ||
|
||
import { getMedicalRecord } from './helpers'; | ||
import { MedicalNote, MedicalRecordData } from './types'; | ||
|
||
/** Small section for adding notes. Passes a ref and note to Byond. */ | ||
export const NoteKeeper = (props, context) => { | ||
const foundRecord = getMedicalRecord(props, context); | ||
if (!foundRecord) return <> </>; | ||
|
||
const { act } = useBackend<MedicalRecordData>(context); | ||
const { record_ref } = foundRecord; | ||
|
||
const [selectedNote, setSelectedNote] = useLocalState< | ||
MedicalNote | undefined | ||
>(context, 'selectedNote', undefined); | ||
|
||
const [writing, setWriting] = useLocalState(context, 'note', false); | ||
|
||
const addNote = (event, value: string) => { | ||
act('add_note', { | ||
record_ref: record_ref, | ||
content: value, | ||
}); | ||
setWriting(false); | ||
}; | ||
|
||
const deleteNote = () => { | ||
if (!selectedNote) return; | ||
act('delete_note', { | ||
record_ref: record_ref, | ||
note_ref: selectedNote.note_ref, | ||
}); | ||
setSelectedNote(undefined); | ||
}; | ||
|
||
return ( | ||
<Section buttons={<NoteTabs />} fill scrollable title="Notes"> | ||
{writing && ( | ||
<TextArea | ||
height="100%" | ||
maxLength={1024} | ||
onEnter={addNote} | ||
onEscape={() => setWriting(false)} | ||
/> | ||
)} | ||
|
||
{!!selectedNote && ( | ||
<> | ||
<LabeledList> | ||
<LabeledList.Item | ||
label="Author" | ||
buttons={<Button color="bad" icon="trash" onClick={deleteNote} />} | ||
> | ||
{selectedNote.author} | ||
</LabeledList.Item> | ||
<LabeledList.Item label="Time"> | ||
{selectedNote.time} | ||
</LabeledList.Item> | ||
</LabeledList> | ||
<Box color="label" mb={1} mt={1}> | ||
Content: | ||
</Box> | ||
<BlockQuote>{selectedNote.content}</BlockQuote> | ||
</> | ||
)} | ||
</Section> | ||
); | ||
}; | ||
|
||
/** Displays the notes with an add tab next to. */ | ||
const NoteTabs = (props, context) => { | ||
const foundRecord = getMedicalRecord(props, context); | ||
if (!foundRecord) return <> </>; | ||
const { notes } = foundRecord; | ||
|
||
const [selectedNote, setSelectedNote] = useLocalState< | ||
MedicalNote | undefined | ||
>(context, 'selectedNote', undefined); | ||
const [writing, setWriting] = useLocalState(context, 'note', false); | ||
|
||
/** Selects or deselects a note. */ | ||
const setNote = (note: MedicalNote) => { | ||
if (selectedNote?.note_ref === note.note_ref) { | ||
setSelectedNote(undefined); | ||
} else { | ||
setSelectedNote(note); | ||
} | ||
}; | ||
|
||
/** Sets the note to writing mode. */ | ||
const composeNew = () => { | ||
setWriting(true); | ||
setSelectedNote(undefined); | ||
}; | ||
|
||
return ( | ||
<Tabs> | ||
{notes.map((note, index) => ( | ||
<Tabs.Tab | ||
key={index} | ||
onClick={() => setNote(note)} | ||
selected={selectedNote?.note_ref === note.note_ref} | ||
> | ||
{index + 1} | ||
</Tabs.Tab> | ||
))} | ||
<Tooltip | ||
content={`Add a new note. Press enter or escape to exit view.`} | ||
position="bottom" | ||
> | ||
<Tabs.Tab onClick={composeNew} selected={writing}> | ||
<Icon name="plus" /> New | ||
</Tabs.Tab> | ||
</Tooltip> | ||
</Tabs> | ||
); | ||
}; |
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.