Merge pull request #3592 from glitch-soc/glitch-soc/merge-upstream
Merge upstream changes up to 5f5dfd7823
This commit is contained in:
14 files changed
+901
-67
No files matched your search
@@ -6,6 +6,8 @@ class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
||||
before_action :destroy_previous_subscriptions, only: :create, if: :prior_subscriptions?
|
||||
after_action :update_session_with_subscription, only: :create
|
||||
|
||||
skip_forgery_protection only: :destroy
|
||||
|
||||
def create
|
||||
@push_subscription = ::Web::PushSubscription.create!(web_push_subscription_params)
|
||||
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
.base {
|
||||
--bg: transparent;
|
||||
--fg: var(--color-text-primary);
|
||||
|
||||
background-color: var(--bg);
|
||||
border-radius: var(--radius-round);
|
||||
color: var(--fg);
|
||||
transition:
|
||||
background-color 200ms,
|
||||
color 200ms;
|
||||
border: 0;
|
||||
appearance: none;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: var(--fs-sm);
|
||||
line-height: 1;
|
||||
box-sizing: border-box;
|
||||
gap: var(--space-2xs);
|
||||
|
||||
&:focus-visible,
|
||||
&:focus-within {
|
||||
outline: 2px solid var(--fg);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&:hover:disabled {
|
||||
cursor: auto;
|
||||
}
|
||||
}
|
||||
|
||||
// Override default anchor styles
|
||||
a.base {
|
||||
&:focus {
|
||||
border-radius: var(--radius-round);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
text-decoration: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.xs {
|
||||
padding: var(--space-3xs) var(--space-xs);
|
||||
font-size: var(--fs-2xs);
|
||||
min-height: 24px;
|
||||
}
|
||||
|
||||
.sm {
|
||||
padding: var(--space-xs);
|
||||
min-height: 32px;
|
||||
}
|
||||
|
||||
.md {
|
||||
padding: var(--space-xs) var(--space-sm);
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.lg {
|
||||
padding: var(--space-sm) var(--space-md);
|
||||
min-height: 48px;
|
||||
}
|
||||
|
||||
.solid {
|
||||
--bg: var(--color-bg-inverted);
|
||||
--bg-hover: color-mix(in srgb, var(--bg) 90%, var(--fg));
|
||||
--fg: var(--color-text-inverted);
|
||||
|
||||
background-color: var(--bg);
|
||||
border-radius: var(--radius-round);
|
||||
color: var(--fg);
|
||||
transition:
|
||||
background-color 200ms,
|
||||
color 200ms;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--bg-hover);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background-color: color-mix(in srgb, var(--bg-hover) 80%, var(--fg));
|
||||
}
|
||||
|
||||
&.accent {
|
||||
--bg: var(--color-bg-brand-base);
|
||||
--bg-hover: var(--color-bg-brand-base-hover);
|
||||
}
|
||||
|
||||
&.tonal {
|
||||
--bg: var(--color-bg-highlight);
|
||||
--fg: var(--color-text-primary);
|
||||
}
|
||||
|
||||
&.destructive {
|
||||
--bg: var(--color-bg-error-base);
|
||||
--bg-hover: var(--color-bg-error-base-hover);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
--bg: var(--color-bg-disabled);
|
||||
--bg-hover: var(--bg);
|
||||
--fg: var(--color-text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
&.accent {
|
||||
--fg: var(--color-text-brand);
|
||||
|
||||
&:hover {
|
||||
--fg: var(--color-text-brand-soft);
|
||||
}
|
||||
}
|
||||
|
||||
&.neutral,
|
||||
&.tonal {
|
||||
&:hover {
|
||||
--fg: rgb(from var(--color-text-primary) r g b / 80%);
|
||||
}
|
||||
}
|
||||
|
||||
&.destructive {
|
||||
--fg: var(--color-text-error);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&:hover:disabled {
|
||||
--fg: var(--color-text-disabled);
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: var(--fs-lg);
|
||||
}
|
||||
|
||||
.iconOnly {
|
||||
aspect-ratio: 1;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: inherit;
|
||||
height: 0.8em;
|
||||
width: 0.8em;
|
||||
|
||||
.iconOnly & {
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { fn } from 'storybook/test';
|
||||
|
||||
import ChatIcon from '@/material-icons/400-24px/chat.svg?react';
|
||||
import DownloadIcon from '@/material-icons/400-24px/download.svg?react';
|
||||
import HeadphonesIcon from '@/material-icons/400-24px/headphones.svg?react';
|
||||
|
||||
import { Button, IconButton } from './redesign';
|
||||
|
||||
const iconArgType = {
|
||||
control: 'select',
|
||||
options: ['chat', 'download', 'audio'],
|
||||
mapping: {
|
||||
chat: ChatIcon,
|
||||
download: DownloadIcon,
|
||||
audio: HeadphonesIcon,
|
||||
},
|
||||
} as const;
|
||||
|
||||
const meta = {
|
||||
title: 'Redesign/Button',
|
||||
component: Button,
|
||||
args: {
|
||||
children: 'Action',
|
||||
size: 'md',
|
||||
variant: 'solid',
|
||||
color: 'neutral',
|
||||
disabled: false,
|
||||
loading: false,
|
||||
as: 'button',
|
||||
onClick: fn(),
|
||||
},
|
||||
argTypes: {
|
||||
children: {
|
||||
control: 'text',
|
||||
},
|
||||
as: {
|
||||
control: 'inline-radio',
|
||||
options: ['button', 'a', 'link'],
|
||||
},
|
||||
size: {
|
||||
control: 'inline-radio',
|
||||
options: ['xs', 'sm', 'md', 'lg'],
|
||||
},
|
||||
variant: {
|
||||
control: 'inline-radio',
|
||||
options: ['solid', 'text'],
|
||||
},
|
||||
color: {
|
||||
control: 'inline-radio',
|
||||
options: ['neutral', 'accent', 'tonal', 'destructive'],
|
||||
},
|
||||
leadingIcon: iconArgType,
|
||||
trailingIcon: iconArgType,
|
||||
onClick: {
|
||||
table: {
|
||||
disable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies Meta<typeof Button>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const IconLeading: Story = {
|
||||
args: {
|
||||
leadingIcon: ChatIcon,
|
||||
},
|
||||
};
|
||||
|
||||
export const IconTrailing: Story = {
|
||||
args: {
|
||||
trailingIcon: HeadphonesIcon,
|
||||
},
|
||||
};
|
||||
|
||||
export const IconOnly: Story = {
|
||||
render(args) {
|
||||
return <IconButton {...args} icon={args.leadingIcon ?? ChatIcon} />;
|
||||
},
|
||||
args: {
|
||||
leadingIcon: ChatIcon,
|
||||
},
|
||||
};
|
||||
|
||||
export const Link: Story = {
|
||||
render(args) {
|
||||
if (args.as === 'link') {
|
||||
return <Button {...args} to='/example' />;
|
||||
}
|
||||
return <Button {...args} />;
|
||||
},
|
||||
args: {
|
||||
as: 'link',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
import type React from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
import { Link } from 'react-router-dom';
|
||||
import type { LinkProps } from 'react-router-dom';
|
||||
|
||||
import { CircularProgress } from '../circular_progress';
|
||||
import type { IconProp } from '../icon';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
import classes from './redesign.module.scss';
|
||||
|
||||
interface ButtonPropsBase<As extends 'a' | 'button'> {
|
||||
size?: 'lg' | 'md' | 'sm' | 'xs';
|
||||
variant?: 'solid' | 'text';
|
||||
color?: 'accent' | 'neutral' | 'tonal' | 'destructive';
|
||||
onClick?: React.MouseEventHandler<
|
||||
As extends 'button' ? HTMLButtonElement : HTMLAnchorElement
|
||||
>;
|
||||
loading?: boolean;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
type ButtonButtonProps = { as?: 'button' } & ButtonPropsBase<'button'> &
|
||||
Omit<React.ComponentPropsWithRef<'button'>, 'children'>;
|
||||
type ButtonAnchorProps = { as: 'a' } & ButtonPropsBase<'a'> &
|
||||
Omit<React.ComponentPropsWithRef<'a'>, 'children'>;
|
||||
type ButtonLinkProps = { as: 'link' } & ButtonPropsBase<'a'> &
|
||||
Omit<LinkProps, 'children'>;
|
||||
|
||||
type ButtonProps = ButtonButtonProps | ButtonAnchorProps | ButtonLinkProps;
|
||||
|
||||
const BaseButton: React.FC<ButtonProps> = ({
|
||||
size = 'md',
|
||||
variant = 'solid',
|
||||
color = 'neutral',
|
||||
as: asComp = 'button',
|
||||
children,
|
||||
className,
|
||||
onClick,
|
||||
loading,
|
||||
'aria-disabled': ariaDisabled,
|
||||
'aria-live': ariaLive,
|
||||
...props
|
||||
}) => {
|
||||
const disabled = 'disabled' in props ? props.disabled : false;
|
||||
const handleClick: React.MouseEventHandler<
|
||||
HTMLButtonElement & HTMLAnchorElement
|
||||
> = useCallback(
|
||||
(event) => {
|
||||
if (disabled || loading) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
} else if (onClick) {
|
||||
onClick(event);
|
||||
}
|
||||
},
|
||||
[loading, onClick, disabled],
|
||||
);
|
||||
|
||||
let Comp: React.ElementType = asComp;
|
||||
if (asComp === 'link') {
|
||||
Comp = Link;
|
||||
}
|
||||
|
||||
return (
|
||||
<Comp
|
||||
type='button'
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
classes.base,
|
||||
classes[size],
|
||||
classes[color],
|
||||
classes[variant],
|
||||
)}
|
||||
onClick={handleClick}
|
||||
// Disabled buttons can't have focus, so we don't really
|
||||
// disable the button during loading
|
||||
disabled={disabled && !loading}
|
||||
aria-disabled={loading || ariaDisabled}
|
||||
// If the loading prop is used, announce label changes
|
||||
aria-live={ariaLive ?? (loading !== undefined ? 'polite' : undefined)}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
};
|
||||
|
||||
export const Button: React.FC<
|
||||
ButtonProps & {
|
||||
leadingIcon?: IconProp;
|
||||
trailingIcon?: IconProp;
|
||||
}
|
||||
> = ({ children, leadingIcon, trailingIcon, ...props }) => (
|
||||
<BaseButton {...props}>
|
||||
{leadingIcon && !props.loading && (
|
||||
<Icon id='leading' icon={leadingIcon} className={classes.icon} />
|
||||
)}
|
||||
{props.loading && <LoadingIcon />}
|
||||
{children}
|
||||
{trailingIcon && (
|
||||
<Icon id='trailing' icon={trailingIcon} className={classes.icon} />
|
||||
)}
|
||||
</BaseButton>
|
||||
);
|
||||
|
||||
export const IconButton: React.FC<ButtonProps & { icon: IconProp }> = ({
|
||||
icon,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<BaseButton {...props} className={classNames(classNames, classes.iconOnly)}>
|
||||
{props.loading ? (
|
||||
<LoadingIcon />
|
||||
) : (
|
||||
<Icon id='icon' icon={icon} className={classes.icon} />
|
||||
)}
|
||||
<span className='sr-only'>{children}</span>
|
||||
</BaseButton>
|
||||
);
|
||||
|
||||
const LoadingIcon: React.FC = () => (
|
||||
<CircularProgress
|
||||
size={10}
|
||||
strokeWidth={1}
|
||||
className={classes.loading}
|
||||
role='none'
|
||||
/>
|
||||
);
|
||||
@@ -1,9 +1,13 @@
|
||||
import classNames from 'classnames';
|
||||
|
||||
interface Props {
|
||||
size: number;
|
||||
strokeWidth: number;
|
||||
}
|
||||
|
||||
export const CircularProgress: React.FC<Props> = ({ size, strokeWidth }) => {
|
||||
export const CircularProgress: React.FC<
|
||||
Props & React.SVGAttributes<SVGElement>
|
||||
> = ({ size, strokeWidth, className, ...props }) => {
|
||||
const viewBox = `0 0 ${size} ${size}`;
|
||||
const radius = (size - strokeWidth) / 2;
|
||||
|
||||
@@ -12,8 +16,9 @@ export const CircularProgress: React.FC<Props> = ({ size, strokeWidth }) => {
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox={viewBox}
|
||||
className='circular-progress'
|
||||
className={classNames('circular-progress', className)}
|
||||
role='progressbar'
|
||||
{...props}
|
||||
>
|
||||
<circle
|
||||
fill='none'
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
.base {
|
||||
--bg: transparent;
|
||||
--fg: var(--color-text-primary);
|
||||
|
||||
background-color: var(--bg);
|
||||
border-radius: var(--radius-round);
|
||||
color: var(--fg);
|
||||
transition:
|
||||
background-color 200ms,
|
||||
color 200ms;
|
||||
border: 0;
|
||||
appearance: none;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: var(--fs-sm);
|
||||
line-height: 1;
|
||||
box-sizing: border-box;
|
||||
gap: var(--space-2xs);
|
||||
|
||||
&:focus-visible,
|
||||
&:focus-within {
|
||||
outline: 2px solid var(--fg);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&:hover:disabled {
|
||||
cursor: auto;
|
||||
}
|
||||
}
|
||||
|
||||
// Override default anchor styles
|
||||
a.base {
|
||||
&:focus {
|
||||
border-radius: var(--radius-round);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
text-decoration: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.xs {
|
||||
padding: var(--space-3xs) var(--space-xs);
|
||||
font-size: var(--fs-2xs);
|
||||
min-height: 24px;
|
||||
}
|
||||
|
||||
.sm {
|
||||
padding: var(--space-xs);
|
||||
min-height: 32px;
|
||||
}
|
||||
|
||||
.md {
|
||||
padding: var(--space-xs) var(--space-sm);
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.lg {
|
||||
padding: var(--space-sm) var(--space-md);
|
||||
min-height: 48px;
|
||||
}
|
||||
|
||||
.solid {
|
||||
--bg: var(--color-bg-inverted);
|
||||
--bg-hover: color-mix(in srgb, var(--bg) 90%, var(--fg));
|
||||
--fg: var(--color-text-inverted);
|
||||
|
||||
background-color: var(--bg);
|
||||
border-radius: var(--radius-round);
|
||||
color: var(--fg);
|
||||
transition:
|
||||
background-color 200ms,
|
||||
color 200ms;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--bg-hover);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background-color: color-mix(in srgb, var(--bg-hover) 80%, var(--fg));
|
||||
}
|
||||
|
||||
&.accent {
|
||||
--bg: var(--color-bg-brand-base);
|
||||
--bg-hover: var(--color-bg-brand-base-hover);
|
||||
}
|
||||
|
||||
&.tonal {
|
||||
--bg: var(--color-bg-highlight);
|
||||
--fg: var(--color-text-primary);
|
||||
}
|
||||
|
||||
&.destructive {
|
||||
--bg: var(--color-bg-error-base);
|
||||
--bg-hover: var(--color-bg-error-base-hover);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
--bg: var(--color-bg-disabled);
|
||||
--bg-hover: var(--bg);
|
||||
--fg: var(--color-text-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
&.accent {
|
||||
--fg: var(--color-text-brand);
|
||||
|
||||
&:hover {
|
||||
--fg: var(--color-text-brand-soft);
|
||||
}
|
||||
}
|
||||
|
||||
&.neutral,
|
||||
&.tonal {
|
||||
&:hover {
|
||||
--fg: rgb(from var(--color-text-primary) r g b / 80%);
|
||||
}
|
||||
}
|
||||
|
||||
&.destructive {
|
||||
--fg: var(--color-text-error);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&:hover:disabled {
|
||||
--fg: var(--color-text-disabled);
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: var(--fs-lg);
|
||||
}
|
||||
|
||||
.iconOnly {
|
||||
aspect-ratio: 1;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: inherit;
|
||||
height: 0.8em;
|
||||
width: 0.8em;
|
||||
|
||||
.iconOnly & {
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { fn } from 'storybook/test';
|
||||
|
||||
import ChatIcon from '@/material-icons/400-24px/chat.svg?react';
|
||||
import DownloadIcon from '@/material-icons/400-24px/download.svg?react';
|
||||
import HeadphonesIcon from '@/material-icons/400-24px/headphones.svg?react';
|
||||
|
||||
import { Button, IconButton } from './redesign';
|
||||
|
||||
const iconArgType = {
|
||||
control: 'select',
|
||||
options: ['chat', 'download', 'audio'],
|
||||
mapping: {
|
||||
chat: ChatIcon,
|
||||
download: DownloadIcon,
|
||||
audio: HeadphonesIcon,
|
||||
},
|
||||
} as const;
|
||||
|
||||
const meta = {
|
||||
title: 'Redesign/Button',
|
||||
component: Button,
|
||||
args: {
|
||||
children: 'Action',
|
||||
size: 'md',
|
||||
variant: 'solid',
|
||||
color: 'neutral',
|
||||
disabled: false,
|
||||
loading: false,
|
||||
as: 'button',
|
||||
onClick: fn(),
|
||||
},
|
||||
argTypes: {
|
||||
children: {
|
||||
control: 'text',
|
||||
},
|
||||
as: {
|
||||
control: 'inline-radio',
|
||||
options: ['button', 'a', 'link'],
|
||||
},
|
||||
size: {
|
||||
control: 'inline-radio',
|
||||
options: ['xs', 'sm', 'md', 'lg'],
|
||||
},
|
||||
variant: {
|
||||
control: 'inline-radio',
|
||||
options: ['solid', 'text'],
|
||||
},
|
||||
color: {
|
||||
control: 'inline-radio',
|
||||
options: ['neutral', 'accent', 'tonal', 'destructive'],
|
||||
},
|
||||
leadingIcon: iconArgType,
|
||||
trailingIcon: iconArgType,
|
||||
onClick: {
|
||||
table: {
|
||||
disable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies Meta<typeof Button>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const IconLeading: Story = {
|
||||
args: {
|
||||
leadingIcon: ChatIcon,
|
||||
},
|
||||
};
|
||||
|
||||
export const IconTrailing: Story = {
|
||||
args: {
|
||||
trailingIcon: HeadphonesIcon,
|
||||
},
|
||||
};
|
||||
|
||||
export const IconOnly: Story = {
|
||||
render(args) {
|
||||
return <IconButton {...args} icon={args.leadingIcon ?? ChatIcon} />;
|
||||
},
|
||||
args: {
|
||||
leadingIcon: ChatIcon,
|
||||
},
|
||||
};
|
||||
|
||||
export const Link: Story = {
|
||||
render(args) {
|
||||
if (args.as === 'link') {
|
||||
return <Button {...args} to='/example' />;
|
||||
}
|
||||
return <Button {...args} />;
|
||||
},
|
||||
args: {
|
||||
as: 'link',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
import type React from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
import { Link } from 'react-router-dom';
|
||||
import type { LinkProps } from 'react-router-dom';
|
||||
|
||||
import { CircularProgress } from '../circular_progress';
|
||||
import type { IconProp } from '../icon';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
import classes from './redesign.module.scss';
|
||||
|
||||
interface ButtonPropsBase<As extends 'a' | 'button'> {
|
||||
size?: 'lg' | 'md' | 'sm' | 'xs';
|
||||
variant?: 'solid' | 'text';
|
||||
color?: 'accent' | 'neutral' | 'tonal' | 'destructive';
|
||||
onClick?: React.MouseEventHandler<
|
||||
As extends 'button' ? HTMLButtonElement : HTMLAnchorElement
|
||||
>;
|
||||
loading?: boolean;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
type ButtonButtonProps = { as?: 'button' } & ButtonPropsBase<'button'> &
|
||||
Omit<React.ComponentPropsWithRef<'button'>, 'children'>;
|
||||
type ButtonAnchorProps = { as: 'a' } & ButtonPropsBase<'a'> &
|
||||
Omit<React.ComponentPropsWithRef<'a'>, 'children'>;
|
||||
type ButtonLinkProps = { as: 'link' } & ButtonPropsBase<'a'> &
|
||||
Omit<LinkProps, 'children'>;
|
||||
|
||||
type ButtonProps = ButtonButtonProps | ButtonAnchorProps | ButtonLinkProps;
|
||||
|
||||
const BaseButton: React.FC<ButtonProps> = ({
|
||||
size = 'md',
|
||||
variant = 'solid',
|
||||
color = 'neutral',
|
||||
as: asComp = 'button',
|
||||
children,
|
||||
className,
|
||||
onClick,
|
||||
loading,
|
||||
'aria-disabled': ariaDisabled,
|
||||
'aria-live': ariaLive,
|
||||
...props
|
||||
}) => {
|
||||
const disabled = 'disabled' in props ? props.disabled : false;
|
||||
const handleClick: React.MouseEventHandler<
|
||||
HTMLButtonElement & HTMLAnchorElement
|
||||
> = useCallback(
|
||||
(event) => {
|
||||
if (disabled || loading) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
} else if (onClick) {
|
||||
onClick(event);
|
||||
}
|
||||
},
|
||||
[loading, onClick, disabled],
|
||||
);
|
||||
|
||||
let Comp: React.ElementType = asComp;
|
||||
if (asComp === 'link') {
|
||||
Comp = Link;
|
||||
}
|
||||
|
||||
return (
|
||||
<Comp
|
||||
type='button'
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
classes.base,
|
||||
classes[size],
|
||||
classes[color],
|
||||
classes[variant],
|
||||
)}
|
||||
onClick={handleClick}
|
||||
// Disabled buttons can't have focus, so we don't really
|
||||
// disable the button during loading
|
||||
disabled={disabled && !loading}
|
||||
aria-disabled={loading || ariaDisabled}
|
||||
// If the loading prop is used, announce label changes
|
||||
aria-live={ariaLive ?? (loading !== undefined ? 'polite' : undefined)}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
};
|
||||
|
||||
export const Button: React.FC<
|
||||
ButtonProps & {
|
||||
leadingIcon?: IconProp;
|
||||
trailingIcon?: IconProp;
|
||||
}
|
||||
> = ({ children, leadingIcon, trailingIcon, ...props }) => (
|
||||
<BaseButton {...props}>
|
||||
{leadingIcon && !props.loading && (
|
||||
<Icon id='leading' icon={leadingIcon} className={classes.icon} />
|
||||
)}
|
||||
{props.loading && <LoadingIcon />}
|
||||
{children}
|
||||
{trailingIcon && (
|
||||
<Icon id='trailing' icon={trailingIcon} className={classes.icon} />
|
||||
)}
|
||||
</BaseButton>
|
||||
);
|
||||
|
||||
export const IconButton: React.FC<ButtonProps & { icon: IconProp }> = ({
|
||||
icon,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<BaseButton {...props} className={classNames(classNames, classes.iconOnly)}>
|
||||
{props.loading ? (
|
||||
<LoadingIcon />
|
||||
) : (
|
||||
<Icon id='icon' icon={icon} className={classes.icon} />
|
||||
)}
|
||||
<span className='sr-only'>{children}</span>
|
||||
</BaseButton>
|
||||
);
|
||||
|
||||
const LoadingIcon: React.FC = () => (
|
||||
<CircularProgress
|
||||
size={10}
|
||||
strokeWidth={1}
|
||||
className={classes.loading}
|
||||
role='none'
|
||||
/>
|
||||
);
|
||||
@@ -1,9 +1,13 @@
|
||||
import classNames from 'classnames';
|
||||
|
||||
interface Props {
|
||||
size: number;
|
||||
strokeWidth: number;
|
||||
}
|
||||
|
||||
export const CircularProgress: React.FC<Props> = ({ size, strokeWidth }) => {
|
||||
export const CircularProgress: React.FC<
|
||||
Props & React.SVGAttributes<SVGElement>
|
||||
> = ({ size, strokeWidth, className, ...props }) => {
|
||||
const viewBox = `0 0 ${size} ${size}`;
|
||||
const radius = (size - strokeWidth) / 2;
|
||||
|
||||
@@ -12,8 +16,9 @@ export const CircularProgress: React.FC<Props> = ({ size, strokeWidth }) => {
|
||||
width={size}
|
||||
height={size}
|
||||
viewBox={viewBox}
|
||||
className='circular-progress'
|
||||
className={classNames('circular-progress', className)}
|
||||
role='progressbar'
|
||||
{...props}
|
||||
>
|
||||
<circle
|
||||
fill='none'
|
||||
|
||||
@@ -36,6 +36,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
|
||||
if @status.nil?
|
||||
process_status
|
||||
elsif @status.account_id != @account.id
|
||||
Rails.logger.debug { "Not processing #{object_uri}: authorship change is not supported" }
|
||||
return reject_payload!
|
||||
elsif @options[:delivered_to_account_id].present?
|
||||
postprocess_audience_and_deliver
|
||||
end
|
||||
@@ -92,7 +95,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
def find_existing_status
|
||||
status = status_from_uri(object_uri)
|
||||
status ||= Status.find_by(uri: @object['atomUri']) if @object['atomUri'].present?
|
||||
status if status&.account_id == @account.id
|
||||
status
|
||||
end
|
||||
|
||||
def process_status_params
|
||||
|
||||
+2
-2
@@ -156,7 +156,7 @@
|
||||
"@types/redux-immutable": "^4.0.3",
|
||||
"@types/requestidlecallback": "^0.3.5",
|
||||
"@vitest/browser": "^4.1.0",
|
||||
"@vitest/browser-playwright": "^4.1.7",
|
||||
"@vitest/browser-playwright": "^4.1.10",
|
||||
"@vitest/coverage-v8": "^4.1.0",
|
||||
"@vitest/ui": "^4.1.0",
|
||||
"chromatic": "^18.0.0",
|
||||
@@ -185,7 +185,7 @@
|
||||
"typescript": "~6.0.0",
|
||||
"typescript-eslint": "^8.55.0",
|
||||
"typescript-plugin-css-modules": "^5.2.0",
|
||||
"vitest": "^4.1.7"
|
||||
"vitest": "^4.1.10"
|
||||
},
|
||||
"resolutions": {
|
||||
"kind-of": "^6.0.3"
|
||||
|
||||
@@ -527,6 +527,30 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the status is already known' do
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:object_json) do
|
||||
build_object(
|
||||
to: ActivityPub::TagManager.instance.uri_for(recipient)
|
||||
)
|
||||
end
|
||||
|
||||
let!(:status) { Fabricate(:status, uri: object_json[:id], account: sender, text: object_json[:content]) }
|
||||
|
||||
it 'keeps the status intact' do
|
||||
expect(subject.perform).to eq status
|
||||
end
|
||||
|
||||
context 'when the known status is attributed to a different actor' do
|
||||
let!(:status) { Fabricate(:status, uri: object_json[:id], account: Fabricate(:remote_account)) }
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.perform).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when direct' do
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
@@ -1469,7 +1493,7 @@ RSpec.describe ActivityPub::Activity::Create do
|
||||
|
||||
def build_object(options = {})
|
||||
{
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
|
||||
id: [ActivityPub::TagManager.instance.uri_for(sender), '/bar'].join,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
}.merge(options)
|
||||
|
||||
@@ -39,6 +39,15 @@ RSpec.describe 'API Web Push Subscriptions' do
|
||||
describe 'DELETE /api/web/push_subscriptions/:id' do
|
||||
subject { delete api_web_push_subscription_path(token) }
|
||||
|
||||
around do |example|
|
||||
old = ActionController::Base.allow_forgery_protection
|
||||
ActionController::Base.allow_forgery_protection = true
|
||||
|
||||
example.run
|
||||
|
||||
ActionController::Base.allow_forgery_protection = old
|
||||
end
|
||||
|
||||
context 'when the subscription exists' do
|
||||
let!(:web_push_subscription) do
|
||||
Fabricate(:web_push_subscription)
|
||||
|
||||
@@ -2989,7 +2989,7 @@ __metadata:
|
||||
"@vitejs/plugin-legacy": "npm:^8.0.0"
|
||||
"@vitejs/plugin-react": "npm:^6.0.0"
|
||||
"@vitest/browser": "npm:^4.1.0"
|
||||
"@vitest/browser-playwright": "npm:^4.1.7"
|
||||
"@vitest/browser-playwright": "npm:^4.1.10"
|
||||
"@vitest/coverage-v8": "npm:^4.1.0"
|
||||
"@vitest/ui": "npm:^4.1.0"
|
||||
arrow-key-navigation: "npm:^1.2.0"
|
||||
@@ -3085,7 +3085,7 @@ __metadata:
|
||||
vite: "npm:^8.0.0"
|
||||
vite-plugin-manifest-sri: "npm:^0.2.0"
|
||||
vite-plugin-svgr: "npm:^5.0.0"
|
||||
vitest: "npm:^4.1.7"
|
||||
vitest: "npm:^4.1.10"
|
||||
wicg-inert: "npm:^3.1.2"
|
||||
peerDependenciesMeta:
|
||||
react:
|
||||
@@ -5409,38 +5409,38 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/browser-playwright@npm:^4.1.7":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/browser-playwright@npm:4.1.9"
|
||||
"@vitest/browser-playwright@npm:^4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/browser-playwright@npm:4.1.10"
|
||||
dependencies:
|
||||
"@vitest/browser": "npm:4.1.9"
|
||||
"@vitest/mocker": "npm:4.1.9"
|
||||
"@vitest/browser": "npm:4.1.10"
|
||||
"@vitest/mocker": "npm:4.1.10"
|
||||
tinyrainbow: "npm:^3.1.0"
|
||||
peerDependencies:
|
||||
playwright: "*"
|
||||
vitest: 4.1.9
|
||||
vitest: 4.1.10
|
||||
peerDependenciesMeta:
|
||||
playwright:
|
||||
optional: false
|
||||
checksum: 10c0/4c042c980bb0aa950646d4d1f0f131f44156141d86f54eb96f5f69863ed05720cac7ef1a0901ab71e18929a62c41e5d64a428b2612ea708905bf423ff961dcf4
|
||||
checksum: 10c0/161530da4da9c061875c0e80c2c94e93658bf92514f2e5173c04299e17a6021feb209ef8fb5e14e880c8c8b2b9e7fc4f3ec7a346c8c4a77831864597331257fc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/browser@npm:4.1.9, @vitest/browser@npm:^4.1.0":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/browser@npm:4.1.9"
|
||||
"@vitest/browser@npm:4.1.10, @vitest/browser@npm:^4.1.0":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/browser@npm:4.1.10"
|
||||
dependencies:
|
||||
"@blazediff/core": "npm:1.9.1"
|
||||
"@vitest/mocker": "npm:4.1.9"
|
||||
"@vitest/utils": "npm:4.1.9"
|
||||
"@vitest/mocker": "npm:4.1.10"
|
||||
"@vitest/utils": "npm:4.1.10"
|
||||
magic-string: "npm:^0.30.21"
|
||||
pngjs: "npm:^7.0.0"
|
||||
sirv: "npm:^3.0.2"
|
||||
tinyrainbow: "npm:^3.1.0"
|
||||
ws: "npm:^8.19.0"
|
||||
peerDependencies:
|
||||
vitest: 4.1.9
|
||||
checksum: 10c0/9ff634e56b0bd5a3727f2eec7666f97a089b92fb596d5b9e4fbe2a2e4fd988aa7a7bd2a7b98d7cf14790717db69db8f72bae6dc007f2fac613b9bb93d8e8edfb
|
||||
vitest: 4.1.10
|
||||
checksum: 10c0/61c86b8c0fcc78bd01de559914525e768dc16d565ee8a40a41d51ef6d99595c3c5e976defe32d090b3dda5f77a980caa11a2072e9c4d279cfb8d55d31c565fc7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5481,25 +5481,25 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/expect@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/expect@npm:4.1.9"
|
||||
"@vitest/expect@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/expect@npm:4.1.10"
|
||||
dependencies:
|
||||
"@standard-schema/spec": "npm:^1.1.0"
|
||||
"@types/chai": "npm:^5.2.2"
|
||||
"@vitest/spy": "npm:4.1.9"
|
||||
"@vitest/utils": "npm:4.1.9"
|
||||
"@vitest/spy": "npm:4.1.10"
|
||||
"@vitest/utils": "npm:4.1.10"
|
||||
chai: "npm:^6.2.2"
|
||||
tinyrainbow: "npm:^3.1.0"
|
||||
checksum: 10c0/243bacaed2cba5e0ea4ec7465662fcec465a358a0e06381e337fac49426aa67a73b104fbb9d65d8bccadfba8f70e27f57ffb897aacfa140f579a556367357875
|
||||
checksum: 10c0/a817ad0d9bd6a039776a7228d54fb8319c17e4af15917407f5566ac61781a8511f591d302519d6999217399915bc3c0290028189fc73f5c38f80cb01b6f19c8d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/mocker@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/mocker@npm:4.1.9"
|
||||
"@vitest/mocker@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/mocker@npm:4.1.10"
|
||||
dependencies:
|
||||
"@vitest/spy": "npm:4.1.9"
|
||||
"@vitest/spy": "npm:4.1.10"
|
||||
estree-walker: "npm:^3.0.3"
|
||||
magic-string: "npm:^0.30.21"
|
||||
peerDependencies:
|
||||
@@ -5510,7 +5510,7 @@ __metadata:
|
||||
optional: true
|
||||
vite:
|
||||
optional: true
|
||||
checksum: 10c0/707353b7435bbfd441cc754e4ee7bc5921b70d07b051c6e414b6bbe4ca369154702b0ddeb603389469fe87ca1983e002eb2d55044582661f54a1945dd27e5c82
|
||||
checksum: 10c0/4aa70b0df58681652e2e28093437fb2e8f4d02a6d03f5619abc266ac1c5ae5f43326148061d13ae6e071e0f6cfcf7634659af63644de8ce098a7c98949a3d1ad
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5523,6 +5523,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/pretty-format@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/pretty-format@npm:4.1.10"
|
||||
dependencies:
|
||||
tinyrainbow: "npm:^3.1.0"
|
||||
checksum: 10c0/1a5daba730ffe23f2000bff484b4b2842f3b178d93663cb487b215516b8d3b62caa3e2bb2a3c63307b61a9fe58fb9bfff38559bc0c5e49d8aa403d6803a1d918
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/pretty-format@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/pretty-format@npm:4.1.9"
|
||||
@@ -5532,25 +5541,25 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/runner@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/runner@npm:4.1.9"
|
||||
"@vitest/runner@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/runner@npm:4.1.10"
|
||||
dependencies:
|
||||
"@vitest/utils": "npm:4.1.9"
|
||||
"@vitest/utils": "npm:4.1.10"
|
||||
pathe: "npm:^2.0.3"
|
||||
checksum: 10c0/d206b4891a64b1f55c346f832b0a7b489108094d8ae34438d3b53e78be7b45b139fa95ffa027c98c357bd532268ee573168de1943235b7eed32a9236ed5978bb
|
||||
checksum: 10c0/554b72639de9694271b99be8ae273fe12ec793093ec91cce143816cd1187d40b7138a4d9d4de4f456cfca9567de986825bff97e107c05b9eb4abc130e854286d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/snapshot@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/snapshot@npm:4.1.9"
|
||||
"@vitest/snapshot@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/snapshot@npm:4.1.10"
|
||||
dependencies:
|
||||
"@vitest/pretty-format": "npm:4.1.9"
|
||||
"@vitest/utils": "npm:4.1.9"
|
||||
"@vitest/pretty-format": "npm:4.1.10"
|
||||
"@vitest/utils": "npm:4.1.10"
|
||||
magic-string: "npm:^0.30.21"
|
||||
pathe: "npm:^2.0.3"
|
||||
checksum: 10c0/c3099df12ad1f9c1e180441856c9eb82f1990f87ff16aafedd6fa19978eaff20bc59220b692a99fcc822daef86eab256ba3dadb49544b7bd625b57c49cd9d995
|
||||
checksum: 10c0/e71398725f51af5fd0c07bb4b957d0f987daf9b4c564ac24cb2a4d1afde1a6939f535ac17761a32dcc41b0a1e6d4088af66dc44df89fdebebb92aabed1a92b5f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5563,10 +5572,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/spy@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/spy@npm:4.1.9"
|
||||
checksum: 10c0/e51f328f55b76e8ba66e5e18f183484a8dc0a092685b101112d3e9fb8e989ddca162c98ddf00254476502c25bc05c4ec1e277fd6ad8bfc702464c08f6b5dd115
|
||||
"@vitest/spy@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/spy@npm:4.1.10"
|
||||
checksum: 10c0/e5c08012560af6727fd66741c5cda25560d7c5442103d0c83e4276a9b0dd90b9da6cdf823a461195229a16c6ff87768ce788a68d0fa29dea73ee285618668178
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5598,6 +5607,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/utils@npm:4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "@vitest/utils@npm:4.1.10"
|
||||
dependencies:
|
||||
"@vitest/pretty-format": "npm:4.1.10"
|
||||
convert-source-map: "npm:^2.0.0"
|
||||
tinyrainbow: "npm:^3.1.0"
|
||||
checksum: 10c0/05b0ecec6997ec22fc08377e57dbd8fa37992e05961f3a7a916d98b1ab56d15c2a87dbd83d392b628242bdc156b1705e7fa60a3bf0c54bdb51158c153e05fc5d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@vitest/utils@npm:4.1.9":
|
||||
version: 4.1.9
|
||||
resolution: "@vitest/utils@npm:4.1.9"
|
||||
@@ -14787,17 +14807,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vitest@npm:^4.1.7":
|
||||
version: 4.1.9
|
||||
resolution: "vitest@npm:4.1.9"
|
||||
"vitest@npm:^4.1.10":
|
||||
version: 4.1.10
|
||||
resolution: "vitest@npm:4.1.10"
|
||||
dependencies:
|
||||
"@vitest/expect": "npm:4.1.9"
|
||||
"@vitest/mocker": "npm:4.1.9"
|
||||
"@vitest/pretty-format": "npm:4.1.9"
|
||||
"@vitest/runner": "npm:4.1.9"
|
||||
"@vitest/snapshot": "npm:4.1.9"
|
||||
"@vitest/spy": "npm:4.1.9"
|
||||
"@vitest/utils": "npm:4.1.9"
|
||||
"@vitest/expect": "npm:4.1.10"
|
||||
"@vitest/mocker": "npm:4.1.10"
|
||||
"@vitest/pretty-format": "npm:4.1.10"
|
||||
"@vitest/runner": "npm:4.1.10"
|
||||
"@vitest/snapshot": "npm:4.1.10"
|
||||
"@vitest/spy": "npm:4.1.10"
|
||||
"@vitest/utils": "npm:4.1.10"
|
||||
es-module-lexer: "npm:^2.0.0"
|
||||
expect-type: "npm:^1.3.0"
|
||||
magic-string: "npm:^0.30.21"
|
||||
@@ -14815,12 +14835,12 @@ __metadata:
|
||||
"@edge-runtime/vm": "*"
|
||||
"@opentelemetry/api": ^1.9.0
|
||||
"@types/node": ^20.0.0 || ^22.0.0 || >=24.0.0
|
||||
"@vitest/browser-playwright": 4.1.9
|
||||
"@vitest/browser-preview": 4.1.9
|
||||
"@vitest/browser-webdriverio": 4.1.9
|
||||
"@vitest/coverage-istanbul": 4.1.9
|
||||
"@vitest/coverage-v8": 4.1.9
|
||||
"@vitest/ui": 4.1.9
|
||||
"@vitest/browser-playwright": 4.1.10
|
||||
"@vitest/browser-preview": 4.1.10
|
||||
"@vitest/browser-webdriverio": 4.1.10
|
||||
"@vitest/coverage-istanbul": 4.1.10
|
||||
"@vitest/coverage-v8": 4.1.10
|
||||
"@vitest/ui": 4.1.10
|
||||
happy-dom: "*"
|
||||
jsdom: "*"
|
||||
vite: ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
@@ -14851,7 +14871,7 @@ __metadata:
|
||||
optional: false
|
||||
bin:
|
||||
vitest: ./vitest.mjs
|
||||
checksum: 10c0/1ac80ef4991be82822a52aea48415f1bc64ddf8fd88ee24c172ec368f1d480fefacbde622c3c951982f7961a1d07313e18deaafc774d29e42ad6f6ffa63334a7
|
||||
checksum: 10c0/ff07294a57f9c62f3b503f7cf88a52ee0753ed26389a49cda430387a3898f39d80af47180b0af19e27acab5bd11ae95706bd4b44ce8befc97d3ae49af6ca4fc1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in new issue
Block a user