Commit 54782fc1 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate thread-annotations to TypeScript

parent 082de109
import type { Annotation } from '../../types/api';
import { memoize } from '../util/memoize'; import { memoize } from '../util/memoize';
import { generateFacetedFilter } from '../util/search-filter'; import { generateFacetedFilter } from '../util/search-filter';
import { buildThread } from './build-thread'; import { buildThread } from './build-thread';
import type { Thread, BuildThreadOptions } from './build-thread';
import { shouldShowInTab } from './tabs'; import { shouldShowInTab } from './tabs';
import { sorters } from './thread-sorters'; import { sorters } from './thread-sorters';
import { filterAnnotations } from './view-filter'; import { filterAnnotations } from './view-filter';
/** @typedef {import('../../types/api').Annotation} Annotation */ type ThreadState = {
/** @typedef {import('./build-thread').Thread} Thread */ annotations: Annotation[];
/** @typedef {import('./build-thread').BuildThreadOptions} BuildThreadOptions */ route: string | null;
selection: {
/** expanded: Record<string, boolean>;
* @typedef ThreadState filterQuery: string | null;
* @prop {Annotation[]} annotations filters: Record<string, string>;
* @prop {object} selection forcedVisible: string[];
* @prop {Record<string,boolean>} selection.expanded selected: string[];
* @prop {string|null} selection.filterQuery sortKey: keyof typeof sorters;
* @prop {Record<string,string>} selection.filters selectedTab: 'annotation' | 'note' | 'orphan';
* @prop {string[]} selection.forcedVisible };
* @prop {string[]} selection.selected };
* @prop {keyof sorters} selection.sortKey
* @prop {'annotation'|'note'|'orphan'} selection.selectedTab
* @prop {string|null} route
*/
/** /**
* Cobble together the right set of options and filters based on current * Cobble together the right set of options and filters based on current
* `threadState` to build the root thread. * `threadState` to build the root thread.
*
* @param {ThreadState} threadState
* @return {Thread}
*/ */
function buildRootThread(threadState) { function buildRootThread(threadState: ThreadState): Thread {
const selection = threadState.selection; const selection = threadState.selection;
const options: BuildThreadOptions = {
/** @type {BuildThreadOptions} */
const options = {
expanded: selection.expanded, expanded: selection.expanded,
forcedVisible: selection.forcedVisible, forcedVisible: selection.forcedVisible,
selected: selection.selected, selected: selection.selected,
......
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