import React from 'react'; import { observer } from 'mobx-react-lite'; import { iTag } from 'App/services/NotesService'; import { useStore } from 'App/mstore'; import { numberWithCommas } from 'App/utils'; import { Pagination, NoContent, Loader } from 'UI'; import cn from 'classnames'; import { withSiteId, highlights } from "App/routes"; import HighlightClip from './HighlightClip'; import { useQuery } from '@tanstack/react-query'; import HighlightPlayer from "./HighlightPlayer"; import { useLocation, useHistory } from 'react-router-dom'; import { toast } from 'react-toastify'; import EditHlModal from "./EditHlModal"; import HighlightsListHeader from './HighlightsListHeader' function HighlightsList() { const { notesStore, projectsStore } = useStore(); const hist = useHistory(); const [editModalOpen, setEditModalOpen] = React.useState(false); const [editHl, setEditHl] = React.useState>({ message: '', isPublic: false, }); const { search } = useLocation(); const highlight = new URLSearchParams(search).get('highlight'); const query = notesStore.query; const limit = notesStore.pageSize; const listLength = notesStore.notes.length; const activeTags = notesStore.activeTags; const page = notesStore.page; const ownOnly = notesStore.ownOnly const { data = { notes: [], total: 0 }, isPending, refetch, } = useQuery({ queryKey: ['notes', page, query, activeTags], queryFn: () => notesStore.fetchNotes(), retry: 3, }); const { total, notes } = data; const onSearch = (value: string) => { notesStore.setQuery(value); }; const handleInputChange = (e: React.ChangeEvent) => { notesStore.setQuery(e.target.value); }; const toggleTag = (tag?: iTag) => { notesStore.toggleTag(tag) }; const onPageChange = (page: number) => { notesStore.changePage(page); }; const onDelete = async (id: number) => { await notesStore.deleteNote(id); refetch(); toast.success('Highlight deleted successfully'); }; const onItemClick = (id: string) => { hist.replace(`?highlight=${id}`); } const onClose = () => { hist.replace(withSiteId(highlights(), projectsStore.active?.id)); } const onEdit = (id: string) => { const hl = notesStore.getNoteById(id); if (!hl) { return toast.error('Highlight not found in the list'); } setEditHl(hl); setEditModalOpen(true) } const onSave = async (noteText: string, visible: boolean) => { if (!editHl) { return; } const newNote = { ...editHl, message: noteText, isPublic: visible, } try { await notesStore.updateNote(editHl.noteId, newNote); toast.success('Highlight updated successfully'); } catch (e) { console.error(e); toast.error('Error updating highlight'); } setEditModalOpen(false); } const toggleShared = (val: boolean) => { notesStore.toggleShared(val); refetch(); } const isEmpty = !isPending && total === 0; return (
{highlight && }
Highlight and note observations during session replays and share them with your team.
} > {notes.map((note) => ( onEdit(note.noteId)} onDelete={() => onDelete(note.noteId)} onItemClick={() => onItemClick(note.noteId)} /> ))} setEditModalOpen(false)} text={editHl?.message} visible={editHl?.isPublic} onSave={onSave} />
Showing {(page - 1) * limit + 1} {' to '} {(page - 1) * limit + listLength} {' of '} {numberWithCommas(total)} {' highlights'}.
); } export default observer(HighlightsList);