From cc32eb0d682b2d7e856c4efdf2faa1d9a2c60caa Mon Sep 17 00:00:00 2001 From: sylenien Date: Tue, 4 Oct 2022 14:44:41 +0200 Subject: [PATCH] fix(ui): change notes sort and insertion --- frontend/app/components/Session/WebPlayer.js | 8 +- .../Session_/EventsBlock/EventGroupWrapper.js | 9 +-- .../Session_/EventsBlock/NoteEvent.tsx | 74 ++++++++----------- .../Player/Controls/components/CreateNote.tsx | 14 ++-- .../Player/Controls/components/ReadNote.tsx | 30 +++----- .../app/components/shared/Select/Select.tsx | 10 +-- .../components/Notes/NoteItem.tsx | 69 ++++++++--------- .../components/Notes/NoteList.tsx | 26 +++---- .../components/Notes/NoteTags.tsx | 8 +- frontend/app/mstore/notesStore.ts | 8 ++ frontend/app/services/NotesService.ts | 7 +- 11 files changed, 114 insertions(+), 149 deletions(-) diff --git a/frontend/app/components/Session/WebPlayer.js b/frontend/app/components/Session/WebPlayer.js index 026aa93ab..e9e32d057 100644 --- a/frontend/app/components/Session/WebPlayer.js +++ b/frontend/app/components/Session/WebPlayer.js @@ -111,13 +111,7 @@ function WebPlayer(props) { {showNoteModal ? ( m.id === noteItem?.userId)?.email || ''} - timestamp={noteItem?.timestamp} - tags={noteItem?.tags} - isPublic={noteItem?.isPublic} - message={noteItem?.message} - sessionId={noteItem?.sessionId} - date={noteItem?.createdAt} - noteId={noteItem?.noteId} + note={noteItem} onClose={onNoteClose} notFound={!noteItem} /> diff --git a/frontend/app/components/Session_/EventsBlock/EventGroupWrapper.js b/frontend/app/components/Session_/EventsBlock/EventGroupWrapper.js index 72ab7ea7d..b33191239 100644 --- a/frontend/app/components/Session_/EventsBlock/EventGroupWrapper.js +++ b/frontend/app/components/Session_/EventsBlock/EventGroupWrapper.js @@ -8,6 +8,7 @@ import Event from './Event' import stl from './eventGroupWrapper.module.css'; import NoteEvent from './NoteEvent'; import { setEditNoteTooltip } from 'Duck/sessions'; +import { Note } from 'App/services/NotesService'; // TODO: incapsulate toggler in LocationEvent @withToggle("showLoadInfo", "toggleLoadInfo") @@ -74,13 +75,7 @@ class EventGroupWrapper extends React.Component { {isNote ? ( m.id === event.userId)?.email || event.userId} - timestamp={event.timestamp} - tags={event.tags} - isPublic={event.isPublic} - message={event.message} - sessionId={event.sessionId} - date={event.createdAt} - noteId={event.noteId} + note={event} filterOutNote={filterOutNote} onEdit={this.props.setEditNoteTooltip} noEdit={this.props.currentUserId !== event.userId} diff --git a/frontend/app/components/Session_/EventsBlock/NoteEvent.tsx b/frontend/app/components/Session_/EventsBlock/NoteEvent.tsx index dc6251f5c..190b3e0a9 100644 --- a/frontend/app/components/Session_/EventsBlock/NoteEvent.tsx +++ b/frontend/app/components/Session_/EventsBlock/NoteEvent.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { Icon } from 'UI'; -import { tagProps, iTag } from 'App/services/NotesService'; +import { tagProps, iTag, Note } from 'App/services/NotesService'; import { formatTimeOrDate } from 'App/date'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; @@ -12,15 +12,9 @@ import { confirm } from 'UI'; import { filterOutNote as filterOutTimelineNote } from 'Player'; interface Props { - userEmail: number; - timestamp: number; - tags: iTag[]; - isPublic: boolean; - message: string; - sessionId: string; - date: string; - noteId: number; + note: Note; noEdit: boolean; + userEmail: string; filterOutNote: (id: number) => void; onEdit: (noteTooltipObj: Record) => void; } @@ -29,28 +23,28 @@ function NoteEvent(props: Props) { const { settingsStore, notesStore } = useStore(); const { timezone } = settingsStore.sessionSettings; - console.log(props.noEdit) + console.log(props.noEdit); const onEdit = () => { props.onEdit({ isVisible: true, isEdit: true, - time: props.timestamp, + time: props.note.timestamp, note: { - timestamp: props.timestamp, - tags: props.tags, - isPublic: props.isPublic, - message: props.message, - sessionId: props.sessionId, - noteId: props.noteId, + timestamp: props.note.timestamp, + tag: props.note.tag, + isPublic: props.note.isPublic, + message: props.note.message, + sessionId: props.note.sessionId, + noteId: props.note.noteId, }, }); }; const onCopy = () => { copy( - `${window.location.origin}/${window.location.pathname.split('/')[1]}${session(props.sessionId)}${ - props.timestamp > 0 ? '?jumpto=' + props.timestamp : '' - }` + `${window.location.origin}/${window.location.pathname.split('/')[1]}${session( + props.note.sessionId + )}${props.note.timestamp > 0 ? '?jumpto=' + props.note.timestamp : ''}` ); toast.success('Note URL copied to clipboard'); }; @@ -63,9 +57,9 @@ function NoteEvent(props: Props) { confirmation: `Are you sure you want to delete this note?`, }) ) { - notesStore.deleteNote(props.noteId).then((r) => { - props.filterOutNote(props.noteId); - filterOutTimelineNote(props.noteId); + notesStore.deleteNote(props.note.noteId).then((r) => { + props.filterOutNote(props.note.noteId); + filterOutTimelineNote(props.note.noteId); toast.success('Note deleted'); }); } @@ -87,35 +81,31 @@ function NoteEvent(props: Props) {
{props.userEmail}
- {formatTimeOrDate(props.date as unknown as number, timezone)} + {formatTimeOrDate(props.note.createdAt as unknown as number, timezone)}
-
{props.message}
+
{props.note.message}
- {props.tags.length ? ( -
- {props.tags.map((tag) => ( -
- {tag} -
- ))} + {props.note.tag ? ( +
+ {props.note.tag}
) : null} - {!props.isPublic ? null : ( + {!props.note.isPublic ? null : ( <> Team diff --git a/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx b/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx index 38df4dc34..5b21d2b4c 100644 --- a/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx +++ b/frontend/app/components/Session_/Player/Controls/components/CreateNote.tsx @@ -32,14 +32,14 @@ function CreateNote({ }: Props) { const [text, setText] = React.useState(''); const [isPublic, setPublic] = React.useState(false); - const [tags, setTags] = React.useState([]); + const [tag, setTag] = React.useState(); const [useTimestamp, setUseTs] = React.useState(true); const { notesStore } = useStore(); React.useEffect(() => { if (isEdit) { - setTags(editNote.tags); + setTag(editNote.tag); setText(editNote.message); setPublic(editNote.isPublic); if (editNote.timestamp > 0) { @@ -56,7 +56,7 @@ function CreateNote({ const onSubmit = () => { const note: WriteNote = { message: text, - tags, + tag, timestamp: useTimestamp ? (isEdit ? editNote.timestamp : time) : -1, isPublic, }; @@ -76,7 +76,7 @@ function CreateNote({ .finally(() => { setCreateNoteTooltip({ isVisible: false, time: 0 }); setText(''); - setTags([]); + setTag(undefined); }); } @@ -96,7 +96,7 @@ function CreateNote({ .finally(() => { setCreateNoteTooltip({ isVisible: false, time: 0 }); setText(''); - setTags([]); + setTag(undefined); }); }; @@ -104,10 +104,10 @@ function CreateNote({ setCreateNoteTooltip({ isVisible: false, time: 0 }); }; - const tagActive = (tag: iTag) => tags.includes(tag); + const tagActive = (noteTag: iTag) => tag === noteTag; const addTag = (tag: iTag) => { - setTags([tag]); + setTag(tag); }; return ( diff --git a/frontend/app/components/Session_/Player/Controls/components/ReadNote.tsx b/frontend/app/components/Session_/Player/Controls/components/ReadNote.tsx index db497e866..a85ca8af1 100644 --- a/frontend/app/components/Session_/Player/Controls/components/ReadNote.tsx +++ b/frontend/app/components/Session_/Player/Controls/components/ReadNote.tsx @@ -1,21 +1,15 @@ import React from 'react'; import { Icon } from 'UI'; -import { tagProps, iTag } from 'App/services/NotesService'; +import { tagProps, Note } from 'App/services/NotesService'; import { formatTimeOrDate } from 'App/date'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; interface Props { - userEmail: number; - timestamp: number; - tags: iTag[]; - isPublic: boolean; - message: string; - sessionId: string; - date: string; - noteId: number; - onClose: () => void; + userEmail: string; + note: Note; notFound?: boolean; + onClose: () => void; } function ReadNote(props: Props) { @@ -60,29 +54,25 @@ function ReadNote(props: Props) {
{props.userEmail}
- {formatTimeOrDate(props.date as unknown as number, timezone)} + {formatTimeOrDate(props.note.createdAt as unknown as number, timezone)}
-
{props.message}
+
{props.note.message}
- {props.tags.length ? ( -
- {props.tags.map((tag) => ( + {props.note.tag ? (
- {tag} + {props.note.tag}
- ))} -
) : null} - {!props.isPublic ? null : ( + {!props.note.isPublic ? null : ( <> Team diff --git a/frontend/app/components/shared/Select/Select.tsx b/frontend/app/components/shared/Select/Select.tsx index 3ef9383ca..285488e78 100644 --- a/frontend/app/components/shared/Select/Select.tsx +++ b/frontend/app/components/shared/Select/Select.tsx @@ -12,7 +12,7 @@ type ValueObject = { interface Props { options: Value[]; isSearchable?: boolean; - defaultValue?: string; + defaultValue?: string | number; plain?: boolean; components?: any; styles?: any; @@ -103,7 +103,7 @@ export default function({ placeholder='Select', name singleValue: (provided: any, state: { isDisabled: any; }) => { const opacity = state.isDisabled ? 0.5 : 1; const transition = 'opacity 300ms'; - + return { ...provided, opacity, transition, fontWeight: '500' }; }, input: (provided: any) => ({ @@ -160,13 +160,13 @@ const DropdownIndicator = ( const CustomValueContainer = ({ children, ...rest }: any) => { const selectedCount = rest.getValue().length const conditional = (selectedCount < 3) - + let firstChild: any = [] - + if (!conditional) { firstChild = [children[0].shift(), children[1]] } - + return ( {conditional ? children : firstChild} diff --git a/frontend/app/components/shared/SessionListContainer/components/Notes/NoteItem.tsx b/frontend/app/components/shared/SessionListContainer/components/Notes/NoteItem.tsx index 0cada8d87..c3e7cc103 100644 --- a/frontend/app/components/shared/SessionListContainer/components/Notes/NoteItem.tsx +++ b/frontend/app/components/shared/SessionListContainer/components/Notes/NoteItem.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Icon, Link } from 'UI'; import PlayLink from 'Shared/SessionItem/PlayLink'; -import { tagProps, iTag } from 'App/services/NotesService'; +import { tagProps, Note } from 'App/services/NotesService'; import { formatTimeOrDate } from 'App/date'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; @@ -11,14 +11,7 @@ import { toast } from 'react-toastify'; import { session } from 'App/routes'; interface Props { - userId: number; - timestamp: number; - tags: iTag[]; - isPublic: boolean; - description: string; - sessionId: string; - date: string; - noteId: number; + note: Note; userEmail: string; } @@ -29,13 +22,13 @@ function NoteItem(props: Props) { const onCopy = () => { copy( `${window.location.origin}/${window.location.pathname.split('/')[1]}${session( - props.sessionId - )}${props.timestamp > 0 ? '?jumpto=' + props.timestamp : ''}` + props.note.sessionId + )}${props.note.timestamp > 0 ? '?jumpto=' + props.note.timestamp : ''}` ); toast.success('Note URL copied to clipboard'); }; const onDelete = () => { - notesStore.deleteNote(props.noteId).then((r) => { + notesStore.deleteNote(props.note.noteId).then((r) => { notesStore.fetchNotes(); toast.success('Note deleted'); }); @@ -49,32 +42,36 @@ function NoteItem(props: Props) { className="flex items-center p-4 border-b" style={{ background: 'rgba(253, 243, 155, 0.1)' }} > - 0 ? `?jumpto=${props.timestamp}¬e=${props.noteId}` : '')}> + 0 + ? `?jumpto=${props.note.timestamp}¬e=${props.note.noteId}` + : '') + } + >
-
{props.description}
+
{props.note.message}
- {props.tags.length ? ( -
- {props.tags.map((tag) => ( -
- {tag} -
- ))} + {props.note.tag ? ( +
+ {props.note.tag}
) : null}
By - {props.userEmail}, {formatTimeOrDate(props.date as unknown as number, timezone)} - {!props.isPublic ? null : ( + {props.userEmail},{' '} + {formatTimeOrDate(props.note.createdAt as unknown as number, timezone)} + {!props.note.isPublic ? null : ( <> Team @@ -84,13 +81,7 @@ function NoteItem(props: Props) {
- +
diff --git a/frontend/app/components/shared/SessionListContainer/components/Notes/NoteList.tsx b/frontend/app/components/shared/SessionListContainer/components/Notes/NoteList.tsx index 33609bea6..f5650117f 100644 --- a/frontend/app/components/shared/SessionListContainer/components/Notes/NoteList.tsx +++ b/frontend/app/components/shared/SessionListContainer/components/Notes/NoteList.tsx @@ -5,16 +5,16 @@ import NoteItem from './NoteItem'; import { observer } from 'mobx-react-lite'; import { useStore } from 'App/mstore'; -function NotesList({ members }: {members: Array>}) { - const { notesStore } = useStore() +function NotesList({ members }: { members: Array> }) { + const { notesStore } = useStore(); React.useEffect(() => { if (!notesStore.notes.length) { - notesStore.fetchNotes() + notesStore.fetchNotes(); } - }, []) + }, []); - const list = notesStore.notes + const list = notesStore.notes; return ( @@ -28,18 +28,11 @@ function NotesList({ members }: {members: Array>}) { } >
- {sliceListPerPage(list, notesStore.page - 1, notesStore.pageSize).map(note => ( + {sliceListPerPage(list, notesStore.page - 1, notesStore.pageSize).map((note) => ( m.id === note.userId)?.email || note.userId} + note={note} + userEmail={members.find((m) => m.id === note.userId)?.email || note.userId} /> ))} @@ -47,7 +40,8 @@ function NotesList({ members }: {members: Array>}) {
- Showing {Math.min(list.length, notesStore.pageSize)} out + Showing{' '} + {Math.min(list.length, notesStore.pageSize)} out of {list.length} notes
({ value, label })); - +const notesOwner = [{ value: '0', label: 'All Notes'},{ value: '1', label: 'My Notes'}] function NoteTags() { const { notesStore } = useStore() - const defaultOption = sortOptions[0].value; + return (
@@ -34,7 +34,9 @@ function NoteTags() {
))}
- notesStore.toggleSort(value.value)} defaultValue={sortOptions[0].value} /> +
+