feat: store last feed type
This commit is contained in:
@@ -2,6 +2,7 @@ export const StorageKey = {
|
|||||||
THEME_SETTING: 'themeSetting',
|
THEME_SETTING: 'themeSetting',
|
||||||
RELAY_SETS: 'relaySets',
|
RELAY_SETS: 'relaySets',
|
||||||
ACTIVE_RELAY_SET_ID: 'activeRelaySetId',
|
ACTIVE_RELAY_SET_ID: 'activeRelaySetId',
|
||||||
|
FEED_TYPE: 'feedType',
|
||||||
ACCOUNTS: 'accounts',
|
ACCOUNTS: 'accounts',
|
||||||
CURRENT_ACCOUNT: 'currentAccount',
|
CURRENT_ACCOUNT: 'currentAccount',
|
||||||
ADD_CLIENT_TAG: 'addClientTag'
|
ADD_CLIENT_TAG: 'addClientTag'
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ export const useFeed = () => {
|
|||||||
export function FeedProvider({ children }: { children: React.ReactNode }) {
|
export function FeedProvider({ children }: { children: React.ReactNode }) {
|
||||||
const { pubkey } = useNostr()
|
const { pubkey } = useNostr()
|
||||||
const { relaySets } = useRelaySets()
|
const { relaySets } = useRelaySets()
|
||||||
const [feedType, setFeedType] = useState<TFeedType>('relays')
|
const [feedType, setFeedType] = useState<TFeedType>(storage.getFeedType())
|
||||||
const [relayUrls, setRelayUrls] = useState<string[]>([])
|
const [relayUrls, setRelayUrls] = useState<string[]>([])
|
||||||
const [temporaryRelayUrls, setTemporaryRelayUrls] = useState<string[]>([])
|
const [temporaryRelayUrls, setTemporaryRelayUrls] = useState<string[]>([])
|
||||||
const [filter, setFilter] = useState<Filter>({})
|
const [filter, setFilter] = useState<Filter>({})
|
||||||
const [isReady, setIsReady] = useState(false)
|
const [isReady, setIsReady] = useState(false)
|
||||||
const [activeRelaySetId, setActiveRelaySetId] = useState<string | null>(() =>
|
const [activeRelaySetId, setActiveRelaySetId] = useState<string | null>(
|
||||||
storage.getActiveRelaySetId()
|
storage.getActiveRelaySetId()
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,6 +55,9 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
|
|||||||
return await switchFeed('temporary')
|
return await switchFeed('temporary')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (feedType === 'following') {
|
||||||
|
return await switchFeed('following')
|
||||||
|
}
|
||||||
await switchFeed('relays', { activeRelaySetId })
|
await switchFeed('relays', { activeRelaySetId })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +98,7 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
|
|||||||
setFilter({})
|
setFilter({})
|
||||||
setIsReady(true)
|
setIsReady(true)
|
||||||
storage.setActiveRelaySetId(relaySet.id)
|
storage.setActiveRelaySetId(relaySet.id)
|
||||||
|
storage.setFeedType(feedType)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -109,6 +113,7 @@ export function FeedProvider({ children }: { children: React.ReactNode }) {
|
|||||||
setRelayUrls(relayList.read.slice(0, 4))
|
setRelayUrls(relayList.read.slice(0, 4))
|
||||||
setFilter({ authors: followings.includes(pubkey) ? followings : [...followings, pubkey] })
|
setFilter({ authors: followings.includes(pubkey) ? followings : [...followings, pubkey] })
|
||||||
setIsReady(true)
|
setIsReady(true)
|
||||||
|
storage.setFeedType(feedType)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (feedType === 'temporary') {
|
if (feedType === 'temporary') {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { StorageKey } from '@/constants'
|
import { StorageKey } from '@/constants'
|
||||||
import { isSameAccount } from '@/lib/account'
|
import { isSameAccount } from '@/lib/account'
|
||||||
import { randomString } from '@/lib/random'
|
import { randomString } from '@/lib/random'
|
||||||
import { TAccount, TAccountPointer, TRelaySet, TThemeSetting } from '@/types'
|
import { TAccount, TAccountPointer, TFeedType, TRelaySet, TThemeSetting } from '@/types'
|
||||||
|
|
||||||
const DEFAULT_RELAY_SETS: TRelaySet[] = [
|
const DEFAULT_RELAY_SETS: TRelaySet[] = [
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,7 @@ class StorageService {
|
|||||||
|
|
||||||
private relaySets: TRelaySet[] = []
|
private relaySets: TRelaySet[] = []
|
||||||
private activeRelaySetId: string | null = null
|
private activeRelaySetId: string | null = null
|
||||||
|
private feedType: TFeedType = 'relays'
|
||||||
private themeSetting: TThemeSetting = 'system'
|
private themeSetting: TThemeSetting = 'system'
|
||||||
private accounts: TAccount[] = []
|
private accounts: TAccount[] = []
|
||||||
private currentAccount: TAccount | null = null
|
private currentAccount: TAccount | null = null
|
||||||
@@ -40,6 +41,8 @@ class StorageService {
|
|||||||
this.accounts = accountsStr ? JSON.parse(accountsStr) : []
|
this.accounts = accountsStr ? JSON.parse(accountsStr) : []
|
||||||
const currentAccountStr = window.localStorage.getItem(StorageKey.CURRENT_ACCOUNT)
|
const currentAccountStr = window.localStorage.getItem(StorageKey.CURRENT_ACCOUNT)
|
||||||
this.currentAccount = currentAccountStr ? JSON.parse(currentAccountStr) : null
|
this.currentAccount = currentAccountStr ? JSON.parse(currentAccountStr) : null
|
||||||
|
const feedTypeStr = window.localStorage.getItem(StorageKey.FEED_TYPE)
|
||||||
|
this.feedType = feedTypeStr ? JSON.parse(feedTypeStr) : 'relays'
|
||||||
|
|
||||||
const relaySetsStr = window.localStorage.getItem(StorageKey.RELAY_SETS)
|
const relaySetsStr = window.localStorage.getItem(StorageKey.RELAY_SETS)
|
||||||
if (!relaySetsStr) {
|
if (!relaySetsStr) {
|
||||||
@@ -94,6 +97,15 @@ class StorageService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFeedType() {
|
||||||
|
return this.feedType
|
||||||
|
}
|
||||||
|
|
||||||
|
setFeedType(feedType: TFeedType) {
|
||||||
|
this.feedType = feedType
|
||||||
|
window.localStorage.setItem(StorageKey.FEED_TYPE, JSON.stringify(this.feedType))
|
||||||
|
}
|
||||||
|
|
||||||
getThemeSetting() {
|
getThemeSetting() {
|
||||||
return this.themeSetting
|
return this.themeSetting
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user