Skip to content

Commit

Permalink
Merge pull request #2681 from ClearlyClaire/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes up to d702a03
  • Loading branch information
ClearlyClaire authored Mar 16, 2024
2 parents 6ee7a64 + c511e52 commit ada2ac4
Show file tree
Hide file tree
Showing 60 changed files with 2,167 additions and 1,232 deletions.
25 changes: 0 additions & 25 deletions app/javascript/core/embed.js

This file was deleted.

41 changes: 41 additions & 0 deletions app/javascript/core/embed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file will be loaded on embed pages, regardless of theme.

import 'packs/public-path';
import ready from '../mastodon/ready';

interface SetHeightMessage {
type: 'setHeight';
id: string;
height: number;
}

function isSetHeightMessage(data: unknown): data is SetHeightMessage {
if (
data &&
typeof data === 'object' &&
'type' in data &&
data.type === 'setHeight'
)
return true;
else return false;
}

window.addEventListener('message', (e) => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- typings are not correct, it can be null in very rare cases
if (!e.data || !isSetHeightMessage(e.data) || !window.parent) return;

const data = e.data;

ready(() => {
window.parent.postMessage(
{
type: 'setHeight',
id: data.id,
height: document.getElementsByTagName('html')[0].scrollHeight,
},
'*',
);
}).catch((e) => {
console.error('Error in setHeightMessage postMessage', e);
});
});
44 changes: 0 additions & 44 deletions app/javascript/core/settings.js

This file was deleted.

70 changes: 70 additions & 0 deletions app/javascript/core/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// This file will be loaded on settings pages, regardless of theme.

import 'packs/public-path';
import Rails from '@rails/ujs';

Rails.delegate(
document,
'#edit_profile input[type=file]',
'change',
({ target }) => {
if (!(target instanceof HTMLInputElement)) return;

const avatar = document.querySelector<HTMLImageElement>(
`img#${target.id}-preview`,
);

if (!avatar) return;

let file: File | undefined;
if (target.files) file = target.files[0];

const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc;

if (url) avatar.src = url;
},
);

Rails.delegate(document, '.input-copy input', 'click', ({ target }) => {
if (!(target instanceof HTMLInputElement)) return;

target.focus();
target.select();
target.setSelectionRange(0, target.value.length);
});

Rails.delegate(document, '.input-copy button', 'click', ({ target }) => {
if (!(target instanceof HTMLButtonElement)) return;

const input = target.parentNode?.querySelector<HTMLInputElement>(
'.input-copy__wrapper input',
);

if (!input) return;

const oldReadOnly = input.readOnly;

input.readOnly = false;
input.focus();
input.select();
input.setSelectionRange(0, input.value.length);

try {
if (document.execCommand('copy')) {
input.blur();

const parent = target.parentElement;

if (!parent) return;
parent.classList.add('copied');

setTimeout(() => {
parent.classList.remove('copied');
}, 700);
}
} catch (err) {
console.error(err);
}

input.readOnly = oldReadOnly;
});
4 changes: 2 additions & 2 deletions app/javascript/core/theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pack:
common:
filename: common.js
stylesheet: true
embed: embed.js
embed: embed.ts
error:
home:
inert:
Expand All @@ -18,7 +18,7 @@ pack:
stylesheet: true
modal:
public:
settings: settings.js
settings: settings.ts
sign_up:
share:
remote_interaction_helper: remote_interaction_helper.ts
15 changes: 7 additions & 8 deletions app/javascript/flavours/glitch/actions/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const BLOCKS_EXPAND_REQUEST = 'BLOCKS_EXPAND_REQUEST';
export const BLOCKS_EXPAND_SUCCESS = 'BLOCKS_EXPAND_SUCCESS';
export const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL';

export const BLOCKS_INIT_MODAL = 'BLOCKS_INIT_MODAL';

export function fetchBlocks() {
return (dispatch, getState) => {
dispatch(fetchBlocksRequest());
Expand Down Expand Up @@ -90,11 +88,12 @@ export function expandBlocksFail(error) {

export function initBlockModal(account) {
return dispatch => {
dispatch({
type: BLOCKS_INIT_MODAL,
account,
});

dispatch(openModal({ modalType: 'BLOCK' }));
dispatch(openModal({
modalType: 'BLOCK',
modalProps: {
accountId: account.get('id'),
acct: account.get('acct'),
},
}));
};
}
11 changes: 11 additions & 0 deletions app/javascript/flavours/glitch/actions/domain_blocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import api, { getLinks } from '../api';

import { blockDomainSuccess, unblockDomainSuccess } from "./domain_blocks_typed";
import { openModal } from './modal';


export * from "./domain_blocks_typed";

Expand Down Expand Up @@ -150,3 +152,12 @@ export function expandDomainBlocksFail(error) {
error,
};
}

export const initDomainBlockModal = account => dispatch => dispatch(openModal({
modalType: 'DOMAIN_BLOCK',
modalProps: {
domain: account.get('acct').split('@')[1],
acct: account.get('acct'),
accountId: account.get('id'),
},
}));
32 changes: 7 additions & 25 deletions app/javascript/flavours/glitch/actions/mutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export const MUTES_EXPAND_REQUEST = 'MUTES_EXPAND_REQUEST';
export const MUTES_EXPAND_SUCCESS = 'MUTES_EXPAND_SUCCESS';
export const MUTES_EXPAND_FAIL = 'MUTES_EXPAND_FAIL';

export const MUTES_INIT_MODAL = 'MUTES_INIT_MODAL';
export const MUTES_TOGGLE_HIDE_NOTIFICATIONS = 'MUTES_TOGGLE_HIDE_NOTIFICATIONS';
export const MUTES_CHANGE_DURATION = 'MUTES_CHANGE_DURATION';

export function fetchMutes() {
return (dispatch, getState) => {
dispatch(fetchMutesRequest());
Expand Down Expand Up @@ -92,26 +88,12 @@ export function expandMutesFail(error) {

export function initMuteModal(account) {
return dispatch => {
dispatch({
type: MUTES_INIT_MODAL,
account,
});

dispatch(openModal({ modalType: 'MUTE' }));
};
}

export function toggleHideNotifications() {
return dispatch => {
dispatch({ type: MUTES_TOGGLE_HIDE_NOTIFICATIONS });
};
}

export function changeMuteDuration(duration) {
return dispatch => {
dispatch({
type: MUTES_CHANGE_DURATION,
duration,
});
dispatch(openModal({
modalType: 'MUTE',
modalProps: {
accountId: account.get('id'),
acct: account.get('acct'),
},
}));
};
}
39 changes: 39 additions & 0 deletions app/javascript/flavours/glitch/components/check_box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import classNames from 'classnames';

import DoneIcon from '@/material-icons/400-24px/done.svg?react';

import { Icon } from './icon';

interface Props {
value: string;
checked: boolean;
name: string;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
label: React.ReactNode;
}

export const CheckBox: React.FC<Props> = ({
name,
value,
checked,
onChange,
label,
}) => {
return (
<label className='check-box'>
<input
name={name}
type='checkbox'
value={value}
checked={checked}
onChange={onChange}
/>

<span className={classNames('check-box__input', { checked })}>
{checked && <Icon id='check' icon={DoneIcon} />}
</span>

<span>{label}</span>
</label>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const getUnitDelay = (units: string) => {
};

export const timeAgoString = (
intl: IntlShape,
intl: Pick<IntlShape, 'formatDate' | 'formatMessage'>,
date: Date,
now: number,
year: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ class Header extends ImmutablePureComponent {
};

handleBlockDomain = () => {
const domain = this.props.account.get('acct').split('@')[1];

if (!domain) return;

this.props.onBlockDomain(domain);
this.props.onBlockDomain(this.props.account);
};

handleUnblockDomain = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
mentionCompose,
directCompose,
} from '../../../actions/compose';
import { blockDomain, unblockDomain } from '../../../actions/domain_blocks';
import { initDomainBlockModal, unblockDomain } from '../../../actions/domain_blocks';
import { openModal } from '../../../actions/modal';
import { initMuteModal } from '../../../actions/mutes';
import { initReport } from '../../../actions/reports';
Expand Down Expand Up @@ -138,15 +138,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}
},

onBlockDomain (domain) {
dispatch(openModal({
modalType: 'CONFIRM',
modalProps: {
message: <FormattedMessage id='confirmations.domain_block.message' defaultMessage='Are you really, really sure you want to block the entire {domain}? In most cases a few targeted blocks or mutes are sufficient and preferable. You will not see content from that domain in any public timelines or your notifications. Your followers from that domain will be removed.' values={{ domain: <strong>{domain}</strong> }} />,
confirm: intl.formatMessage(messages.blockDomainConfirm),
onConfirm: () => dispatch(blockDomain(domain)),
},
}));
onBlockDomain (account) {
dispatch(initDomainBlockModal(account));
},

onUnblockDomain (domain) {
Expand Down
Loading

0 comments on commit ada2ac4

Please sign in to comment.