Commit f8dd14fb authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Move type to shared module to avoid dependency from shared to sidebar store module

parent 184ff1ab
import { useCallback, useEffect, useState } from 'preact/hooks'; import { useCallback, useEffect, useState } from 'preact/hooks';
import BaseToastMessages from '../../shared/components/BaseToastMessages'; import BaseToastMessages from '../../shared/components/BaseToastMessages';
import type { ToastMessage } from '../../shared/components/BaseToastMessages';
import type { PortRPC } from '../../shared/messaging'; import type { PortRPC } from '../../shared/messaging';
import type { ToastMessage } from '../../sidebar/store/modules/toast-messages';
import type { import type {
HostToSidebarEvent, HostToSidebarEvent,
SidebarToHostEvent, SidebarToHostEvent,
......
...@@ -7,7 +7,14 @@ import { ...@@ -7,7 +7,14 @@ import {
} from '@hypothesis/frontend-shared/lib/next'; } from '@hypothesis/frontend-shared/lib/next';
import classnames from 'classnames'; import classnames from 'classnames';
import type { ToastMessage } from '../../sidebar/store/modules/toast-messages'; export type ToastMessage = {
type: 'error' | 'success' | 'notice';
id: string;
message: string;
moreInfoURL: string;
isDismissed: boolean;
visuallyHidden: boolean;
};
type ToastMessageItemProps = { type ToastMessageItemProps = {
message: ToastMessage; message: ToastMessage;
...@@ -18,9 +25,6 @@ type ToastMessageItemProps = { ...@@ -18,9 +25,6 @@ type ToastMessageItemProps = {
* An individual toast message: a brief and transient success or error message. * An individual toast message: a brief and transient success or error message.
* The message may be dismissed by clicking on it. `visuallyHidden` toast * The message may be dismissed by clicking on it. `visuallyHidden` toast
* messages will not be visible but are still available to screen readers. * messages will not be visible but are still available to screen readers.
*
* Otherwise, the `toastMessenger` service handles removing messages after a
* certain amount of time.
*/ */
function ToastMessageItem({ message, onDismiss }: ToastMessageItemProps) { function ToastMessageItem({ message, onDismiss }: ToastMessageItemProps) {
// Capitalize the message type for prepending; Don't prepend a message // Capitalize the message type for prepending; Don't prepend a message
...@@ -98,7 +102,7 @@ function ToastMessageItem({ message, onDismiss }: ToastMessageItemProps) { ...@@ -98,7 +102,7 @@ function ToastMessageItem({ message, onDismiss }: ToastMessageItemProps) {
); );
} }
export type ToastMessageProps = { export type BaseToastMessageProps = {
messages: ToastMessage[]; messages: ToastMessage[];
onMessageDismiss: (messageId: string) => void; onMessageDismiss: (messageId: string) => void;
}; };
...@@ -110,7 +114,7 @@ export type ToastMessageProps = { ...@@ -110,7 +114,7 @@ export type ToastMessageProps = {
export default function BaseToastMessages({ export default function BaseToastMessages({
messages, messages,
onMessageDismiss, onMessageDismiss,
}: ToastMessageProps) { }: BaseToastMessageProps) {
// The `ul` containing any toast messages is absolute-positioned and the full // The `ul` containing any toast messages is absolute-positioned and the full
// width of the viewport. Each toast message `li` has its position and width // width of the viewport. Each toast message `li` has its position and width
// constrained by `container` configuration in tailwind. // constrained by `container` configuration in tailwind.
......
...@@ -9,7 +9,7 @@ export type ToastMessageProps = { ...@@ -9,7 +9,7 @@ export type ToastMessageProps = {
}; };
/** /**
* A component designed to render toast messages handled by the sidebar store. * Component that renders the active toast messages from the sidebar store
*/ */
function ToastMessages({ toastMessenger }: ToastMessageProps) { function ToastMessages({ toastMessenger }: ToastMessageProps) {
const store = useSidebarStore(); const store = useSidebarStore();
......
...@@ -2,6 +2,7 @@ import debounce from 'lodash.debounce'; ...@@ -2,6 +2,7 @@ import debounce from 'lodash.debounce';
import type { DebouncedFunction } from 'lodash.debounce'; import type { DebouncedFunction } from 'lodash.debounce';
import shallowEqual from 'shallowequal'; import shallowEqual from 'shallowequal';
import type { ToastMessage } from '../../shared/components/BaseToastMessages';
import { ListenerCollection } from '../../shared/listener-collection'; import { ListenerCollection } from '../../shared/listener-collection';
import { import {
PortFinder, PortFinder,
...@@ -22,7 +23,6 @@ import { isReply, isPublic } from '../helpers/annotation-metadata'; ...@@ -22,7 +23,6 @@ import { isReply, isPublic } from '../helpers/annotation-metadata';
import { annotationMatchesSegment } from '../helpers/annotation-segment'; import { annotationMatchesSegment } from '../helpers/annotation-segment';
import type { SidebarStore } from '../store'; import type { SidebarStore } from '../store';
import type { Frame } from '../store/modules/frames'; import type { Frame } from '../store/modules/frames';
import type { ToastMessage } from '../store/modules/toast-messages';
import { watch } from '../util/watch'; import { watch } from '../util/watch';
import type { AnnotationsService } from './annotations'; import type { AnnotationsService } from './annotations';
import type { ToastMessengerService } from './toast-messenger'; import type { ToastMessengerService } from './toast-messenger';
......
import { createStoreModule, makeAction } from '../create-store'; import { createStoreModule, makeAction } from '../create-store';
/** /**
* @typedef ToastMessage * @typedef {import('../../../shared/components/BaseToastMessages').ToastMessage} ToastMessage
* @prop {('error'|'success'|'notice')} type
* @prop {string} id
* @prop {string} message
* @prop {string} moreInfoURL
* @prop {boolean} isDismissed
* @prop {boolean} visuallyHidden
*/ */
/** /**
......
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