about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/state/models/feed-view.ts46
-rw-r--r--src/state/models/shell.ts10
-rw-r--r--src/view/com/modals/ComposePost.tsx9
-rw-r--r--src/view/com/post-thread/PostThread.tsx6
-rw-r--r--src/view/com/post-thread/PostThreadItem.tsx6
-rw-r--r--src/view/com/post/Post.tsx2
-rw-r--r--src/view/com/posts/FeedItem.tsx2
-rw-r--r--src/view/screens/Home.tsx5
-rw-r--r--todos.txt2
9 files changed, 79 insertions, 9 deletions
diff --git a/src/state/models/feed-view.ts b/src/state/models/feed-view.ts
index 9fd024032..10d283922 100644
--- a/src/state/models/feed-view.ts
+++ b/src/state/models/feed-view.ts
@@ -102,6 +102,7 @@ export class FeedViewModel {
   params: GetFeedView.QueryParams
   _loadPromise: Promise<void> | undefined
   _loadMorePromise: Promise<void> | undefined
+  _loadLatestPromise: Promise<void> | undefined
   _updatePromise: Promise<void> | undefined
 
   // data
@@ -118,6 +119,7 @@ export class FeedViewModel {
         params: false,
         _loadPromise: false,
         _loadMorePromise: false,
+        _loadLatestPromise: false,
         _updatePromise: false,
       },
       {autoBind: true},
@@ -181,6 +183,19 @@ export class FeedViewModel {
   }
 
   /**
+   * Load more posts to the start of the feed
+   */
+  async loadLatest() {
+    if (this._loadLatestPromise) {
+      return this._loadLatestPromise
+    }
+    await this._pendingWork()
+    this._loadLatestPromise = this._loadLatest()
+    await this._loadLatestPromise
+    this._loadLatestPromise = undefined
+  }
+
+  /**
    * Update content in-place
    */
   async update() {
@@ -219,6 +234,9 @@ export class FeedViewModel {
     if (this._loadMorePromise) {
       await this._loadMorePromise
     }
+    if (this._loadLatestPromise) {
+      await this._loadLatestPromise
+    }
     if (this._updatePromise) {
       await this._updatePromise
     }
@@ -235,6 +253,17 @@ export class FeedViewModel {
     }
   }
 
+  private async _loadLatest() {
+    this._xLoading()
+    try {
+      const res = await this.rootStore.api.todo.social.getFeed(this.params)
+      this._prependAll(res)
+      this._xIdle()
+    } catch (e: any) {
+      this._xIdle(`Failed to load feed: ${e.toString()}`)
+    }
+  }
+
   private async _loadMore() {
     this._xLoading()
     try {
@@ -298,6 +327,23 @@ export class FeedViewModel {
     this.feed.push(new FeedViewItemModel(this.rootStore, `item-${keyId}`, item))
   }
 
+  private _prependAll(res: GetFeedView.Response) {
+    let counter = this.feed.length
+    for (const item of res.data.feed) {
+      if (this.feed.find(item2 => item2.uri === item.uri)) {
+        return // stop here - we've hit a post we already ahve
+      }
+      this._prepend(counter++, item)
+    }
+  }
+
+  private _prepend(keyId: number, item: GetFeedView.FeedItem) {
+    // TODO: validate .record
+    this.feed.unshift(
+      new FeedViewItemModel(this.rootStore, `item-${keyId}`, item),
+    )
+  }
+
   private _updateAll(res: GetFeedView.Response) {
     for (const item of res.data.feed) {
       const existingItem = this.feed.find(
diff --git a/src/state/models/shell.ts b/src/state/models/shell.ts
index 3a5376421..7ef8137e8 100644
--- a/src/state/models/shell.ts
+++ b/src/state/models/shell.ts
@@ -34,11 +34,19 @@ export class SharePostModel {
   }
 }
 
+export interface ComposePostModelOpts {
+  replyTo?: string
+  onPost?: () => void
+}
 export class ComposePostModel {
   name = 'compose-post'
+  replyTo?: string
+  onPost?: () => void
 
-  constructor(public replyTo?: string) {
+  constructor(opts?: ComposePostModelOpts) {
     makeAutoObservable(this)
+    this.replyTo = opts?.replyTo
+    this.onPost = opts?.onPost
   }
 }
 
diff --git a/src/view/com/modals/ComposePost.tsx b/src/view/com/modals/ComposePost.tsx
index 510900b60..cecc478f7 100644
--- a/src/view/com/modals/ComposePost.tsx
+++ b/src/view/com/modals/ComposePost.tsx
@@ -16,7 +16,13 @@ const WARNING_TEXT_LENGTH = 200
 const DANGER_TEXT_LENGTH = 255
 export const snapPoints = ['100%']
 
-export function Component({replyTo}: {replyTo?: string}) {
+export function Component({
+  replyTo,
+  onPost,
+}: {
+  replyTo?: string
+  onPost?: () => void
+}) {
   const store = useStores()
   const [error, setError] = useState('')
   const [text, setText] = useState('')
@@ -72,6 +78,7 @@ export function Component({replyTo}: {replyTo?: string}) {
       )
       return
     }
+    onPost?.()
     store.shell.closeModal()
     Toast.show(`Your ${replyTo ? 'reply' : 'post'} has been published`, {
       duration: Toast.durations.LONG,
diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx
index 5bd379fed..8a0ddab5d 100644
--- a/src/view/com/post-thread/PostThread.tsx
+++ b/src/view/com/post-thread/PostThread.tsx
@@ -70,7 +70,11 @@ export const PostThread = observer(function PostThread({uri}: {uri: string}) {
   // =
   const posts = view.thread ? Array.from(flattenThread(view.thread)) : []
   const renderItem = ({item}: {item: PostThreadViewPostModel}) => (
-    <PostThreadItem item={item} onPressShare={onPressShare} />
+    <PostThreadItem
+      item={item}
+      onPressShare={onPressShare}
+      onPostReply={onRefresh}
+    />
   )
   return (
     <FlatList
diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx
index d28017e44..ef1324bfb 100644
--- a/src/view/com/post-thread/PostThreadItem.tsx
+++ b/src/view/com/post-thread/PostThreadItem.tsx
@@ -20,9 +20,11 @@ const PARENT_REPLY_LINE_LENGTH = 8
 export const PostThreadItem = observer(function PostThreadItem({
   item,
   onPressShare,
+  onPostReply,
 }: {
   item: PostThreadViewPostModel
   onPressShare: (_uri: string) => void
+  onPostReply: () => void
 }) {
   const store = useStores()
   const record = item.record as unknown as PostType.Record
@@ -47,7 +49,9 @@ export const PostThreadItem = observer(function PostThreadItem({
   const repostsTitle = 'Reposts of this post'
 
   const onPressReply = () => {
-    store.shell.openModal(new ComposePostModel(item.uri))
+    store.shell.openModal(
+      new ComposePostModel({replyTo: item.uri, onPost: onPostReply}),
+    )
   }
   const onPressToggleRepost = () => {
     item
diff --git a/src/view/com/post/Post.tsx b/src/view/com/post/Post.tsx
index 4cd35659f..752a054b4 100644
--- a/src/view/com/post/Post.tsx
+++ b/src/view/com/post/Post.tsx
@@ -72,7 +72,7 @@ export const Post = observer(function Post({uri}: {uri: string}) {
     replyHref = `/profile/${urip.hostname}/post/${urip.recordKey}`
   }
   const onPressReply = () => {
-    store.shell.openModal(new ComposePostModel(item.uri))
+    store.shell.openModal(new ComposePostModel({replyTo: item.uri}))
   }
   const onPressToggleRepost = () => {
     item
diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx
index c24762730..b29470d2c 100644
--- a/src/view/com/posts/FeedItem.tsx
+++ b/src/view/com/posts/FeedItem.tsx
@@ -40,7 +40,7 @@ export const FeedItem = observer(function FeedItem({
   }, [record.reply])
 
   const onPressReply = () => {
-    store.shell.openModal(new ComposePostModel(item.uri))
+    store.shell.openModal(new ComposePostModel({replyTo: item.uri}))
   }
   const onPressToggleRepost = () => {
     item
diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx
index 5b4f1011d..dbf1eb29a 100644
--- a/src/view/screens/Home.tsx
+++ b/src/view/screens/Home.tsx
@@ -31,7 +31,10 @@ export const Home = observer(function Home({visible}: ScreenParams) {
   }, [visible, store])
 
   const onComposePress = () => {
-    store.shell.openModal(new ComposePostModel())
+    store.shell.openModal(new ComposePostModel({onPost: onCreatePost}))
+  }
+  const onCreatePost = () => {
+    feedView?.loadLatest()
   }
 
   return (
diff --git a/todos.txt b/todos.txt
index 28ebfe1cb..ce07e83c6 100644
--- a/todos.txt
+++ b/todos.txt
@@ -9,8 +9,6 @@ Paul's todo list
 - Private beta
   - Users list
   - Firehose
-- Composer
-  - Update the view after creating a post
 - Linking
   - Web linking
   - App linking