Merge branch 'cleanup' into 'develop'

Use Array.includes instead of indexOf

See merge request soapbox-pub/soapbox-fe!1727
environments/review-develop-3zknud/deployments/774
marcin mikołajczak 2022-08-12 22:07:19 +00:00
commit 67f5f5fb8b
11 zmienionych plików z 16 dodań i 16 usunięć

Wyświetl plik

@ -37,7 +37,7 @@ if (!HTMLCanvasElement.prototype.toBlob) {
const dataURL = this.toDataURL(type, quality); const dataURL = this.toDataURL(type, quality);
let data; let data;
if (dataURL.indexOf(BASE64_MARKER) >= 0) { if (dataURL.includes(BASE64_MARKER)) {
const [, base64] = dataURL.split(BASE64_MARKER); const [, base64] = dataURL.split(BASE64_MARKER);
data = decodeBase64(base64); data = decodeBase64(base64);
} else { } else {

Wyświetl plik

@ -30,7 +30,7 @@ const textAtCursorMatchesToken = (str: string, caretPosition: number, searchToke
word = str.slice(left, right + caretPosition); word = str.slice(left, right + caretPosition);
} }
if (!word || word.trim().length < 3 || searchTokens.indexOf(word[0]) === -1) { if (!word || word.trim().length < 3 || !searchTokens.includes(word[0])) {
return [null, null]; return [null, null];
} }

Wyświetl plik

@ -23,7 +23,7 @@ const textAtCursorMatchesToken = (str: string, caretPosition: number) => {
word = str.slice(left, right + caretPosition); word = str.slice(left, right + caretPosition);
} }
if (!word || word.trim().length < 3 || ['@', ':', '#'].indexOf(word[0]) === -1) { if (!word || word.trim().length < 3 || !['@', ':', '#'].includes(word[0])) {
return [null, null]; return [null, null];
} }

Wyświetl plik

@ -38,7 +38,7 @@ const MediaItem: React.FC<IMediaItem> = ({ attachment, displayWidth, onOpenMedia
}; };
const hoverToPlay = () => { const hoverToPlay = () => {
return !autoPlayGif && ['gifv', 'video'].indexOf(attachment.type) !== -1; return !autoPlayGif && ['gifv', 'video'].includes(attachment.type);
}; };
const handleClick: React.MouseEventHandler = e => { const handleClick: React.MouseEventHandler = e => {

Wyświetl plik

@ -85,8 +85,8 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude
pool = {}; pool = {};
data.categories.forEach(category => { data.categories.forEach(category => {
const isIncluded = include && include.length ? include.indexOf(category.name.toLowerCase()) > -1 : true; const isIncluded = include && include.length ? include.includes(category.name.toLowerCase()) : true;
const isExcluded = exclude && exclude.length ? exclude.indexOf(category.name.toLowerCase()) > -1 : false; const isExcluded = exclude && exclude.length ? exclude.includes(category.name.toLowerCase()) : false;
if (!isIncluded || isExcluded) { if (!isIncluded || isExcluded) {
return; return;
} }
@ -95,8 +95,8 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude
}); });
if (custom.length) { if (custom.length) {
const customIsIncluded = include && include.length ? include.indexOf('custom') > -1 : true; const customIsIncluded = include && include.length ? include.includes('custom') : true;
const customIsExcluded = exclude && exclude.length ? exclude.indexOf('custom') > -1 : false; const customIsExcluded = exclude && exclude.length ? exclude.includes('custom') : false;
if (customIsIncluded && !customIsExcluded) { if (customIsIncluded && !customIsExcluded) {
addCustomToPool(custom, pool); addCustomToPool(custom, pool);
} }

Wyświetl plik

@ -15,7 +15,7 @@ const buildSearch = (data) => {
(split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => { (split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => {
s = s.toLowerCase(); s = s.toLowerCase();
if (search.indexOf(s) === -1) { if (!search.includes(s)) {
search.push(s); search.push(s);
} }
}); });
@ -190,7 +190,7 @@ function getData(emoji, skin, set) {
function uniq(arr) { function uniq(arr) {
return arr.reduce((acc, item) => { return arr.reduce((acc, item) => {
if (acc.indexOf(item) === -1) { if (!acc.includes(item)) {
acc.push(item); acc.push(item);
} }
return acc; return acc;
@ -201,7 +201,7 @@ function intersect(a, b) {
const uniqA = uniq(a); const uniqA = uniq(a);
const uniqB = uniq(b); const uniqB = uniq(b);
return uniqA.filter(item => uniqB.indexOf(item) >= 0); return uniqA.filter(item => uniqB.includes(item));
} }
function deepMerge(a, b) { function deepMerge(a, b) {

Wyświetl plik

@ -26,7 +26,7 @@ const addAutoPlay = (html: string): string => {
const iframe = document.querySelector('iframe'); const iframe = document.querySelector('iframe');
if (iframe) { if (iframe) {
if (iframe.src.indexOf('?') !== -1) { if (iframe.src.includes('?')) {
iframe.src += '&'; iframe.src += '&';
} else { } else {
iframe.src += '?'; iframe.src += '?';

Wyświetl plik

@ -92,7 +92,7 @@ export default class ModalRoot extends React.PureComponent {
} }
renderLoading = modalId => () => { renderLoading = modalId => () => {
return ['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null; return !['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].includes(modalId) ? <ModalLoading /> : null;
} }
renderError = (props) => { renderError = (props) => {

Wyświetl plik

@ -28,7 +28,7 @@ const UserPanel: React.FC<IUserPanel> = ({ accountId, action, badges, domain })
if (!account) return null; if (!account) return null;
const displayNameHtml = { __html: account.get('display_name_html') }; const displayNameHtml = { __html: account.get('display_name_html') };
const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct'); const acct = !account.get('acct').includes('@') && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
const header = account.get('header'); const header = account.get('header');
const verified = account.get('verified'); const verified = account.get('verified');

Wyświetl plik

@ -352,7 +352,7 @@ const UI: React.FC = ({ children }) => {
const handleDragEnter = (e: DragEvent) => { const handleDragEnter = (e: DragEvent) => {
e.preventDefault(); e.preventDefault();
if (e.target && dragTargets.current.indexOf(e.target) === -1) { if (e.target && !dragTargets.current.includes(e.target)) {
dragTargets.current.push(e.target); dragTargets.current.push(e.target);
} }

Wyświetl plik

@ -93,7 +93,7 @@ const toServerSideType = (columnType: string): string => {
case 'thread': case 'thread':
return columnType; return columnType;
default: default:
if (columnType.indexOf('list:') > -1) { if (columnType.includes('list:')) {
return 'home'; return 'home';
} else { } else {
return 'public'; // community, account, hashtag return 'public'; // community, account, hashtag