Commit 6ed0156a authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate to TS remaining js files in sidebar/components module

parent 2c37c7e8
...@@ -3,16 +3,13 @@ import { useMemo } from 'preact/hooks'; ...@@ -3,16 +3,13 @@ import { useMemo } from 'preact/hooks';
import { username } from '../../helpers/account-id'; import { username } from '../../helpers/account-id';
import { annotationDisplayName } from '../../helpers/annotation-user'; import { annotationDisplayName } from '../../helpers/annotation-user';
import { useSidebarStore } from '../../store'; import { useSidebarStore } from '../../store';
import type { FilterOption } from '../../store/modules/filters';
/** @typedef {import('../../store/modules/filters').FilterOption} FilterOption */
/** /**
* Generate a list of users for filtering annotations; update when set of * Generate a list of users for filtering annotations; update when set of
* annotations or filter state changes meaningfully. * annotations or filter state changes meaningfully.
*
* @return {FilterOption[]}
*/ */
export function useUserFilterOptions() { export function useUserFilterOptions(): FilterOption[] {
const store = useSidebarStore(); const store = useSidebarStore();
const annotations = store.allAnnotations(); const annotations = store.allAnnotations();
const focusFilters = store.getFocusFilters(); const focusFilters = store.getFocusFilters();
...@@ -22,8 +19,7 @@ export function useUserFilterOptions() { ...@@ -22,8 +19,7 @@ export function useUserFilterOptions() {
return useMemo(() => { return useMemo(() => {
// Determine unique users (authors) in annotation collection // Determine unique users (authors) in annotation collection
/** @type {Record<string, string>} */ const users: Record<string, string> = {};
const users = {};
annotations.forEach(annotation => { annotations.forEach(annotation => {
const username_ = username(annotation.user); const username_ = username(annotation.user);
users[username_] = annotationDisplayName( users[username_] = annotationDisplayName(
......
import { useMemo } from 'preact/hooks'; import { useMemo } from 'preact/hooks';
import type { Thread } from '../../helpers/build-thread';
import { threadAnnotations } from '../../helpers/thread-annotations'; import { threadAnnotations } from '../../helpers/thread-annotations';
import type { ThreadState } from '../../helpers/thread-annotations';
import { useSidebarStore } from '../../store'; import { useSidebarStore } from '../../store';
/** @typedef {import('../../helpers/build-thread').Thread} Thread */
/** /**
* Gather together state relevant to building a root thread of annotations and * Gather together state relevant to building a root thread of annotations and
* replies and return an updated root thread when changes occur. * replies and return an updated root thread when changes occur.
*
* @return {Thread}
*/ */
export function useRootThread() { export function useRootThread(): Thread {
const store = useSidebarStore(); const store = useSidebarStore();
const annotations = store.allAnnotations(); const annotations = store.allAnnotations();
const query = store.filterQuery(); const query = store.filterQuery();
...@@ -19,8 +17,7 @@ export function useRootThread() { ...@@ -19,8 +17,7 @@ export function useRootThread() {
const selectionState = store.selectionState(); const selectionState = store.selectionState();
const filters = store.getFilterValues(); const filters = store.getFilterValues();
const threadState = useMemo(() => { const threadState = useMemo((): ThreadState => {
/** @type {Record<string,string>} */
return { return {
annotations, annotations,
route, route,
......
...@@ -7,7 +7,7 @@ import { shouldShowInTab } from './tabs'; ...@@ -7,7 +7,7 @@ import { shouldShowInTab } from './tabs';
import { sorters } from './thread-sorters'; import { sorters } from './thread-sorters';
import { filterAnnotations } from './view-filter'; import { filterAnnotations } from './view-filter';
type ThreadState = { export type ThreadState = {
annotations: Annotation[]; annotations: Annotation[];
route: string | null; route: string | null;
selection: { selection: {
......
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