diff --git a/src/components/related-actions.jsx b/src/components/related-actions.jsx index f1e0863f..1f78202a 100644 --- a/src/components/related-actions.jsx +++ b/src/components/related-actions.jsx @@ -6,6 +6,7 @@ import punycode from 'punycode/'; import { api } from '../utils/api'; import i18nDuration from '../utils/i18n-duration'; +import isSearchEnabled from '../utils/is-search-enabled'; import niceDateTime from '../utils/nice-date-time'; import showCompose from '../utils/show-compose'; import showToast from '../utils/show-toast'; @@ -173,6 +174,15 @@ function RelatedActions({ const [showAddRemoveLists, setShowAddRemoveLists] = useState(false); const [showPrivateNoteModal, setShowPrivateNoteModal] = useState(false); const [lists, setLists] = useState([]); + const [searchEnabled, setSearchEnabled] = useState(false); + + useEffect(() => { + if (!currentAuthenticated) return; + (async () => { + const enabled = await isSearchEnabled(currentInstance); + setSearchEnabled(enabled); + })(); + }, [currentInstance, currentAuthenticated]); let { headerStatic, avatarStatic } = info; if (!headerStatic || /missing\.png$/.test(headerStatic)) { @@ -298,6 +308,21 @@ function RelatedActions({ + {searchEnabled && ( + { + states.showSearchCommand = { query: `from:${acct} ` }; + }} + > + + + + Search @{username}'s + posts + + + + )} { setShowTranslatedBio(true); @@ -470,16 +495,32 @@ function RelatedActions({ ) : ( - supportsEndorsements && - !renderEndorsements && ( - <> - setRenderEndorsements(true)}> - - Show featured profiles + <> + {searchEnabled && isSelf && ( + { + states.showSearchCommand = { query: 'from:me ' }; + }} + > + + + Search my posts + + )} + {supportsEndorsements && !renderEndorsements && ( + <> + setRenderEndorsements(true)}> + + Show featured profiles + + + )} + {((searchEnabled && isSelf) || + (supportsEndorsements && !renderEndorsements)) && ( - - ) + )} + )} { diff --git a/src/components/search-command.jsx b/src/components/search-command.jsx index 50f7bdb1..6d6d318f 100644 --- a/src/components/search-command.jsx +++ b/src/components/search-command.jsx @@ -1,15 +1,33 @@ import './search-command.css'; import { memo } from 'preact/compat'; -import { useRef, useState } from 'preact/hooks'; +import { useEffect, useRef, useState } from 'preact/hooks'; import { useHotkeys } from 'react-hotkeys-hook'; +import { useSnapshot } from 'valtio'; + +import states from '../utils/states'; import SearchForm from './search-form'; export default memo(function SearchCommand({ onClose = () => {} }) { + const snapStates = useSnapshot(states); const [showSearch, setShowSearch] = useState(false); const searchFormRef = useRef(null); + useEffect(() => { + if (snapStates.showSearchCommand) { + const { query } = snapStates.showSearchCommand; + setShowSearch(true); + setTimeout(() => { + if (query) { + searchFormRef.current?.setValue?.(query); + } + searchFormRef.current?.focus?.(); + }, 150); + states.showSearchCommand = false; + } + }, [snapStates.showSearchCommand]); + useHotkeys( ['Slash', '/'], (e) => { diff --git a/src/locales/en.po b/src/locales/en.po index fb6be918..a88a13c1 100644 --- a/src/locales/en.po +++ b/src/locales/en.po @@ -43,17 +43,17 @@ msgid "Mutual" msgstr "" #: src/components/account-block.jsx:191 -#: src/components/related-actions.jsx:921 +#: src/components/related-actions.jsx:962 msgid "Requested" msgstr "" #: src/components/account-block.jsx:195 -#: src/components/related-actions.jsx:912 +#: src/components/related-actions.jsx:953 msgid "Following" msgstr "" #: src/components/account-block.jsx:199 -#: src/components/related-actions.jsx:190 +#: src/components/related-actions.jsx:200 msgid "Follows you" msgstr "" @@ -98,23 +98,23 @@ msgid "<0>{displayName} has indicated that their new account is now:" msgstr "<0>{displayName} has indicated that their new account is now:" #: src/components/account-info.jsx:607 -#: src/components/related-actions.jsx:489 +#: src/components/related-actions.jsx:530 msgid "Handle copied" msgstr "Handle copied" #: src/components/account-info.jsx:610 -#: src/components/related-actions.jsx:492 +#: src/components/related-actions.jsx:533 msgid "Unable to copy handle" msgstr "Unable to copy handle" #: src/components/account-info.jsx:616 -#: src/components/related-actions.jsx:498 +#: src/components/related-actions.jsx:539 msgid "Copy handle" msgstr "" #: src/components/account-info.jsx:634 -#: src/components/related-actions.jsx:245 -#: src/components/related-actions.jsx:563 +#: src/components/related-actions.jsx:255 +#: src/components/related-actions.jsx:604 #: src/components/shortcuts-settings.jsx:1083 msgid "QR code" msgstr "QR code" @@ -133,7 +133,7 @@ msgstr "View profile header" #: src/components/account-info.jsx:692 #: src/components/edit-profile-sheet.jsx:94 -#: src/components/related-actions.jsx:815 +#: src/components/related-actions.jsx:856 msgid "Edit profile" msgstr "" @@ -291,8 +291,8 @@ msgid "Close" msgstr "" #: src/components/add-remove-lists-sheet.jsx:50 -#: src/components/related-actions.jsx:455 -#: src/components/related-actions.jsx:465 +#: src/components/related-actions.jsx:480 +#: src/components/related-actions.jsx:490 msgid "Add/Remove from Lists" msgstr "" @@ -709,7 +709,7 @@ msgid "Poll" msgstr "" #: src/components/drafts.jsx:266 -#: src/pages/account-statuses.jsx:376 +#: src/pages/account-statuses.jsx:366 msgid "Media" msgstr "" @@ -1150,13 +1150,13 @@ msgstr "" #: src/components/media-alt-modal.jsx:55 #: src/components/media-attachment.jsx:430 #: src/components/media-modal.jsx:372 -#: src/components/related-actions.jsx:263 +#: src/components/related-actions.jsx:273 #: src/components/status.jsx:2167 #: src/components/status.jsx:2184 #: src/components/status.jsx:2317 #: src/components/status.jsx:3040 #: src/components/status.jsx:3043 -#: src/pages/account-statuses.jsx:544 +#: src/pages/account-statuses.jsx:559 #: src/pages/accounts.jsx:127 #: src/pages/hashtag.jsx:203 #: src/pages/list.jsx:171 @@ -1427,7 +1427,7 @@ msgid "Followed Hashtags" msgstr "" #: src/components/nav-menu.jsx:273 -#: src/pages/account-statuses.jsx:342 +#: src/pages/account-statuses.jsx:332 #: src/pages/filters.jsx:55 #: src/pages/filters.jsx:94 #: src/pages/hashtag.jsx:344 @@ -1668,13 +1668,13 @@ msgid "Read more →" msgstr "" #: src/components/open-link-sheet.jsx:30 -#: src/components/related-actions.jsx:515 +#: src/components/related-actions.jsx:556 #: src/components/status.jsx:1476 msgid "Link copied" msgstr "" #: src/components/open-link-sheet.jsx:33 -#: src/components/related-actions.jsx:518 +#: src/components/related-actions.jsx:559 #: src/components/status.jsx:1479 msgid "Unable to copy link" msgstr "" @@ -1685,14 +1685,14 @@ msgstr "Open link?" #: src/components/open-link-sheet.jsx:78 #: src/components/post-embed-modal.jsx:232 -#: src/components/related-actions.jsx:524 +#: src/components/related-actions.jsx:565 #: src/components/shortcuts-settings.jsx:1159 #: src/components/status.jsx:1485 msgid "Copy" msgstr "" #: src/components/open-link-sheet.jsx:82 -#: src/components/related-actions.jsx:545 +#: src/components/related-actions.jsx:586 #: src/components/status.jsx:1507 msgid "Share…" msgstr "" @@ -1823,7 +1823,7 @@ msgid "Note: This preview is lightly styled." msgstr "" #: src/components/private-note-sheet.jsx:41 -#: src/components/related-actions.jsx:222 +#: src/components/related-actions.jsx:232 msgid "Notes" msgstr "Notes" @@ -1912,195 +1912,204 @@ msgid "Clear all" msgstr "Clear all" #: src/components/recent-searches.jsx:94 -#: src/pages/account-statuses.jsx:335 +#: src/pages/account-statuses.jsx:325 msgid "Clear" msgstr "" -#: src/components/related-actions.jsx:39 +#: src/components/related-actions.jsx:40 msgid "Forever" msgstr "" #. placeholder {0}: niceDateTime(lastStatusAt, { hideTime: true, }) -#: src/components/related-actions.jsx:194 +#: src/components/related-actions.jsx:204 msgid "Last post: <0>{0}" msgstr "" -#: src/components/related-actions.jsx:208 +#: src/components/related-actions.jsx:218 msgid "Muted" msgstr "" -#: src/components/related-actions.jsx:213 +#: src/components/related-actions.jsx:223 msgid "Blocked" msgstr "" -#: src/components/related-actions.jsx:296 +#: src/components/related-actions.jsx:306 msgid "Mention <0>@{username}" msgstr "" -#: src/components/related-actions.jsx:308 +#: src/components/related-actions.jsx:319 +msgid "Search <0>@{username}'s posts" +msgstr "Search <0>@{username}'s posts" + +#: src/components/related-actions.jsx:333 msgid "Translate bio" msgstr "" -#: src/components/related-actions.jsx:318 +#: src/components/related-actions.jsx:343 msgid "Edit notes" msgstr "Edit notes" -#: src/components/related-actions.jsx:318 +#: src/components/related-actions.jsx:343 msgid "Add notes" msgstr "Add notes" -#: src/components/related-actions.jsx:337 +#: src/components/related-actions.jsx:362 msgid "Notifications enabled for @{username}'s posts." msgstr "Notifications enabled for @{username}'s posts." -#: src/components/related-actions.jsx:338 +#: src/components/related-actions.jsx:363 msgid " Notifications disabled for @{username}'s posts." msgstr " Notifications disabled for @{username}'s posts." -#: src/components/related-actions.jsx:350 +#: src/components/related-actions.jsx:375 msgid "Disable notifications" msgstr "Disable notifications" -#: src/components/related-actions.jsx:351 +#: src/components/related-actions.jsx:376 msgid "Enable notifications" msgstr "Enable notifications" -#: src/components/related-actions.jsx:368 +#: src/components/related-actions.jsx:393 msgid "Boosts from @{username} enabled." msgstr "Boosts from @{username} enabled." -#: src/components/related-actions.jsx:369 +#: src/components/related-actions.jsx:394 msgid "Boosts from @{username} disabled." msgstr "Boosts from @{username} disabled." -#: src/components/related-actions.jsx:380 +#: src/components/related-actions.jsx:405 msgid "Disable boosts" msgstr "Disable boosts" -#: src/components/related-actions.jsx:380 +#: src/components/related-actions.jsx:405 msgid "Enable boosts" msgstr "Enable boosts" -#: src/components/related-actions.jsx:399 +#: src/components/related-actions.jsx:424 msgid "@{username} is no longer featured on your profile." msgstr "@{username} is no longer featured on your profile." -#: src/components/related-actions.jsx:409 +#: src/components/related-actions.jsx:434 msgid "@{username} is now featured on your profile." msgstr "@{username} is now featured on your profile." -#: src/components/related-actions.jsx:417 +#: src/components/related-actions.jsx:442 msgid "Unable to unfeature @{username} on your profile." msgstr "Unable to unfeature @{username} on your profile." -#: src/components/related-actions.jsx:421 +#: src/components/related-actions.jsx:446 msgid "Unable to feature @{username} on your profile." msgstr "Unable to feature @{username} on your profile." -#: src/components/related-actions.jsx:430 +#: src/components/related-actions.jsx:455 msgid "Don't feature on profile" msgstr "Don't feature on profile" -#: src/components/related-actions.jsx:431 +#: src/components/related-actions.jsx:456 #: src/pages/hashtag.jsx:333 msgid "Feature on profile" msgstr "" -#: src/components/related-actions.jsx:440 -#: src/components/related-actions.jsx:478 +#: src/components/related-actions.jsx:465 +#: src/components/related-actions.jsx:515 msgid "Show featured profiles" msgstr "Show featured profiles" -#: src/components/related-actions.jsx:539 +#: src/components/related-actions.jsx:507 +#: src/pages/account-statuses.jsx:464 +msgid "Search my posts" +msgstr "Search my posts" + +#: src/components/related-actions.jsx:580 #: src/components/shortcuts-settings.jsx:1177 #: src/components/status.jsx:1501 msgid "Sharing doesn't seem to work." msgstr "" -#: src/components/related-actions.jsx:581 +#: src/components/related-actions.jsx:622 msgid "Unmuted @{username}" msgstr "Unmuted @{username}" -#: src/components/related-actions.jsx:593 +#: src/components/related-actions.jsx:634 msgid "Unmute <0>@{username}" msgstr "Unmute <0>@{username}" -#: src/components/related-actions.jsx:609 +#: src/components/related-actions.jsx:650 msgid "Mute <0>@{username}…" msgstr "" #. placeholder {0}: typeof MUTE_DURATIONS_LABELS[duration] === 'function' ? MUTE_DURATIONS_LABELS[duration]() : _(MUTE_DURATIONS_LABELS[duration]) -#: src/components/related-actions.jsx:641 +#: src/components/related-actions.jsx:682 msgid "Muted @{username} for {0}" msgstr "Muted @{username} for {0}" -#: src/components/related-actions.jsx:653 +#: src/components/related-actions.jsx:694 msgid "Unable to mute @{username}" msgstr "Unable to mute @{username}" -#: src/components/related-actions.jsx:674 +#: src/components/related-actions.jsx:715 msgid "Remove <0>@{username} from followers?" msgstr "" -#: src/components/related-actions.jsx:694 +#: src/components/related-actions.jsx:735 msgid "@{username} removed from followers" msgstr "@{username} removed from followers" -#: src/components/related-actions.jsx:706 +#: src/components/related-actions.jsx:747 msgid "Remove follower…" msgstr "" -#: src/components/related-actions.jsx:717 +#: src/components/related-actions.jsx:758 msgid "Block <0>@{username}?" msgstr "" -#: src/components/related-actions.jsx:741 +#: src/components/related-actions.jsx:782 msgid "Unblocked @{username}" msgstr "Unblocked @{username}" -#: src/components/related-actions.jsx:749 +#: src/components/related-actions.jsx:790 msgid "Blocked @{username}" msgstr "Blocked @{username}" -#: src/components/related-actions.jsx:757 +#: src/components/related-actions.jsx:798 msgid "Unable to unblock @{username}" msgstr "Unable to unblock @{username}" -#: src/components/related-actions.jsx:759 +#: src/components/related-actions.jsx:800 msgid "Unable to block @{username}" msgstr "Unable to block @{username}" -#: src/components/related-actions.jsx:769 +#: src/components/related-actions.jsx:810 msgid "Unblock <0>@{username}" msgstr "" -#: src/components/related-actions.jsx:778 +#: src/components/related-actions.jsx:819 msgid "Block <0>@{username}…" msgstr "" -#: src/components/related-actions.jsx:795 +#: src/components/related-actions.jsx:836 msgid "Report <0>@{username}…" msgstr "" -#: src/components/related-actions.jsx:851 +#: src/components/related-actions.jsx:892 msgid "Withdraw follow request?" msgstr "Withdraw follow request?" #. placeholder {0}: info.acct || info.username -#: src/components/related-actions.jsx:852 +#: src/components/related-actions.jsx:893 msgid "Unfollow @{0}?" msgstr "Unfollow @{0}?" -#: src/components/related-actions.jsx:915 +#: src/components/related-actions.jsx:956 msgid "Unfollow…" msgstr "" -#: src/components/related-actions.jsx:924 +#: src/components/related-actions.jsx:965 msgid "Withdraw…" msgstr "" -#: src/components/related-actions.jsx:931 -#: src/components/related-actions.jsx:935 +#: src/components/related-actions.jsx:972 +#: src/components/related-actions.jsx:976 #: src/pages/hashtag.jsx:265 msgid "Follow" msgstr "" @@ -3022,95 +3031,100 @@ msgstr "Login required." msgid "Go home" msgstr "" -#: src/pages/account-statuses.jsx:242 +#: src/pages/account-statuses.jsx:232 msgid "Account posts" msgstr "" -#: src/pages/account-statuses.jsx:249 +#: src/pages/account-statuses.jsx:239 msgid "{accountDisplay} (+ Replies)" msgstr "" -#: src/pages/account-statuses.jsx:251 +#: src/pages/account-statuses.jsx:241 msgid "{accountDisplay} (- Boosts)" msgstr "" -#: src/pages/account-statuses.jsx:253 +#: src/pages/account-statuses.jsx:243 msgid "{accountDisplay} (#{tagged})" msgstr "" -#: src/pages/account-statuses.jsx:255 +#: src/pages/account-statuses.jsx:245 msgid "{accountDisplay} (Media)" msgstr "" -#: src/pages/account-statuses.jsx:261 +#: src/pages/account-statuses.jsx:251 msgid "{accountDisplay} ({monthYear})" msgstr "" -#: src/pages/account-statuses.jsx:332 +#: src/pages/account-statuses.jsx:322 msgid "Clear filters" msgstr "" -#: src/pages/account-statuses.jsx:349 +#: src/pages/account-statuses.jsx:339 msgid "Showing post with replies" msgstr "" -#: src/pages/account-statuses.jsx:354 +#: src/pages/account-statuses.jsx:344 msgid "+ Replies" msgstr "" -#: src/pages/account-statuses.jsx:360 +#: src/pages/account-statuses.jsx:350 msgid "Showing posts without boosts" msgstr "" -#: src/pages/account-statuses.jsx:365 +#: src/pages/account-statuses.jsx:355 msgid "- Boosts" msgstr "" -#: src/pages/account-statuses.jsx:371 +#: src/pages/account-statuses.jsx:361 msgid "Showing posts with media" msgstr "" #. placeholder {0}: tag.name -#: src/pages/account-statuses.jsx:388 +#: src/pages/account-statuses.jsx:378 msgid "Showing posts tagged with #{0}" msgstr "" -#. placeholder {0}: date.toLocaleString(i18n.locale, { month: 'long', year: 'numeric', }) -#: src/pages/account-statuses.jsx:427 +#. placeholder {0}: date.toLocaleString( i18n.locale, { month: 'long', year: 'numeric', }, ) +#: src/pages/account-statuses.jsx:418 msgid "Showing posts in {0}" msgstr "Showing posts in {0}" -#: src/pages/account-statuses.jsx:496 +#. placeholder {0}: account?.username +#: src/pages/account-statuses.jsx:465 +msgid "Search @{0}'s posts" +msgstr "Search @{0}'s posts" + +#: src/pages/account-statuses.jsx:511 #: src/pages/search.jsx:345 #: src/pages/search.jsx:492 msgid "Posts" msgstr "" -#: src/pages/account-statuses.jsx:521 +#: src/pages/account-statuses.jsx:536 msgid "Nothing to see here yet." msgstr "" -#: src/pages/account-statuses.jsx:522 +#: src/pages/account-statuses.jsx:537 #: src/pages/public.jsx:99 #: src/pages/trending.jsx:452 msgid "Unable to load posts" msgstr "" -#: src/pages/account-statuses.jsx:563 -#: src/pages/account-statuses.jsx:593 +#: src/pages/account-statuses.jsx:578 +#: src/pages/account-statuses.jsx:608 msgid "Unable to fetch account info" msgstr "" #. placeholder {0}: accountInstance ? ( <> {' '} ({punycode.toUnicode(accountInstance)}) ) : null -#: src/pages/account-statuses.jsx:570 +#: src/pages/account-statuses.jsx:585 msgid "Switch to account's instance {0}" msgstr "" -#: src/pages/account-statuses.jsx:600 +#: src/pages/account-statuses.jsx:615 msgid "Switch to my instance (<0>{currentInstance})" msgstr "" -#: src/pages/account-statuses.jsx:673 +#: src/pages/account-statuses.jsx:688 msgid "Month" msgstr "" diff --git a/src/pages/account-statuses.jsx b/src/pages/account-statuses.jsx index 994d20c1..7166ac94 100644 --- a/src/pages/account-statuses.jsx +++ b/src/pages/account-statuses.jsx @@ -18,6 +18,7 @@ import Link from '../components/link'; import Menu2 from '../components/menu2'; import Timeline from '../components/timeline'; import { api } from '../utils/api'; +import isSearchEnabled from '../utils/is-search-enabled'; import mem from '../utils/mem'; import pmem from '../utils/pmem'; import showToast from '../utils/show-toast'; @@ -43,17 +44,6 @@ const supportsInputMonth = mem(() => { } }); -async function _isSearchEnabled(instance) { - const { masto } = api({ instance }); - const results = await masto.v2.search.list({ - q: 'from:me', - type: 'statuses', - limit: 1, - }); - return !!results?.statuses?.length; -} -const isSearchEnabled = pmem(_isSearchEnabled); - function AccountStatuses() { const { i18n, t } = useLingui(); const snapStates = useSnapshot(states); @@ -400,18 +390,52 @@ function AccountStatuses() { {/* {tag.statusesCount} */} ))} - {searchEnabled && - (supportsInputMonth() ? ( - - ) : ( - // Fallback to for year - { - const { value, validity } = e; - if (!validity.valid) return; - setSearchParams( - value - ? { - month: value, - } - : {}, - ); + )} + + + )} )} diff --git a/src/utils/is-search-enabled.js b/src/utils/is-search-enabled.js new file mode 100644 index 00000000..a0c2bfff --- /dev/null +++ b/src/utils/is-search-enabled.js @@ -0,0 +1,14 @@ +import { api } from './api'; +import pmem from './pmem'; + +async function _isSearchEnabled(instance) { + const { masto } = api({ instance }); + const results = await masto.v2.search.list({ + q: 'from:me', + type: 'statuses', + limit: 1, + }); + return !!results?.statuses?.length; +} + +export default pmem(_isSearchEnabled); diff --git a/src/utils/states.js b/src/utils/states.js index 77ecc550..6cf0bbf7 100644 --- a/src/utils/states.js +++ b/src/utils/states.js @@ -59,6 +59,7 @@ const states = proxy({ showQrCodeModal: false, showQrScannerModal: false, showImportExportAccounts: false, + showSearchCommand: false, // Shortcuts shortcuts: [], // Settings