From 959ac468d85948ef65cb5145660a939f6df1742a Mon Sep 17 00:00:00 2001
From: Lim Chee Aun
Date: Sat, 8 Apr 2023 20:42:38 +0800
Subject: [PATCH] Allow instance-based hashtags
Also change design a little
---
src/components/shortcuts-settings.css | 2 +
src/components/shortcuts-settings.jsx | 34 +++++++++--
src/components/shortcuts.css | 12 ++++
src/components/shortcuts.jsx | 81 +++++++++++++++++----------
src/pages/hashtag.jsx | 28 +++++++--
5 files changed, 117 insertions(+), 40 deletions(-)
diff --git a/src/components/shortcuts-settings.css b/src/components/shortcuts-settings.css
index c3bf0dcd..1036d79b 100644
--- a/src/components/shortcuts-settings.css
+++ b/src/components/shortcuts-settings.css
@@ -26,6 +26,8 @@
#shortcuts-settings-container .shortcuts-list li .shortcut-text {
flex-grow: 1;
min-width: 0;
+ line-height: 1;
+ word-break: break-word;
}
#shortcuts-settings-container .shortcuts-list li .shortcut-actions {
flex-shrink: 0;
diff --git a/src/components/shortcuts-settings.jsx b/src/components/shortcuts-settings.jsx
index ed9e189a..7e2c7fef 100644
--- a/src/components/shortcuts-settings.jsx
+++ b/src/components/shortcuts-settings.jsx
@@ -94,6 +94,13 @@ const TYPE_PARAMS = {
placeholder: 'e.g. PixelArt (Max 5, space-separated)',
pattern: '[^#]+',
},
+ {
+ text: 'Instance',
+ name: 'instance',
+ type: 'text',
+ placeholder: 'Optional, e.g. mastodon.social',
+ notRequired: true,
+ },
],
};
export const SHORTCUTS_META = {
@@ -131,14 +138,15 @@ export const SHORTCUTS_META = {
},
public: {
id: 'public',
- title: ({ local, instance }) =>
- `${local ? 'Local' : 'Federated'} (${instance})`,
+ title: ({ local }) => (local ? 'Local' : 'Federated'),
+ subtitle: ({ instance }) => instance,
path: ({ local, instance }) => `/${instance}/p${local ? '/l' : ''}`,
icon: ({ local }) => (local ? 'group' : 'earth'),
},
trending: {
id: 'trending',
title: 'Trending',
+ subtitle: ({ instance }) => instance,
path: ({ instance }) => `/${instance}/trending`,
icon: 'chart',
},
@@ -177,6 +185,7 @@ export const SHORTCUTS_META = {
hashtag: {
id: 'hashtag',
title: ({ hashtag }) => hashtag,
+ subtitle: ({ instance }) => instance,
path: ({ hashtag }) => `/t/${hashtag.split(/\s+/).join('+')}`,
icon: 'hashtag',
},
@@ -307,10 +316,13 @@ function ShortcutsSettings() {
const key = i + Object.values(shortcut);
const { type } = shortcut;
if (!SHORTCUTS_META[type]) return null;
- let { icon, title } = SHORTCUTS_META[type];
+ let { icon, title, subtitle } = SHORTCUTS_META[type];
if (typeof title === 'function') {
title = title(shortcut, i);
}
+ if (typeof subtitle === 'function') {
+ subtitle = subtitle(shortcut, i);
+ }
if (typeof icon === 'function') {
icon = icon(shortcut, i);
}
@@ -319,6 +331,12 @@ function ShortcutsSettings() {
{title}
+ {subtitle && (
+ <>
+ {' '}
+ {subtitle}
+ >
+ )}
{TYPE_PARAMS[currentType]?.map?.(
- ({ text, name, type, placeholder, pattern }) => {
+ ({ text, name, type, placeholder, pattern, notRequired }) => {
if (currentType === 'list') {
return (