feat: 🌸
This commit is contained in:
parent
74e04e1c7d
commit
e91b2648cc
41 changed files with 756 additions and 92 deletions
|
|
@ -1,9 +1,12 @@
|
|||
import storage from '@/services/local-storage.service'
|
||||
import mediaUpload from '@/services/media-upload.service'
|
||||
import { createContext, useContext, useState } from 'react'
|
||||
import { TMediaUploadServiceConfig } from '@/types'
|
||||
import { createContext, useContext, useEffect, useState } from 'react'
|
||||
import { useNostr } from './NostrProvider'
|
||||
|
||||
type TMediaUploadServiceContext = {
|
||||
service: string
|
||||
updateService: (service: string) => void
|
||||
serviceConfig: TMediaUploadServiceConfig
|
||||
updateServiceConfig: (service: TMediaUploadServiceConfig) => void
|
||||
}
|
||||
|
||||
const MediaUploadServiceContext = createContext<TMediaUploadServiceContext | undefined>(undefined)
|
||||
|
|
@ -17,15 +20,27 @@ export const useMediaUploadService = () => {
|
|||
}
|
||||
|
||||
export function MediaUploadServiceProvider({ children }: { children: React.ReactNode }) {
|
||||
const [service, setService] = useState(mediaUpload.getService())
|
||||
const { pubkey, startLogin } = useNostr()
|
||||
const [serviceConfig, setServiceConfig] = useState(storage.getMediaUploadServiceConfig())
|
||||
|
||||
const updateService = (newService: string) => {
|
||||
setService(newService)
|
||||
mediaUpload.setService(newService)
|
||||
useEffect(() => {
|
||||
const serviceConfig = storage.getMediaUploadServiceConfig(pubkey)
|
||||
setServiceConfig(serviceConfig)
|
||||
mediaUpload.setServiceConfig(serviceConfig)
|
||||
}, [pubkey])
|
||||
|
||||
const updateServiceConfig = (newService: TMediaUploadServiceConfig) => {
|
||||
if (!pubkey) {
|
||||
startLogin()
|
||||
return
|
||||
}
|
||||
setServiceConfig(newService)
|
||||
storage.setMediaUploadServiceConfig(pubkey, newService)
|
||||
mediaUpload.setServiceConfig(newService)
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaUploadServiceContext.Provider value={{ service, updateService }}>
|
||||
<MediaUploadServiceContext.Provider value={{ serviceConfig, updateServiceConfig }}>
|
||||
{children}
|
||||
</MediaUploadServiceContext.Provider>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -210,7 +210,8 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
kinds.Contacts,
|
||||
kinds.Mutelist,
|
||||
kinds.BookmarkList,
|
||||
ExtendedKind.FAVORITE_RELAYS
|
||||
ExtendedKind.FAVORITE_RELAYS,
|
||||
ExtendedKind.BLOSSOM_SERVER_LIST
|
||||
],
|
||||
authors: [account.pubkey]
|
||||
},
|
||||
|
|
@ -226,6 +227,9 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
const muteListEvent = sortedEvents.find((e) => e.kind === kinds.Mutelist)
|
||||
const bookmarkListEvent = sortedEvents.find((e) => e.kind === kinds.BookmarkList)
|
||||
const favoriteRelaysEvent = sortedEvents.find((e) => e.kind === ExtendedKind.FAVORITE_RELAYS)
|
||||
const blossomServerListEvent = sortedEvents.find(
|
||||
(e) => e.kind === ExtendedKind.BLOSSOM_SERVER_LIST
|
||||
)
|
||||
const notificationsSeenAtEvent = sortedEvents.find(
|
||||
(e) =>
|
||||
e.kind === kinds.Application &&
|
||||
|
|
@ -258,6 +262,9 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
setFavoriteRelaysEvent(favoriteRelaysEvent)
|
||||
await indexedDb.putReplaceableEvent(favoriteRelaysEvent)
|
||||
}
|
||||
if (blossomServerListEvent) {
|
||||
await client.updateBlossomServerListEventCache(blossomServerListEvent)
|
||||
}
|
||||
|
||||
const notificationsSeenAt = Math.max(
|
||||
notificationsSeenAtEvent?.created_at ?? 0,
|
||||
|
|
@ -308,6 +315,14 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
}
|
||||
}, [signer])
|
||||
|
||||
useEffect(() => {
|
||||
if (account) {
|
||||
client.pubkey = account.pubkey
|
||||
} else {
|
||||
client.pubkey = undefined
|
||||
}
|
||||
}, [account])
|
||||
|
||||
const hasNostrLoginHash = () => {
|
||||
return window.location.hash && window.location.hash.startsWith('#nostr-login')
|
||||
}
|
||||
|
|
@ -565,7 +580,14 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||
})
|
||||
}
|
||||
}
|
||||
if ([kinds.RelayList, kinds.Contacts, ExtendedKind.FAVORITE_RELAYS].includes(draftEvent.kind)) {
|
||||
if (
|
||||
[
|
||||
kinds.RelayList,
|
||||
kinds.Contacts,
|
||||
ExtendedKind.FAVORITE_RELAYS,
|
||||
ExtendedKind.BLOSSOM_SERVER_LIST
|
||||
].includes(draftEvent.kind)
|
||||
) {
|
||||
additionalRelayUrls.push(...BIG_RELAY_URLS)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue