From 5474c85ace0543a62bddbd10f1ba92947ff12c5b Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Sat, 29 Apr 2023 00:22:03 +0900 Subject: [PATCH] update --- .eslintrc.js | 15 +++- src/components/Config.tsx | 13 ++- src/components/DeprecatedRepost.tsx | 2 +- src/components/NotePostForm.tsx | 28 ++++-- src/components/ProfileDisplay.tsx | 43 ++++----- src/components/SideBar.tsx | 2 +- src/components/TextNote.tsx | 2 +- src/components/TimelineContentDisplay.tsx | 4 +- src/components/notification/Reaction.tsx | 2 +- .../textNote/ContentWarningDisplay.tsx | 2 +- .../textNote/MentionedEventDisplay.tsx | 2 +- .../textNote/MentionedUserDisplay.tsx | 2 +- src/components/textNote/PlainTextDisplay.tsx | 2 +- .../textNote/TextNoteContentDisplay.tsx | 6 +- src/components/textNote/TextNoteDisplay.tsx | 88 ++++++++++++++----- .../textNote/TextNoteDisplayById.tsx | 2 +- src/components/utils/Popup.tsx | 20 +++++ src/{nostr => core}/useConfig.ts | 2 + src/hooks/useFormatDate.ts | 2 +- src/{core => nostr}/event.ts | 0 src/{core => nostr}/parseTextNote.test.ts | 1 + src/{core => nostr}/parseTextNote.ts | 7 +- src/nostr/useBatchedEvents.ts | 4 +- src/nostr/useCommands.ts | 18 ++++ src/nostr/useFollowers.ts | 2 +- src/nostr/useSubscription.ts | 5 +- src/pages/Home.tsx | 2 +- src/utils/epoch.ts | 4 +- 28 files changed, 204 insertions(+), 78 deletions(-) create mode 100644 src/components/utils/Popup.tsx rename src/{nostr => core}/useConfig.ts (98%) rename src/{core => nostr}/event.ts (100%) rename src/{core => nostr}/parseTextNote.test.ts (99%) rename src/{core => nostr}/parseTextNote.ts (94%) diff --git a/.eslintrc.js b/.eslintrc.js index 38699fe..12f0922 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,6 +25,8 @@ module.exports = { }, plugins: ['import', 'solid', 'jsx-a11y', 'prettier', '@typescript-eslint', 'tailwindcss'], rules: { + 'no-alert': ['off'], + 'no-console': ['off'], 'import/extensions': [ 'error', 'ignorePackages', @@ -33,9 +35,6 @@ module.exports = { tsx: 'never', }, ], - 'prettier/prettier': 'error', - 'no-console': ['off'], - 'no-alert': ['off'], 'import/order': [ 'warn', { @@ -49,6 +48,16 @@ module.exports = { ], }, ], + 'jsx-a11y/label-has-associated-control': [ + 'error', + { + labelComponents: ['label'], + labelAttributes: ['inputLabel'], + assert: 'both', + depth: 3, + }, + ], + 'prettier/prettier': 'error', }, settings: { linkComponents: ['Link'], diff --git a/src/components/Config.tsx b/src/components/Config.tsx index 1de4434..b4ed8f2 100644 --- a/src/components/Config.tsx +++ b/src/components/Config.tsx @@ -3,7 +3,7 @@ import { createSignal, For, type JSX } from 'solid-js'; import XMark from 'heroicons/24/outline/x-mark.svg'; import Modal from '@/components/Modal'; -import useConfig, { type Config } from '@/nostr/useConfig'; +import useConfig, { type Config } from '@/core/useConfig'; import UserNameDisplay from './UserDisplayName'; @@ -214,6 +214,13 @@ const OtherConfig = () => { })); }; + const toggleHideCount = () => { + setConfig((current) => ({ + ...current, + hideCount: !(current.hideCount ?? false), + })); + }; + return (

その他

@@ -229,6 +236,10 @@ const OtherConfig = () => {
画像をデフォルトで表示する
toggleShowImage()} />
+
+
いいねやリポスト、フォロワーなどの数を隠す
+ toggleHideCount()} /> +
{/*
リアクションのデフォルト
diff --git a/src/components/DeprecatedRepost.tsx b/src/components/DeprecatedRepost.tsx index db298a1..4512ff0 100644 --- a/src/components/DeprecatedRepost.tsx +++ b/src/components/DeprecatedRepost.tsx @@ -6,9 +6,9 @@ import { Event as NostrEvent } from 'nostr-tools'; import ColumnItem from '@/components/ColumnItem'; import UserDisplayName from '@/components/UserDisplayName'; -import eventWrapper from '@/core/event'; import useFormatDate from '@/hooks/useFormatDate'; import useModalState from '@/hooks/useModalState'; +import eventWrapper from '@/nostr/event'; import TextNoteDisplayById from './textNote/TextNoteDisplayById'; diff --git a/src/components/NotePostForm.tsx b/src/components/NotePostForm.tsx index 9fc8fb9..671d9b7 100644 --- a/src/components/NotePostForm.tsx +++ b/src/components/NotePostForm.tsx @@ -17,11 +17,11 @@ import uniq from 'lodash/uniq'; import { Event as NostrEvent } from 'nostr-tools'; import UserNameDisplay from '@/components/UserDisplayName'; -import eventWrapper from '@/core/event'; -import parseTextNote from '@/core/parseTextNote'; +import useConfig from '@/core/useConfig'; import { useHandleCommand } from '@/hooks/useCommandBus'; +import eventWrapper from '@/nostr/event'; +import parseTextNote, { ParsedTextNote } from '@/nostr/parseTextNote'; import useCommands, { PublishTextNoteParams } from '@/nostr/useCommands'; -import useConfig from '@/nostr/useConfig'; import usePubkey from '@/nostr/usePubkey'; import { uploadNostrBuild, uploadFiles } from '@/utils/imageUpload'; @@ -43,9 +43,7 @@ const placeholder = (mode: NotePostFormProps['mode']) => { } }; -const parseAndExtract = (content: string) => { - const parsed = parseTextNote(content); - +const extract = (parsed: ParsedTextNote) => { const hashtags: string[] = []; const pubkeyReferences: string[] = []; const eventReferences: string[] = []; @@ -73,6 +71,18 @@ const parseAndExtract = (content: string) => { }; }; +const format = (parsed: ParsedTextNote) => { + const content = []; + parsed.forEach((node) => { + if (node.type === 'Bech32Entity' && !node.isNIP19) { + content.push(`nostr:${node.content}`); + } else { + content.push(node.content); + } + }); + return content.join(''); +}; + const NotePostForm: Component = (props) => { let textAreaRef: HTMLTextAreaElement | undefined; let fileInputRef: HTMLInputElement | undefined; @@ -166,12 +176,14 @@ const NotePostForm: Component = (props) => { return; } - const { hashtags, pubkeyReferences, eventReferences, urlReferences } = parseAndExtract(text()); + const parsed = parseTextNote(text()); + const { hashtags, pubkeyReferences, eventReferences, urlReferences } = extract(parsed); + const formattedContent = format(parsed); let textNote: PublishTextNoteParams = { relayUrls: config().relayUrls, pubkey, - content: text(), + content: formattedContent, notifyPubkeys: pubkeyReferences, mentionEventIds: eventReferences, hashtags, diff --git a/src/components/ProfileDisplay.tsx b/src/components/ProfileDisplay.tsx index 44e0747..a1230a7 100644 --- a/src/components/ProfileDisplay.tsx +++ b/src/components/ProfileDisplay.tsx @@ -7,13 +7,14 @@ import GlobeAlt from 'heroicons/24/outline/globe-alt.svg'; import XMark from 'heroicons/24/outline/x-mark.svg'; import CheckCircle from 'heroicons/24/solid/check-circle.svg'; import ExclamationCircle from 'heroicons/24/solid/exclamation-circle.svg'; +import uniq from 'lodash/uniq'; import Modal from '@/components/Modal'; import Timeline from '@/components/Timeline'; import Copy from '@/components/utils/Copy'; import SafeLink from '@/components/utils/SafeLink'; +import useConfig from '@/core/useConfig'; import useCommands from '@/nostr/useCommands'; -import useConfig from '@/nostr/useConfig'; import useFollowers from '@/nostr/useFollowers'; import useFollowings from '@/nostr/useFollowings'; import useProfile from '@/nostr/useProfile'; @@ -125,7 +126,7 @@ const ProfileDisplay: Component = (props) => { relayUrls: config().relayUrls, pubkey: p, content: myFollowingQuery.data?.content ?? '', - followingPubkeys: [...myFollowingPubkeys(), props.pubkey], + followingPubkeys: uniq([...myFollowingPubkeys(), props.pubkey]), }); }; @@ -325,25 +326,27 @@ const ProfileDisplay: Component = (props) => {
-
-
フォロワー
-
- setShowFollowers(true)} - > - 読み込む - - } - keyed - > - - + +
+
フォロワー
+
+ setShowFollowers(true)} + > + 読み込む + + } + keyed + > + + +
-
+
0}>