Skip to content

Convert history button to React #1053

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"react"
],
"parserOptions": {
"ecmaVersion": 11,
"ecmaVersion": 2024,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
Expand Down
1 change: 0 additions & 1 deletion extension/chrome_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"data/styles/old_queuetools.css",
"data/styles/achievements.css",
"data/styles/modbar.css",
"data/styles/historybutton.css",
"data/styles/notifier.css",
"data/styles/usernotes.css",
"data/styles/config.css",
Expand Down
9 changes: 9 additions & 0 deletions extension/data/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}

/*
* emulates old Reddit's style; it's comfy for toolbox too since so much of our
* style is based on that look
*/
a {
color: #369;
text-decoration: none;
}
32 changes: 32 additions & 0 deletions extension/data/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {useEffect, useState} from 'react';
import {useSelector} from 'react-redux';

import {RootState} from './store';
import {drawPosition} from './tbui';

/** Hook to get the return value of a promise. */
export const useFetched = <T>(promise: Promise<T>) => {
Expand Down Expand Up @@ -36,3 +38,33 @@ export const useSetting = (moduleName: string, settingName: string, defaultValue

return savedValue;
};

/**
* Helper hook for managing the visibility of "popups"/draggable windows which
* are shown in response to pointer events.
* Provides functions to show and hide the window in response to events, and
* automatically computes an appropriate initial position for the window when
* it's first shown based on the click event that triggered it.
*/
export function usePopupState<T extends HTMLElement> () {
const [initialPosition, setInitialPosition] = useState<{top: number; left: number}>();

return {
/** The popup's initial position. */
initialPosition,
/** Whether the popup should currently be shown. */
shown: !!initialPosition,
/** Shows the window in response to a pointer event (like a click). */
show: (event: React.MouseEvent<T>) => {
// NOTE: i don't know the details of comparing between
// React.MouseEvent and other mouse events but it's whatever for now
const positions = drawPosition(event as unknown as PointerEvent);
setInitialPosition({
top: positions.topPosition,
left: positions.leftPosition,
});
},
/** Hides the window. */
hide: () => setInitialPosition(undefined),
};
}
Loading