From e652ce8d9ba688e6fa0f7e7048e25c457b158f70 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 4 Dec 2024 14:47:15 +0800 Subject: [PATCH] Include Prettier & format everything properly My bad for not including prettier --- package-lock.json | 13 +++--- package.json | 1 + src/app.jsx | 67 +++++++++++++++------------- src/components/compose.jsx | 46 +++++++++---------- src/components/menu2.jsx | 4 +- src/components/notification.jsx | 16 +++---- src/components/status.jsx | 24 +++++----- src/components/translation-block.jsx | 12 ++--- src/compose.jsx | 8 ++-- src/locales/en.po | 42 ++++++++--------- src/pages/annual-report.jsx | 22 +++++---- src/pages/catchup.jsx | 12 ++--- src/pages/hashtag.jsx | 4 +- src/pages/login.jsx | 8 ++-- src/utils/enhance-content.js | 2 +- src/utils/status-peek.js | 2 +- 16 files changed, 145 insertions(+), 138 deletions(-) diff --git a/package-lock.json b/package-lock.json index 040f1b3c..b1bcfa70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,6 +58,7 @@ "postcss": "~8.4.49", "postcss-dark-theme-class": "~1.3.0", "postcss-preset-env": "~10.1.1", + "prettier": "3.4.1", "sonda": "~0.6.1", "twitter-text": "~3.1.0", "vite": "~5.4.11", @@ -8406,17 +8407,15 @@ } }, "node_modules/prettier": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.0.tgz", - "integrity": "sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.1.tgz", + "integrity": "sha512-G+YdqtITVZmOJje6QkXQWzl3fSfMxFwm1tjTyo9exhkmWSqC4Yhd1+lug++IlR2mvRVAxEDDWYkQdeSztajqgg==", "dev": true, - "license": "MIT", - "peer": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" diff --git a/package.json b/package.json index 8ec05e59..81917824 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "postcss": "~8.4.49", "postcss-dark-theme-class": "~1.3.0", "postcss-preset-env": "~10.1.1", + "prettier": "3.4.1", "sonda": "~0.6.1", "twitter-text": "~3.1.0", "vite": "~5.4.11", diff --git a/src/app.jsx b/src/app.jsx index e4b89603..d8acfdb9 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -27,6 +27,7 @@ import SearchCommand from './components/search-command'; import Shortcuts from './components/shortcuts'; import NotFound from './pages/404'; import AccountStatuses from './pages/account-statuses'; +import AnnualReport from './pages/annual-report'; import Bookmarks from './pages/bookmarks'; import Catchup from './pages/catchup'; import Favourites from './pages/favourites'; @@ -46,7 +47,6 @@ import Search from './pages/search'; import StatusRoute from './pages/status-route'; import Trending from './pages/trending'; import Welcome from './pages/welcome'; -import AnnualReport from './pages/annual-report'; import { api, hasInstance, @@ -99,39 +99,42 @@ window.__STATES_STATS__ = () => { // Experimental "garbage collection" for states // Every 15 minutes // Only posts for now -setInterval(() => { - if (!window.__IDLE__) return; - const { statuses, unfurledLinks, notifications } = states; - let keysCount = 0; - const { instance } = api(); - for (const key in statuses) { - if (!window.__IDLE__) break; - try { - const $post = document.querySelector( - `[data-state-post-id~="${key}"], [data-state-post-ids~="${key}"]`, - ); - const postInNotifications = notifications.some( - (n) => key === statusKey(n.status?.id, instance), - ); - if (!$post && !postInNotifications) { - delete states.statuses[key]; - delete states.statusQuotes[key]; - for (const link in unfurledLinks) { - const unfurled = unfurledLinks[link]; - const sKey = statusKey(unfurled.id, unfurled.instance); - if (sKey === key) { - delete states.unfurledLinks[link]; - break; +setInterval( + () => { + if (!window.__IDLE__) return; + const { statuses, unfurledLinks, notifications } = states; + let keysCount = 0; + const { instance } = api(); + for (const key in statuses) { + if (!window.__IDLE__) break; + try { + const $post = document.querySelector( + `[data-state-post-id~="${key}"], [data-state-post-ids~="${key}"]`, + ); + const postInNotifications = notifications.some( + (n) => key === statusKey(n.status?.id, instance), + ); + if (!$post && !postInNotifications) { + delete states.statuses[key]; + delete states.statusQuotes[key]; + for (const link in unfurledLinks) { + const unfurled = unfurledLinks[link]; + const sKey = statusKey(unfurled.id, unfurled.instance); + if (sKey === key) { + delete states.unfurledLinks[link]; + break; + } } + keysCount++; } - keysCount++; - } - } catch (e) {} - } - if (keysCount) { - console.info(`GC: Removed ${keysCount} keys`); - } -}, 15 * 60 * 1000); + } catch (e) {} + } + if (keysCount) { + console.info(`GC: Removed ${keysCount} keys`); + } + }, + 15 * 60 * 1000, +); // Preload icons // There's probably a better way to do this diff --git a/src/components/compose.jsx b/src/components/compose.jsx index d25d1ed9..775fd637 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -1255,8 +1255,8 @@ function Compose({ replyToStatus ? t`Post your reply` : editStatus - ? t`Edit your post` - : t`What are you doing?` + ? t`Edit your post` + : t`What are you doing?` } required={mediaAttachments?.length === 0} disabled={uiState === 'loading'} @@ -1554,11 +1554,11 @@ function Compose({ {replyToStatus ? t`Reply` : editStatus - ? t`Update` - : t({ - message: 'Post', - context: 'Submit button in composer', - })} + ? t`Update` + : t({ + message: 'Post', + context: 'Submit button in composer', + })} @@ -2214,10 +2214,10 @@ function CharCountMeter({ maxCharacters = 500, hidden }) { leftChars <= -10 ? 'explode' : leftChars <= 0 - ? 'danger' - : leftChars <= 20 - ? 'warning' - : '' + ? 'danger' + : leftChars <= 20 + ? 'warning' + : '' }`} value={charCount} max={maxCharacters} @@ -2846,16 +2846,16 @@ function filterShortcodes(emojis, searchTerm) { return bothStartWith ? a.length - b.length : aStartsWith - ? -1 - : bStartsWith - ? 1 - : bothContain - ? a.length - b.length - : aContains - ? -1 - : bContains - ? 1 - : 0; + ? -1 + : bStartsWith + ? 1 + : bothContain + ? a.length - b.length + : aContains + ? -1 + : bContains + ? 1 + : 0; }) .slice(0, 5); } @@ -3516,8 +3516,8 @@ function GIFPickerModal({ onClose = () => {}, onSelect = () => {} }) { const theImage = fixed_height_small?.url ? fixed_height_small : fixed_height_downsampled?.url - ? fixed_height_downsampled - : fixed_height; + ? fixed_height_downsampled + : fixed_height; let { url, webp, width, height } = theImage; if (+height > 100) { width = (width / height) * 100; diff --git a/src/components/menu2.jsx b/src/components/menu2.jsx index fe79318c..0dbf2a51 100644 --- a/src/components/menu2.jsx +++ b/src/components/menu2.jsx @@ -17,8 +17,8 @@ function Menu2(props) { ? align === 'end' ? 'start' : align === 'start' - ? 'end' - : align + ? 'end' + : align : align; return ( diff --git a/src/components/notification.jsx b/src/components/notification.jsx index 6c497643..25760d28 100644 --- a/src/components/notification.jsx +++ b/src/components/notification.jsx @@ -261,9 +261,7 @@ const contentText = { ), emoji_reaction: emojiText, 'pleroma:emoji_reaction': emojiText, - annual_report: ({ year }) => ( - Your {year} #Wrapstodon is here! - ), + annual_report: ({ year }) => Your {year} #Wrapstodon is here!, }; // account_suspension, domain_block, user_domain_block @@ -537,7 +535,9 @@ function Notification({ )} {type === 'annual_report' && (
- View #Wrapstodon + + View #Wrapstodon +
)} @@ -562,8 +562,8 @@ function Notification({ _accounts.length <= 10 ? 'xxl' : _accounts.length < 20 - ? 'xl' - : 'l' + ? 'xl' + : 'l' } key={account.id} alt={`${account.displayName} @${account.acct}`} @@ -606,8 +606,8 @@ function Notification({ const type = /^favourite/.test(key) ? 'favourite' : /^reblog/.test(key) - ? 'reblog' - : null; + ? 'reblog' + : null; if (!type) continue; for (const account of _accounts) { const theAccount = accounts.find( diff --git a/src/components/status.jsx b/src/components/status.jsx index 7c251c9f..e527d39d 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -996,8 +996,8 @@ function Status({ {reblogsCount > 0 ? shortenNumber(reblogsCount) : reblogged - ? t`Unboost` - : t`Boost…`} + ? t`Unboost` + : t`Boost…`} 0 ? shortenNumber(favouritesCount) : favourited - ? t`Unlike` - : t`Like`} + ? t`Unlike` + : t`Like`} {supports('@mastodon/post-bookmark') && ( @@ -3167,8 +3167,8 @@ function generateHTMLCode(post, instance, level = 0) { } else { mediaHTML = ` 📄 ${ - description || sourceMediaURL - } + description || sourceMediaURL + } `; } @@ -3625,12 +3625,12 @@ function FilteredStatus({ quoted ? '' : isReblog - ? group - ? 'status-group' - : 'status-reblog' - : isFollowedTags - ? 'status-followed-tags' - : '' + ? group + ? 'status-group' + : 'status-reblog' + : isFollowedTags + ? 'status-followed-tags' + : '' } {...containerProps} // title={statusPeekText} diff --git a/src/components/translation-block.jsx b/src/components/translation-block.jsx index 289f689f..7e4f10ca 100644 --- a/src/components/translation-block.jsx +++ b/src/components/translation-block.jsx @@ -189,10 +189,10 @@ function TranslationBlock({ {uiState === 'loading' ? t`Translating…` : sourceLanguage && sourceLangText && !detectedLang - ? autoDetected - ? t`Translate from ${sourceLangText} (auto-detected)` - : t`Translate from ${sourceLangText}` - : t`Translate`} + ? autoDetected + ? t`Translate from ${sourceLangText} (auto-detected)` + : t`Translate from ${sourceLangText}` + : t`Translate`} @@ -221,8 +221,8 @@ function TranslationBlock({ {l.code === 'auto' ? t`Auto (${detectedLang ?? '…'})` : showCommon - ? `${native} - ${common}` - : native} + ? `${native} - ${common}` + : native} ); })} diff --git a/src/compose.jsx b/src/compose.jsx index 296c74fc..709275e7 100644 --- a/src/compose.jsx +++ b/src/compose.jsx @@ -31,10 +31,10 @@ function App() { editStatus ? t`Editing source status` : replyToStatus - ? t`Replying to @${ - replyToStatus.account?.acct || replyToStatus.account?.username - }` - : t`Compose`, + ? t`Replying to @${ + replyToStatus.account?.acct || replyToStatus.account?.username + }` + : t`Compose`, ); useEffect(() => { diff --git a/src/locales/en.po b/src/locales/en.po index 06003a63..71c7c12a 100644 --- a/src/locales/en.po +++ b/src/locales/en.po @@ -963,7 +963,7 @@ msgid "Nothing to show" msgstr "" #: src/components/generic-accounts.jsx:145 -#: src/components/notification.jsx:446 +#: src/components/notification.jsx:444 #: src/pages/accounts.jsx:41 #: src/pages/search.jsx:317 #: src/pages/search.jsx:350 @@ -1472,78 +1472,78 @@ msgstr "" msgid "Moderation warning" msgstr "" -#: src/components/notification.jsx:265 +#: src/components/notification.jsx:264 msgid "Your {year} #Wrapstodon is here!" msgstr "Your {year} #Wrapstodon is here!" -#: src/components/notification.jsx:272 +#: src/components/notification.jsx:270 msgid "An admin from <0>{from} has suspended <1>{targetName}, which means you can no longer receive updates from them or interact with them." msgstr "" -#: src/components/notification.jsx:278 +#: src/components/notification.jsx:276 msgid "An admin from <0>{from} has blocked <1>{targetName}. Affected followers: {followersCount}, followings: {followingCount}." msgstr "" -#: src/components/notification.jsx:284 +#: src/components/notification.jsx:282 msgid "You have blocked <0>{targetName}. Removed followers: {followersCount}, followings: {followingCount}." msgstr "" -#: src/components/notification.jsx:292 +#: src/components/notification.jsx:290 msgid "Your account has received a moderation warning." msgstr "" -#: src/components/notification.jsx:293 +#: src/components/notification.jsx:291 msgid "Your account has been disabled." msgstr "" -#: src/components/notification.jsx:294 +#: src/components/notification.jsx:292 msgid "Some of your posts have been marked as sensitive." msgstr "" -#: src/components/notification.jsx:295 +#: src/components/notification.jsx:293 msgid "Some of your posts have been deleted." msgstr "" -#: src/components/notification.jsx:296 +#: src/components/notification.jsx:294 msgid "Your posts will be marked as sensitive from now on." msgstr "" -#: src/components/notification.jsx:297 +#: src/components/notification.jsx:295 msgid "Your account has been limited." msgstr "" -#: src/components/notification.jsx:298 +#: src/components/notification.jsx:296 msgid "Your account has been suspended." msgstr "" -#: src/components/notification.jsx:373 +#: src/components/notification.jsx:371 msgid "[Unknown notification type: {type}]" msgstr "" -#: src/components/notification.jsx:442 +#: src/components/notification.jsx:440 #: src/components/status.jsx:1036 #: src/components/status.jsx:1046 msgid "Boosted/Liked by…" msgstr "" -#: src/components/notification.jsx:443 +#: src/components/notification.jsx:441 msgid "Liked by…" msgstr "" -#: src/components/notification.jsx:444 +#: src/components/notification.jsx:442 msgid "Boosted by…" msgstr "" -#: src/components/notification.jsx:445 +#: src/components/notification.jsx:443 msgid "Followed by…" msgstr "" -#: src/components/notification.jsx:516 -#: src/components/notification.jsx:532 +#: src/components/notification.jsx:514 +#: src/components/notification.jsx:530 msgid "Learn more <0/>" msgstr "" -#: src/components/notification.jsx:540 +#: src/components/notification.jsx:539 msgid "View #Wrapstodon" msgstr "View #Wrapstodon" @@ -2410,7 +2410,7 @@ msgid "Login required." msgstr "Login required." #: src/compose.jsx:90 -#: src/pages/annual-report.jsx:132 +#: src/pages/annual-report.jsx:136 #: src/pages/http-route.jsx:91 #: src/pages/login.jsx:270 msgid "Go home" diff --git a/src/pages/annual-report.jsx b/src/pages/annual-report.jsx index ab7d1c75..ee71ef40 100644 --- a/src/pages/annual-report.jsx +++ b/src/pages/annual-report.jsx @@ -64,7 +64,8 @@ export default function AnnualReport() { {Object.entries(item).map(([k, value]) => ( - {value && /(accountId)/i.test(k) && + {value && + /(accountId)/i.test(k) && /^(mostRebloggedAccounts|commonlyInteractedWithAccounts)$/i.test( key, ) ? ( @@ -90,14 +91,17 @@ export default function AnnualReport() { <>
{k}
- {value && - - s.id === value)} - size="s" - readOnly - /> - } + {value && ( + + s.id === value, + )} + size="s" + readOnly + /> + + )}
))} diff --git a/src/pages/catchup.jsx b/src/pages/catchup.jsx index 1c0f7c5a..1af5aad2 100644 --- a/src/pages/catchup.jsx +++ b/src/pages/catchup.jsx @@ -1730,10 +1730,10 @@ const PostLine = memo( group ? 'group' : reblog - ? 'reblog' - : isFollowedTags?.length - ? 'followed-tags' - : '' + ? 'reblog' + : isFollowedTags?.length + ? 'followed-tags' + : '' } ${isReplyTo ? 'reply-to' : ''} ${ isFiltered ? 'filtered' : '' } visibility-${visibility}`} @@ -1826,8 +1826,8 @@ function postDensity(post) { (mediaAttachments?.length ? MEDIA_DENSITY * mediaAttachments.length : card?.image - ? CARD_DENSITY - : 0); + ? CARD_DENSITY + : 0); return density; } diff --git a/src/pages/hashtag.jsx b/src/pages/hashtag.jsx index ae901bdf..8a9ca319 100644 --- a/src/pages/hashtag.jsx +++ b/src/pages/hashtag.jsx @@ -55,8 +55,8 @@ function Hashtags({ media: mediaView, columnMode, ...props }) { ? t`${hashtagTitle} (Media only) on ${instance}` : t`${hashtagTitle} on ${instance}` : media - ? t`${hashtagTitle} (Media only)` - : t`${hashtagTitle}`; + ? t`${hashtagTitle} (Media only)` + : t`${hashtagTitle}`; useTitle(title, `/:instance?/t/:hashtag`); const latestItem = useRef(); diff --git a/src/pages/login.jsx b/src/pages/login.jsx index 32b25e6f..b0f339e4 100644 --- a/src/pages/login.jsx +++ b/src/pages/login.jsx @@ -152,10 +152,10 @@ function Login() { const selectedInstanceText = instanceTextLooksLikeDomain ? cleanInstanceText : instancesSuggestions?.length - ? instancesSuggestions[0] - : instanceText - ? instancesList.find((instance) => instance.includes(instanceText)) - : null; + ? instancesSuggestions[0] + : instanceText + ? instancesList.find((instance) => instance.includes(instanceText)) + : null; const onSubmit = (e) => { e.preventDefault(); diff --git a/src/utils/enhance-content.js b/src/utils/enhance-content.js index dc65480d..70e92e38 100644 --- a/src/utils/enhance-content.js +++ b/src/utils/enhance-content.js @@ -13,7 +13,7 @@ function escapeHTML(html) { '&': '&', '<': '<', '>': '>', - }[c]), + })[c], ); } diff --git a/src/utils/status-peek.js b/src/utils/status-peek.js index 9a9388e4..cd2ba645 100644 --- a/src/utils/status-peek.js +++ b/src/utils/status-peek.js @@ -26,7 +26,7 @@ function statusPeek(status) { video: '📹', audio: '🎵', unknown: '', - }[m.type] || ''), + })[m.type] || '', ) .join(''); }