about summary refs log tree commit diff
path: root/src/state/preferences/feed-tuners.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-11-10 15:34:25 -0800
committerGitHub <noreply@github.com>2023-11-10 15:34:25 -0800
commitc8c308e31e63607280648e3e9f1f56a371adcd05 (patch)
tree09cea4c603968a1a0b4cab299af9a417880c8115 /src/state/preferences/feed-tuners.tsx
parent51f04b96200e38d95e486628d3cbc43398c47980 (diff)
downloadvoidsky-c8c308e31e63607280648e3e9f1f56a371adcd05.tar.zst
Refactor feeds to use react-query (#1862)
* Update to react-query v5

* Introduce post-feed react query

* Add feed refresh behaviors

* Only fetch feeds of visible pages

* Implement polling for latest on feeds

* Add moderation filtering to slices

* Handle block errors

* Update feed error messages

* Remove old models

* Replace simple-feed option with disable-tuner option

* Add missing useMemo

* Implement the mergefeed and fixes to polling

* Correctly handle failed load more state

* Improve error and empty state behaviors

* Clearer naming
Diffstat (limited to 'src/state/preferences/feed-tuners.tsx')
-rw-r--r--src/state/preferences/feed-tuners.tsx48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/state/preferences/feed-tuners.tsx b/src/state/preferences/feed-tuners.tsx
new file mode 100644
index 000000000..96770055c
--- /dev/null
+++ b/src/state/preferences/feed-tuners.tsx
@@ -0,0 +1,48 @@
+import {useMemo} from 'react'
+import {FeedTuner} from '#/lib/api/feed-manip'
+import {FeedDescriptor} from '../queries/post-feed'
+import {useLanguagePrefs} from './languages'
+
+export function useFeedTuners(feedDesc: FeedDescriptor) {
+  const langPrefs = useLanguagePrefs()
+
+  return useMemo(() => {
+    if (feedDesc.startsWith('feedgen')) {
+      return [
+        FeedTuner.dedupReposts,
+        FeedTuner.preferredLangOnly(langPrefs.contentLanguages),
+      ]
+    }
+    if (feedDesc.startsWith('list')) {
+      return [FeedTuner.dedupReposts]
+    }
+    if (feedDesc === 'home' || feedDesc === 'following') {
+      const feedTuners = []
+
+      if (false /*TODOthis.homeFeed.hideReposts*/) {
+        feedTuners.push(FeedTuner.removeReposts)
+      } else {
+        feedTuners.push(FeedTuner.dedupReposts)
+      }
+
+      if (true /*TODOthis.homeFeed.hideReplies*/) {
+        feedTuners.push(FeedTuner.removeReplies)
+      } /* TODO else {
+        feedTuners.push(
+          FeedTuner.thresholdRepliesOnly({
+            userDid: this.rootStore.session.data?.did || '',
+            minLikes: this.homeFeed.hideRepliesByLikeCount,
+            followedOnly: !!this.homeFeed.hideRepliesByUnfollowed,
+          }),
+        )
+      }*/
+
+      if (false /*TODOthis.homeFeed.hideQuotePosts*/) {
+        feedTuners.push(FeedTuner.removeQuotePosts)
+      }
+
+      return feedTuners
+    }
+    return []
+  }, [feedDesc, langPrefs])
+}