@@ -114,7 +117,7 @@ export const DifferentHeights: Story = {
args: {
items: slides.map((props, index) => ({
...props,
- styles: { height: 100 + index * 100 },
+ style: { height: 100 + index * 100 },
})),
},
};
diff --git a/app/javascript/flavours/glitch/components/carousel/index.tsx b/app/javascript/flavours/glitch/components/carousel/index.tsx
index b4ebf751ca..4fa5952a61 100644
--- a/app/javascript/flavours/glitch/components/carousel/index.tsx
+++ b/app/javascript/flavours/glitch/components/carousel/index.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
+import { useCallback, useMemo, useState } from 'react';
import type {
ComponentPropsWithoutRef,
ComponentType,
@@ -75,10 +75,13 @@ export const Carousel = <
}: CarouselProps
& ComponentPropsWithoutRef<'div'>) => {
// Handle slide change
const [slideIndex, setSlideIndex] = useState(0);
- const wrapperRef = useRef(null);
+ const [wrapperElement, setWrapperElement] = useState(
+ null,
+ );
+
// Handle slide heights
- const [currentSlideHeight, setCurrentSlideHeight] = useState(
- () => wrapperRef.current?.scrollHeight ?? 0,
+ const [currentSlideHeight, setCurrentSlideHeight] = useState(
+ null,
);
const previousSlideHeight = usePrevious(currentSlideHeight);
const handleSlideChange = useCallback(
@@ -92,7 +95,7 @@ export const Carousel = <
newIndex = 0;
}
- const slide = wrapperRef.current?.children[newIndex];
+ const slide = wrapperElement?.children[newIndex];
if (slide) {
setCurrentSlideHeight(slide.scrollHeight);
if (slide instanceof HTMLElement) {
@@ -103,26 +106,27 @@ export const Carousel = <
return newIndex;
});
},
- [items.length, onChangeSlide],
+ [wrapperElement, items.length, onChangeSlide],
);
- const observerRef = useRef(null);
- observerRef.current ??= new ResizeObserver(() => {
+ // Update slide height when the component mounts
+ if (wrapperElement && currentSlideHeight === null) {
handleSlideChange(0);
- });
+ }
+
+ const [observer] = useState(
+ () =>
+ new ResizeObserver(() => {
+ handleSlideChange(0);
+ }),
+ );
const wrapperStyles = useSpring({
x: `-${slideIndex * 100}%`,
- height: currentSlideHeight,
+ height: currentSlideHeight ?? 0,
// Don't animate from zero to the height of the initial slide
immediate: !previousSlideHeight,
});
- useLayoutEffect(() => {
- // Update slide height when the component mounts
- if (currentSlideHeight === 0) {
- handleSlideChange(0);
- }
- }, [currentSlideHeight, handleSlideChange]);
// Handle swiping animations
const bind = useDrag(
@@ -135,12 +139,12 @@ export const Carousel = <
handleSlideChange(-1);
// We're focusing on the wrapper as the child slides can potentially be inert.
// Because of that, only the active slide can be focused anyway.
- wrapperRef.current?.focus();
- }, [handleSlideChange]);
+ wrapperElement?.focus();
+ }, [handleSlideChange, wrapperElement]);
const handleNext = useCallback(() => {
handleSlideChange(1);
- wrapperRef.current?.focus();
- }, [handleSlideChange]);
+ wrapperElement?.focus();
+ }, [handleSlideChange, wrapperElement]);
const intl = useIntl();
@@ -173,7 +177,7 @@ export const Carousel = <
item={itemsProps}
renderItem={renderItem}
- observer={observerRef.current}
+ observer={observer}
index={index}
key={`slide-${itemsProps.id}`}
className={classNames(`${classNamePrefix}__slide`, slideClassName, {
diff --git a/app/javascript/flavours/glitch/components/dropdown_menu.tsx b/app/javascript/flavours/glitch/components/dropdown_menu.tsx
index f96a33a995..52e18763d8 100644
--- a/app/javascript/flavours/glitch/components/dropdown_menu.tsx
+++ b/app/javascript/flavours/glitch/components/dropdown_menu.tsx
@@ -488,6 +488,8 @@ export const Dropdown = - ({
};
if (children) {
+ // We're just assigning the ref to an element so this is safe
+ // eslint-disable-next-line react-hooks/refs
button = cloneElement(Children.only(children), buttonProps);
} else if (icon && iconComponent) {
button = (
diff --git a/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx b/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx
index 49f3f4fd16..399a73d4e6 100644
--- a/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx
+++ b/app/javascript/flavours/glitch/components/form_fields/combobox_field.tsx
@@ -317,6 +317,9 @@ const ComboboxWithRef =
- (
// Reset scroll & highlight when menu items change
useEffect(() => {
if (flatItems.length) {
+ // This only runs when the items change so should be safe from
+ // cascade renders.
+ // eslint-disable-next-line react-hooks/set-state-in-effect
resetHighlight();
}
}, [flatItems, resetHighlight]);
diff --git a/app/javascript/flavours/glitch/containers/scroll_container/scroll_context.tsx b/app/javascript/flavours/glitch/containers/scroll_container/scroll_context.tsx
index 8b45eb73ef..a85ce29347 100644
--- a/app/javascript/flavours/glitch/containers/scroll_container/scroll_context.tsx
+++ b/app/javascript/flavours/glitch/containers/scroll_container/scroll_context.tsx
@@ -74,6 +74,7 @@ export const ScrollContext: React.FC = ({
* than a ref to simplify the types and ensure it's defined immediately.
*/
const [scrollBehavior] = useState(
+ // eslint-disable-next-line react-hooks/refs
(): ScrollBehaviorInstance =>
new ScrollBehavior({
addNavigationListener: history.listen.bind(history),
diff --git a/app/javascript/flavours/glitch/features/audio/index.tsx b/app/javascript/flavours/glitch/features/audio/index.tsx
index 70ca5e5222..8a622f95be 100644
--- a/app/javascript/flavours/glitch/features/audio/index.tsx
+++ b/app/javascript/flavours/glitch/features/audio/index.tsx
@@ -20,9 +20,11 @@ import { SpoilerButton } from 'flavours/glitch/components/spoiler_button';
import { formatTime, getPointerPosition } from 'flavours/glitch/features/video';
import { useAudioContext } from 'flavours/glitch/hooks/useAudioContext';
import { useAudioVisualizer } from 'flavours/glitch/hooks/useAudioVisualizer';
-import { displayMedia, useBlurhash } from 'flavours/glitch/initial_state';
+import { useBlurhash } from 'flavours/glitch/initial_state';
import { playerSettings } from 'flavours/glitch/settings';
+import { useRevealedMedia } from '../../hooks/useRevealedMedia';
+
import { AudioVisualizer } from './visualizer';
const messages = defineMessages({
@@ -100,7 +102,7 @@ export const Audio: React.FC<{
const [volume, setVolume] = useState(0.5);
const [hovered, setHovered] = useState(false);
const [dragging, setDragging] = useState(false);
- const [revealed, setRevealed] = useState(false);
+ const [revealed, setRevealed] = useRevealedMedia({ visible, sensitive });
const playerRef = useRef(null);
const audioRef = useRef(null);
@@ -177,17 +179,6 @@ export const Audio: React.FC<{
}
}, [volume, muted, gainNodeRef]);
- useEffect(() => {
- if (typeof visible !== 'undefined') {
- setRevealed(visible);
- } else {
- setRevealed(
- displayMedia === 'show_all' ||
- (displayMedia !== 'hide_all' && !sensitive),
- );
- }
- }, [visible, sensitive]);
-
useEffect(() => {
if (!revealed) {
pauseAudio();
diff --git a/app/javascript/flavours/glitch/features/collection_adder/index.tsx b/app/javascript/flavours/glitch/features/collection_adder/index.tsx
index 0fa131579c..28baca2007 100644
--- a/app/javascript/flavours/glitch/features/collection_adder/index.tsx
+++ b/app/javascript/flavours/glitch/features/collection_adder/index.tsx
@@ -10,6 +10,7 @@ import { useCurrentAccountId } from '@/flavours/glitch/hooks/useAccountId';
import type { Account } from '@/flavours/glitch/models/account';
import {
addCollectionItem,
+ collectionEditorActions,
removeCollectionItem,
} from '@/flavours/glitch/reducers/slices/collections';
import CloseIcon from '@/material-icons/400-24px/close.svg?react';
@@ -23,6 +24,7 @@ import {
} from '../collections/overview/created_by_account';
import { CollectionToggle } from './collection_toggle';
+import classes from './styles.module.scss';
const messages = defineMessages({
close: {
@@ -107,6 +109,23 @@ export const CollectionAdder: React.FC<{
const account = useAppSelector((state) => state.accounts.get(accountId));
const currentAccountId = useCurrentAccountId();
const { collections, status } = useCollectionsCreatedBy(currentAccountId);
+ const dispatch = useAppDispatch();
+
+ const handleNewCollection = useCallback(() => {
+ if (account) {
+ dispatch(
+ collectionEditorActions.reset({
+ account_id: account.id,
+ state:
+ account.feature_approval.current_user === 'manual'
+ ? 'pending'
+ : 'accepted',
+ }),
+ );
+ }
+
+ onClose();
+ }, [account, dispatch, onClose]);
return (
@@ -155,12 +174,22 @@ export const CollectionAdder: React.FC<{
/>
}
>
-
+
) : (
- collections.map((item) => (
-
- ))
+ <>
+
+
+
+
+
+ {collections.map((item) => (
+
+ ))}
+ >
)}
diff --git a/app/javascript/flavours/glitch/features/collection_adder/styles.module.scss b/app/javascript/flavours/glitch/features/collection_adder/styles.module.scss
new file mode 100644
index 0000000000..0a0ee300b8
--- /dev/null
+++ b/app/javascript/flavours/glitch/features/collection_adder/styles.module.scss
@@ -0,0 +1,3 @@
+.newCollection {
+ padding: 16px;
+}
diff --git a/app/javascript/flavours/glitch/features/collections/overview/created_by_account.tsx b/app/javascript/flavours/glitch/features/collections/overview/created_by_account.tsx
index 7ac5f89307..0be6c1ac10 100644
--- a/app/javascript/flavours/glitch/features/collections/overview/created_by_account.tsx
+++ b/app/javascript/flavours/glitch/features/collections/overview/created_by_account.tsx
@@ -1,7 +1,9 @@
+import type { ReactNode } from 'react';
import { useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
+import classNames from 'classnames';
import { Link } from 'react-router-dom';
import AddIcon from '@/material-icons/400-24px/add.svg?react';
@@ -29,16 +31,23 @@ import {
} from '../editor';
import classes from '../styles.module.scss';
-export const NewCollectionButton: React.FC<{ onClick?: () => void }> = ({
- onClick,
-}) => (
+export const NewCollectionButton: React.FC<{
+ compact?: boolean;
+ secondary?: boolean;
+ onClick?: () => void;
+ children?: ReactNode;
+}> = ({ compact, secondary, onClick, children }) => (