Feed feedback and fixes #231
@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import { PropsWithChildren } from 'react'
|
||||
import { Filter } from '.'
|
||||
import { FilterOptions, SortBy } from 'types'
|
||||
import { FilterOptions, RepostFilter, SortBy } from 'types'
|
||||
import { Dropdown } from './Dropdown'
|
||||
import { Option } from './Option'
|
||||
import { DEFAULT_FILTER_OPTIONS } from 'utils'
|
||||
@ -86,6 +86,27 @@ export const FeedFilter = React.memo(
|
||||
</Dropdown>
|
||||
)}
|
||||
|
||||
{/* Repost filter */}
|
||||
{tab === 2 && (
|
||||
<Dropdown label={filterOptions.repost}>
|
||||
{Object.values(RepostFilter).map((item, index) =>
|
||||
item === RepostFilter.Only_Repost ? null : (
|
||||
<Option
|
||||
key={`repost-${index}`}
|
||||
onClick={() =>
|
||||
setFilterOptions((prev) => ({
|
||||
...prev,
|
||||
repost: item
|
||||
}))
|
||||
}
|
||||
>
|
||||
{item}
|
||||
</Option>
|
||||
)
|
||||
)}
|
||||
</Dropdown>
|
||||
)}
|
||||
|
||||
{children}
|
||||
</Filter>
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useLoaderData } from 'react-router-dom'
|
||||
import { FeedPageLoaderResult } from './loader'
|
||||
import { useAppSelector, useNDKContext } from 'hooks'
|
||||
import { useAppSelector, useLocalStorage, useNDKContext } from 'hooks'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { LoadingSpinner } from 'components/LoadingSpinner'
|
||||
import {
|
||||
@ -11,6 +11,8 @@ import {
|
||||
} from '@nostr-dev-kit/ndk'
|
||||
import { NoteSubmit } from 'components/Notes/NoteSubmit'
|
||||
import { Note } from 'components/Notes/Note'
|
||||
import { FeedPostsFilter, RepostFilter } from 'types'
|
||||
import { DEFAULT_FILTER_OPTIONS } from 'utils'
|
||||
|
||||
export const FeedTabPosts = () => {
|
||||
const SHOWING_STEP = 20
|
||||
@ -24,6 +26,12 @@ export const FeedTabPosts = () => {
|
||||
const [isLoadMoreVisible, setIsLoadMoreVisible] = useState(true)
|
||||
const [showing, setShowing] = useState(SHOWING_STEP)
|
||||
|
||||
const filterKey = 'filter-feed-2'
|
||||
const [filterOptions] = useLocalStorage<FeedPostsFilter>(
|
||||
filterKey,
|
||||
DEFAULT_FILTER_OPTIONS
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!userPubkey) return
|
||||
|
||||
@ -65,14 +73,23 @@ export const FeedTabPosts = () => {
|
||||
// )
|
||||
// )
|
||||
|
||||
// Filter reply events
|
||||
_notes = _notes.filter((n) => n.getMatchingTags('e').length === 0)
|
||||
_notes = _notes.filter((n) => {
|
||||
if (n.kind === NDKKind.Text) {
|
||||
// Filter out the replies (Kind 1 events with e tags are replies to other kind 1 events)
|
||||
return n.getMatchingTags('e').length === 0
|
||||
}
|
||||
// Filter repost events if the option is set to hide reposts
|
||||
return !(
|
||||
n.kind === NDKKind.Repost &&
|
||||
filterOptions.repost === RepostFilter.Hide_Repost
|
||||
)
|
||||
})
|
||||
|
||||
_notes = _notes.sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0))
|
||||
|
||||
showing > 0 && _notes.splice(showing)
|
||||
return _notes
|
||||
}, [notes, showing])
|
||||
}, [filterOptions.repost, notes, showing])
|
||||
|
||||
if (!userPubkey) return null
|
||||
|
||||
|
@ -41,4 +41,4 @@ export interface FilterOptions {
|
||||
repost: RepostFilter
|
||||
}
|
||||
|
||||
export type FeedPostsFilter = Pick<FilterOptions, 'nsfw'>
|
||||
export type FeedPostsFilter = Pick<FilterOptions, 'nsfw' | 'repost'>
|
||||
|
Loading…
x
Reference in New Issue
Block a user