added keys and types to the note api for adding and loading notes and chats
This commit is contained in:
parent
a2ac900f3e
commit
63bba4f74e
11 changed files with 49 additions and 31 deletions
|
|
@ -21,13 +21,14 @@ const useStyles = makeStyles((_theme: Theme) => {
|
|||
})
|
||||
|
||||
interface Props {
|
||||
objectKey: string;
|
||||
parent: string;
|
||||
parentType: string;
|
||||
type?: pond.NoteType;
|
||||
}
|
||||
|
||||
export default function Chat(props: Props) {
|
||||
const [chats, setChats] = useState<pond.Chat[]>([]);
|
||||
const { objectKey, type } = props;
|
||||
const { parent, parentType, type } = props;
|
||||
const noteAPI = useNoteAPI();
|
||||
const [loaded, setLoaded] = useState<boolean>(false);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
|
@ -38,7 +39,7 @@ export default function Chat(props: Props) {
|
|||
const loadChats = () => {
|
||||
setLoading(true)
|
||||
// console.log("listing chats?")
|
||||
noteAPI.listChats(10, chats.length, "desc", "timestamp", objectKey).then(resp => {
|
||||
noteAPI.listChats(10, chats.length, "desc", "timestamp", parent, [parent], [parentType]).then(resp => {
|
||||
setChats(resp.data.chats ? resp.data.chats.reverse().concat(chats) : [])
|
||||
setTotalMessages(resp.data.total)
|
||||
}).finally(() => {
|
||||
|
|
@ -81,13 +82,13 @@ export default function Chat(props: Props) {
|
|||
setLoaded(false);
|
||||
setLoading(false);
|
||||
setTotalMessages(0);
|
||||
}, [objectKey]);
|
||||
}, [parent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (chats.length === 0 && !loaded) {
|
||||
loadChats();
|
||||
}
|
||||
}, [objectKey, chats, loaded]);
|
||||
}, [parent, chats, loaded]);
|
||||
|
||||
const loadMore = () => {
|
||||
loadChats();
|
||||
|
|
@ -111,7 +112,7 @@ export default function Chat(props: Props) {
|
|||
</Box>
|
||||
<Box style={{ flexShrink: 0 }}>
|
||||
<Divider />
|
||||
<ChatInput newNoteMethod={showNewNotes} objectKey={objectKey} type={type} />
|
||||
<ChatInput newNoteMethod={showNewNotes} parent={parent} type={type} parentType={parentType} />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ export function ChatDrawer(props: Props) {
|
|||
<Typography>{selectedTeam.name()} Chat</Typography>
|
||||
</Box>
|
||||
<Box className={classes.chatContainer}>
|
||||
<Chat objectKey={selectedTeam.key()} type={pond.NoteType.NOTE_TYPE_TEAM} />
|
||||
<Chat parent={selectedTeam.key()} parentType={"team"} type={pond.NoteType.NOTE_TYPE_TEAM} />
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||
}))
|
||||
|
||||
interface Props {
|
||||
objectKey: string;
|
||||
parent: string;
|
||||
newNoteMethod: (note: Note) => void;
|
||||
parentType: string; // the object type the note is for ie "bin", "team" etc.
|
||||
type?: pond.NoteType;
|
||||
}
|
||||
|
||||
|
|
@ -52,13 +53,13 @@ interface Props {
|
|||
export default function ChatInput(props: Props) {
|
||||
const [message, setMessage] = useState("");
|
||||
const classes = useStyles();
|
||||
const { objectKey, type } = props;
|
||||
const { parent, type, parentType } = props;
|
||||
const [{ user }] = useGlobalState();
|
||||
const noteAPI = useNoteAPI();
|
||||
const { openSnack } = useSnackbar();
|
||||
const [shift, setShift] = useState(false);
|
||||
const theme = useTheme();
|
||||
const [uploadedFiles, setUploadedFiles] = useState<Map<string, string>>(new Map());
|
||||
// const [uploadedFiles, setUploadedFiles] = useState<Map<string, string>>(new Map());
|
||||
|
||||
const clearEntry = () => {
|
||||
setMessage("");
|
||||
|
|
@ -93,13 +94,13 @@ export default function ChatInput(props: Props) {
|
|||
}
|
||||
valid ? submit() : openSnack("Invalid Message");
|
||||
clearEntry();
|
||||
setUploadedFiles(new Map());
|
||||
// setUploadedFiles(new Map());
|
||||
};
|
||||
|
||||
const submit = () => {
|
||||
if (message !== "" && message !== "\n") {
|
||||
let newNote = Note.create();
|
||||
newNote.settings.objectKey = objectKey;
|
||||
newNote.settings.objectKey = parent;
|
||||
newNote.settings.userId = user.id();
|
||||
if (type) {
|
||||
newNote.settings.objectType = type;
|
||||
|
|
@ -107,13 +108,14 @@ export default function ChatInput(props: Props) {
|
|||
newNote.settings.timestamp = Date.now();
|
||||
newNote.settings.content = message;
|
||||
noteAPI
|
||||
.addNote(newNote.settings, Array.from(uploadedFiles.keys()))
|
||||
.addNote(newNote.settings, undefined, [parent], [parentType])
|
||||
.then(resp => {
|
||||
newNote.settings.key = resp.data.note
|
||||
props.newNoteMethod(newNote);
|
||||
openSnack("Message Sent");
|
||||
})
|
||||
.catch(_err => {
|
||||
console.error(_err)
|
||||
openSnack("Message Failed to send");
|
||||
});
|
||||
}
|
||||
|
|
@ -162,7 +164,7 @@ export default function ChatInput(props: Props) {
|
|||
</Box>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Typography>{Array.from(uploadedFiles.values()).toString()}</Typography>
|
||||
{/* <Typography>{Array.from(uploadedFiles.values()).toString()}</Typography> */}
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue