Commit 3bf039a0 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Convert `AnnotationActionBar` to TS

parent 2c4c0786
...@@ -8,6 +8,9 @@ import { ...@@ -8,6 +8,9 @@ import {
} from '@hypothesis/frontend-shared/lib/next'; } from '@hypothesis/frontend-shared/lib/next';
import { confirm } from '../../../shared/prompts'; import { confirm } from '../../../shared/prompts';
import type { SavedAnnotation } from '../../../types/api';
import type { SidebarSettings } from '../../../types/config';
import { serviceConfig } from '../../config/service-config'; import { serviceConfig } from '../../config/service-config';
import { annotationRole } from '../../helpers/annotation-metadata'; import { annotationRole } from '../../helpers/annotation-metadata';
import { import {
...@@ -16,26 +19,13 @@ import { ...@@ -16,26 +19,13 @@ import {
} from '../../helpers/annotation-sharing'; } from '../../helpers/annotation-sharing';
import { isPrivate, permits } from '../../helpers/permissions'; import { isPrivate, permits } from '../../helpers/permissions';
import { withServices } from '../../service-context'; import { withServices } from '../../service-context';
import type { AnnotationsService } from '../../services/annotations';
import type { ToastMessengerService } from '../../services/toast-messenger';
import { useSidebarStore } from '../../store'; import { useSidebarStore } from '../../store';
import AnnotationShareControl from './AnnotationShareControl'; import AnnotationShareControl from './AnnotationShareControl';
/** function flaggingEnabled(settings: SidebarSettings) {
* @typedef {import("../../../types/api").SavedAnnotation} SavedAnnotation
* @typedef {import('../../../types/config').SidebarSettings} SidebarSettings
*/
/**
* @typedef AnnotationActionBarProps
* @prop {SavedAnnotation} annotation - The annotation in question
* @prop {() => void} onReply - Callbacks for when action buttons are clicked/tapped
* @prop {import('../../services/annotations').AnnotationsService} annotationsService
* @prop {SidebarSettings} settings
* @prop {import('../../services/toast-messenger').ToastMessengerService} toastMessenger
*/
/** @param {SidebarSettings} settings */
function flaggingEnabled(settings) {
const service = serviceConfig(settings); const service = serviceConfig(settings);
if (service?.allowFlagging === false) { if (service?.allowFlagging === false) {
return false; return false;
...@@ -43,6 +33,16 @@ function flaggingEnabled(settings) { ...@@ -43,6 +33,16 @@ function flaggingEnabled(settings) {
return true; return true;
} }
export type AnnotationActionBarProps = {
annotation: SavedAnnotation;
onReply: () => void;
// injected
annotationsService: AnnotationsService;
settings: SidebarSettings;
toastMessenger: ToastMessengerService;
};
/** /**
* A collection of buttons in the footer area of an annotation that take * A collection of buttons in the footer area of an annotation that take
* actions on the annotation. * actions on the annotation.
...@@ -55,15 +55,14 @@ function AnnotationActionBar({ ...@@ -55,15 +55,14 @@ function AnnotationActionBar({
onReply, onReply,
settings, settings,
toastMessenger, toastMessenger,
}) { }: AnnotationActionBarProps) {
const store = useSidebarStore(); const store = useSidebarStore();
const userProfile = store.profile(); const userProfile = store.profile();
const annotationGroup = store.getGroup(annotation.group); const annotationGroup = store.getGroup(annotation.group);
const isLoggedIn = store.isLoggedIn(); const isLoggedIn = store.isLoggedIn();
// Is the current user allowed to take the given `action` on this annotation? // Is the current user allowed to take the given `action` on this annotation?
/** @param {'update'|'delete'} action */ const userIsAuthorizedTo = (action: 'update' | 'delete') => {
const userIsAuthorizedTo = action => {
return permits(annotation.permissions, action, userProfile.userid); return permits(annotation.permissions, action, userProfile.userid);
}; };
......
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