Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule help panel auto-dismiss when automatically opened #6289

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/sidebar/components/HypothesisApp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { confirm } from '@hypothesis/frontend-shared';
import classnames from 'classnames';
import { useEffect, useMemo } from 'preact/hooks';
import { useEffect, useMemo, useRef } from 'preact/hooks';

import type { SidebarSettings } from '../../types/config';
import { serviceConfig } from '../config/service-config';
Expand Down Expand Up @@ -47,8 +47,15 @@ function HypothesisApp({
}: HypothesisAppProps) {
const store = useSidebarStore();
const profile = store.profile();
const currentUser = profile.userid;
const route = store.route();
const isModalRoute = route === 'notebook' || route === 'profile';
const allAnnotations = store.savedAnnotations();
const currentUserHasAnnotations = useMemo(
() => allAnnotations.filter(ann => ann.user === currentUser).length > 0,
[allAnnotations, currentUser],
);
const timer = useRef<number>();

const backgroundStyle = useMemo(
() => applyTheme(['appBackgroundColor'], settings),
Expand All @@ -64,6 +71,22 @@ function HypothesisApp({
}
}, [isSidebar, profile, settings, store]);

// As soon as the user interacts with the page creating annotations, if the
// help panel was auto-displayed, schedule a task that will close it after 5
// minutes
useEffect(() => {
if (
shouldAutoDisplayTutorial(isSidebar, profile, settings) &&
currentUserHasAnnotations &&
!timer.current
) {
timer.current = setTimeout(() => {
store.closeSidebarPanel('help');
session.dismissSidebarTutorial();
}, 5 /** 60*/ * 1000);
}
}, [currentUserHasAnnotations, isSidebar, profile, session, settings, store]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking maybe this logic should be moved to the HelpPanel itself.

In there we are also handling that the show_sidebar_tutorial profile preference is disabled if the panel is manually closed.

When that happens, we should also clear the timeout if it is still in progress.


const isThirdParty = isThirdPartyService(settings);

const login = async () => {
Expand Down
Loading