about summary refs log tree commit diff
path: root/src/view/com/composer/state/composer.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-10-29 20:29:38 +0000
committerGitHub <noreply@github.com>2024-10-29 20:29:38 +0000
commit96ba6456e7371821d01f83fb59c6c1ef0117607c (patch)
tree5b224e8f5df687a83834d46a99801a82ed1b2909 /src/view/com/composer/state/composer.ts
parentbab44a5a1344f56b90d76e6c09d3066ba4d2ef23 (diff)
downloadvoidsky-96ba6456e7371821d01f83fb59c6c1ef0117607c.tar.zst
Remove indirection when rendering composer state (#5954)
* Simplify onPressCancel dismiss condition

* Remove alias variables

* Move grapheme length calculation to reducer
Diffstat (limited to 'src/view/com/composer/state/composer.ts')
-rw-r--r--src/view/com/composer/state/composer.ts4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/view/com/composer/state/composer.ts b/src/view/com/composer/state/composer.ts
index 958718eaf..353600ef6 100644
--- a/src/view/com/composer/state/composer.ts
+++ b/src/view/com/composer/state/composer.ts
@@ -3,6 +3,7 @@ import {AppBskyFeedPostgate, RichText} from '@atproto/api'
 
 import {SelfLabel} from '#/lib/moderation'
 import {insertMentionAt} from '#/lib/strings/mention-manip'
+import {shortenLinks} from '#/lib/strings/rich-text-manip'
 import {
   isBskyPostUrl,
   postUriToRelativePath,
@@ -51,6 +52,7 @@ export type PostDraft = {
   richtext: RichText
   labels: SelfLabel[]
   embed: EmbedDraft
+  shortenedGraphemeLength: number
 }
 
 export type PostAction =
@@ -137,6 +139,7 @@ function postReducer(state: PostDraft, action: PostAction): PostDraft {
       return {
         ...state,
         richtext: action.richtext,
+        shortenedGraphemeLength: shortenLinks(action.richtext).graphemeLength,
       }
     }
     case 'update_labels': {
@@ -425,6 +428,7 @@ export function createComposerState({
       posts: [
         {
           richtext: initRichText,
+          shortenedGraphemeLength: 0,
           labels: [],
           embed: {
             quote,