From fdaa894c8fa1089012d118d68361d7f4ed95b07a Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Sat, 18 Mar 2023 16:37:29 +0900 Subject: [PATCH] feat: support CW and enhance smartphone support --- src/components/Column.tsx | 27 ++++---- src/components/NotePostForm.tsx | 67 ++++++++++++++++--- .../textNote/Bech32EntityDisplay.tsx | 0 src/index.css | 4 -- src/nostr/useCommands.ts | 11 ++- src/pages/Home.tsx | 4 +- src/utils/imageUrl.ts | 4 +- 7 files changed, 82 insertions(+), 35 deletions(-) delete mode 100644 src/components/textNote/Bech32EntityDisplay.tsx diff --git a/src/components/Column.tsx b/src/components/Column.tsx index 0c6ed2b..454f8d0 100644 --- a/src/components/Column.tsx +++ b/src/components/Column.tsx @@ -1,30 +1,18 @@ import type { Component, JSX } from 'solid-js'; import { useHandleCommand } from '@/hooks/useCommandBus'; -const widthToClass = { - widest: 'w-[500px]', - wide: 'w-[350px]', - medium: 'w-[310px]', - narrow: 'w-[270px]', -} as const; - type ColumnProps = { name: string; columnIndex: number; lastColumn?: true; - width: keyof typeof widthToClass | null | undefined; + width: 'widest' | 'wide' | 'medium' | 'narrow' | null | undefined; children: JSX.Element; }; const Column: Component = (props) => { let columnDivRef: HTMLDivElement | undefined; - const width = () => { - if (props.width == null) { - return widthToClass.medium; - } - return widthToClass[props.width]; - }; + const width = () => props.width ?? 'medium'; useHandleCommand(() => ({ commandType: 'moveToColumn', @@ -45,7 +33,16 @@ const Column: Component = (props) => { })); return ( -
+
{/* 🏠 */} {props.name} diff --git a/src/components/NotePostForm.tsx b/src/components/NotePostForm.tsx index edccc8b..35ba85a 100644 --- a/src/components/NotePostForm.tsx +++ b/src/components/NotePostForm.tsx @@ -14,6 +14,8 @@ import uniq from 'lodash/uniq'; import PaperAirplane from 'heroicons/24/solid/paper-airplane.svg'; import Photo from 'heroicons/24/outline/photo.svg'; +import Eye from 'heroicons/24/solid/eye.svg'; +import EyeSlash from 'heroicons/24/outline/eye-slash.svg'; import XMark from 'heroicons/24/outline/x-mark.svg'; import UserNameDisplay from '@/components/UserDisplayName'; @@ -50,10 +52,14 @@ const NotePostForm: Component = (props) => { let fileInputRef: HTMLInputElement | undefined; const [text, setText] = createSignal(''); - const [isUploading, setIsUploading] = createSignal(false); - const [isDragging, setIsDragging] = createSignal(false); + const [contentWarning, setContentWarning] = createSignal(false); + const [contentWarningReason, setContentWarningReason] = createSignal(''); - const clearText = () => setText(''); + const clearText = () => { + setText(''); + setContentWarningReason(''); + setContentWarning(false); + }; const { config } = useConfig(); const getPubkey = usePubkey(); @@ -117,14 +123,26 @@ const NotePostForm: Component = (props) => { console.error('pubkey is not available'); return; } - publishTextNoteMutation.mutate({ + let textNote: Parameters[0] = { relayUrls: config().relayUrls, pubkey, content: text(), - notifyPubkeys: notifyPubkeys(pubkey), - rootEventId: replyTo()?.rootEvent()?.id ?? replyTo()?.id, - replyEventId: replyTo()?.id, - }); + }; + if (replyTo() != null) { + textNote = { + ...textNote, + notifyPubkeys: notifyPubkeys(pubkey), + rootEventId: replyTo()?.rootEvent()?.id ?? replyTo()?.id, + replyEventId: replyTo()?.id, + }; + } + if (contentWarning()) { + textNote = { + ...textNote, + contentWarning: contentWarningReason(), + }; + } + publishTextNoteMutation.mutate(textNote); }; const handleInput: JSX.EventHandler = (ev) => { @@ -162,11 +180,11 @@ const NotePostForm: Component = (props) => { const handleDragOver: JSX.EventHandler = (ev) => { ev.preventDefault(); - setIsDragging(true); }; const submitDisabled = () => text().trim().length === 0 || + (contentWarning() && contentWarningReason().length === 0) || publishTextNoteMutation.isLoading || uploadFilesMutation.isLoading; @@ -193,6 +211,16 @@ const NotePostForm: Component = (props) => {
+ + setContentWarningReason(ev.currentTarget.value)} + value={contentWarningReason()} + /> +