From 50eb9b9f59722be289365944b9dadb875da8f9cc Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 9 Mar 2023 21:51:50 +0800 Subject: [PATCH] Improve context menu design --- src/app.css | 24 ++++++- src/components/icon.jsx | 10 ++- src/components/status.jsx | 133 +++++++++++++++++++++++++------------- 3 files changed, 119 insertions(+), 48 deletions(-) diff --git a/src/app.css b/src/app.css index 39862a70..62026ad4 100644 --- a/src/app.css +++ b/src/app.css @@ -1100,10 +1100,16 @@ body:has(.status-deck) .media-post-link { line-height: 1; padding: 8px 16px !important; transition: all 0.1s ease-in-out; + text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; - text-decoration: none; +} +.szh-menu .szh-menu__item span { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + line-height: 1.05; } .szh-menu .szh-menu__item * { vertical-align: middle; @@ -1141,6 +1147,22 @@ body:has(.status-deck) .media-post-link { text-overflow: ellipsis; overflow: hidden; } +.szh-menu .menu-double-lines { + white-space: normal; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; +} +.szh-menu .menu-double-lines span { + white-space: normal; +} +.szh-menu .menu-horizontal { + display: flex; +} +.szh-menu .menu-horizontal .szh-menu__item { + flex: 1; +} .szh-menu .szh-menu__item .menu-shortcut { opacity: 0.5; font-weight: normal; diff --git a/src/components/icon.jsx b/src/components/icon.jsx index 805823d9..afaa5f9b 100644 --- a/src/components/icon.jsx +++ b/src/components/icon.jsx @@ -68,7 +68,14 @@ const ICONS = { const modules = import.meta.glob('/node_modules/@iconify-icons/mingcute/*.js'); -function Icon({ icon, size = 'm', alt, title, class: className = '' }) { +function Icon({ + icon, + size = 'm', + alt, + title, + class: className = '', + style = {}, +}) { if (!icon) return null; const iconSize = SIZES[size]; @@ -97,6 +104,7 @@ function Icon({ icon, size = 'm', alt, title, class: className = '' }) { display: 'inline-block', overflow: 'hidden', lineHeight: 0, + ...style, }} > {iconData && ( diff --git a/src/components/status.jsx b/src/components/status.jsx index a6ad82a5..b85c91e5 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -373,7 +373,7 @@ function Status({ - View post and replies + View post by @{username || acct} )} @@ -408,7 +408,12 @@ function Status({ } catch (e) {} }} > - + {reblogged ? 'Unboost' : 'Boost…'} )} @@ -421,7 +426,12 @@ function Status({ } catch (e) {} }} > - + {favourited ? 'Unfavourite' : 'Favourite'} - + {bookmarked ? 'Unbookmark' : 'Bookmark'} + {enableTranslate && ( + { + setForceTranslate(true); + }} + > + + Translate + + )} )} - Open link to post + {nicePostURL(url)} - { - // Copy url to clipboard - try { - navigator.clipboard.writeText(url); - showToast('Link copied'); - } catch (e) { - console.error(e); - showToast('Unable to copy link'); - } - }} - > - - Copy link to post - - {enableTranslate && ( + {isSelf && ( <> @@ -546,6 +563,9 @@ function Status({ onContextMenu={(e) => { if (size === 'l') return; if (e.metaKey) return; + console.log('context menu', e); + const link = e.target.closest('a'); + if (link && /^https?:\/\//.test(link.getAttribute('href'))) return; e.preventDefault(); setContextMenuAnchorPoint({ x: e.clientX, @@ -1537,6 +1557,27 @@ function _unfurlMastodonLink(instance, url) { return Promise.any([remoteInstanceFetch, mastoSearchFetch]); } +function nicePostURL(url) { + const urlObj = new URL(url); + const { host, pathname } = urlObj; + const path = pathname.replace(/\/$/, ''); + // split only first slash + const [_, username, restPath] = path.match(/\/(@[^\/]+)\/(.*)/) || []; + return ( + <> + {host} + {username ? ( + <> + /{username} + /{restPath} + + ) : ( + {path} + )} + + ); +} + const unfurlMastodonLink = throttle(_unfurlMastodonLink); const div = document.createElement('div');