Commit 6ad2f0d0 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Convert `NotebookView` to TS

parent 9133aeb5
...@@ -4,6 +4,8 @@ import scrollIntoView from 'scroll-into-view'; ...@@ -4,6 +4,8 @@ import scrollIntoView from 'scroll-into-view';
import { ResultSizeError } from '../search-client'; import { ResultSizeError } from '../search-client';
import { withServices } from '../service-context'; import { withServices } from '../service-context';
import type { LoadAnnotationsService } from '../services/load-annotations';
import type { StreamerService } from '../services/streamer';
import { useSidebarStore } from '../store'; import { useSidebarStore } from '../store';
import NotebookFilters from './NotebookFilters'; import NotebookFilters from './NotebookFilters';
...@@ -11,18 +13,17 @@ import NotebookResultCount from './NotebookResultCount'; ...@@ -11,18 +13,17 @@ import NotebookResultCount from './NotebookResultCount';
import PaginatedThreadList from './PaginatedThreadList'; import PaginatedThreadList from './PaginatedThreadList';
import { useRootThread } from './hooks/use-root-thread'; import { useRootThread } from './hooks/use-root-thread';
/** export type NotebookViewProps = {
* @typedef NotebookViewProps // injected
* @prop {import('../services/load-annotations').LoadAnnotationsService} loadAnnotationsService loadAnnotationsService: LoadAnnotationsService;
* @prop {import('../services/streamer').StreamerService} streamer streamer: StreamerService;
*/ };
/** /**
* The main content of the "notebook" route (https://hypothes.is/notebook) * The main content of the "notebook" route (https://hypothes.is/notebook)
* *
* @param {NotebookViewProps} props * @param {NotebookViewProps} props
*/ */
function NotebookView({ loadAnnotationsService, streamer }) { function NotebookView({ loadAnnotationsService, streamer }: NotebookViewProps) {
const store = useSidebarStore(); const store = useSidebarStore();
const filters = store.getFilterValues(); const filters = store.getFilterValues();
...@@ -56,8 +57,7 @@ function NotebookView({ loadAnnotationsService, streamer }) { ...@@ -56,8 +57,7 @@ function NotebookView({ loadAnnotationsService, streamer }) {
// of them: this is a performance safety valve. // of them: this is a performance safety valve.
const maxResults = 5000; const maxResults = 5000;
/** @param {Error} error */ const onLoadError = (error: Error) => {
const onLoadError = error => {
if (error instanceof ResultSizeError) { if (error instanceof ResultSizeError) {
setHasTooManyAnnotationsError(true); setHasTooManyAnnotationsError(true);
} }
...@@ -102,8 +102,7 @@ function NotebookView({ loadAnnotationsService, streamer }) { ...@@ -102,8 +102,7 @@ function NotebookView({ loadAnnotationsService, streamer }) {
} }
}, [loadAnnotationsService, groupId, store]); }, [loadAnnotationsService, groupId, store]);
/** @param {number} newPage */ const onChangePage = (newPage: number) => {
const onChangePage = newPage => {
setPaginationPage(newPage); setPaginationPage(newPage);
}; };
...@@ -113,7 +112,7 @@ function NotebookView({ loadAnnotationsService, streamer }) { ...@@ -113,7 +112,7 @@ function NotebookView({ loadAnnotationsService, streamer }) {
}, [filters, focusedGroup]); }, [filters, focusedGroup]);
// Scroll back to here when pagination page changes // Scroll back to here when pagination page changes
const threadListScrollTop = useRef(/** @type {HTMLElement|null}*/ (null)); const threadListScrollTop = useRef<HTMLElement | null>(null);
useLayoutEffect(() => { useLayoutEffect(() => {
// TODO: Transition and effects here should be improved // TODO: Transition and effects here should be improved
if (paginationPage !== lastPaginationPage.current) { if (paginationPage !== lastPaginationPage.current) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment