Remove withGetter
This commit is contained in:
parent
6923c2a8b7
commit
b469addd29
2 changed files with 51 additions and 65 deletions
|
|
@ -103,6 +103,7 @@ import {
|
||||||
DEFAULT_BLOSSOM_SERVERS,
|
DEFAULT_BLOSSOM_SERVERS,
|
||||||
userSpaceUrls,
|
userSpaceUrls,
|
||||||
userSettingsValues,
|
userSettingsValues,
|
||||||
|
getSetting,
|
||||||
userInboxRelays,
|
userInboxRelays,
|
||||||
userGroupSelections,
|
userGroupSelections,
|
||||||
} from "@app/core/state"
|
} from "@app/core/state"
|
||||||
|
|
@ -549,7 +550,7 @@ export const createDmAlert = async () => {
|
||||||
// Settings
|
// Settings
|
||||||
|
|
||||||
export const makeSettings = async (params: Partial<SettingsValues>) => {
|
export const makeSettings = async (params: Partial<SettingsValues>) => {
|
||||||
const json = JSON.stringify({...userSettingsValues.get(), ...params})
|
const json = JSON.stringify({...get(userSettingsValues), ...params})
|
||||||
const content = await signer.get().nip44.encrypt(pubkey.get()!, json)
|
const content = await signer.get().nip44.encrypt(pubkey.get()!, json)
|
||||||
const tags = [["d", SETTINGS]]
|
const tags = [["d", SETTINGS]]
|
||||||
|
|
||||||
|
|
@ -560,10 +561,10 @@ export const publishSettings = async (params: Partial<SettingsValues>) =>
|
||||||
publishThunk({event: await makeSettings(params), relays: Router.get().FromUser().getUrls()})
|
publishThunk({event: await makeSettings(params), relays: Router.get().FromUser().getUrls()})
|
||||||
|
|
||||||
export const addTrustedRelay = async (url: string) =>
|
export const addTrustedRelay = async (url: string) =>
|
||||||
publishSettings({trusted_relays: append(url, userSettingsValues.get().trusted_relays)})
|
publishSettings({trusted_relays: append(url, getSetting<string[]>("trusted_relays"))})
|
||||||
|
|
||||||
export const removeTrustedRelay = async (url: string) =>
|
export const removeTrustedRelay = async (url: string) =>
|
||||||
publishSettings({trusted_relays: remove(url, userSettingsValues.get().trusted_relays)})
|
publishSettings({trusted_relays: remove(url, getSetting<string[]>("trusted_relays"))})
|
||||||
|
|
||||||
// Join request
|
// Join request
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,7 @@ import {
|
||||||
SocketEvent,
|
SocketEvent,
|
||||||
netContext,
|
netContext,
|
||||||
} from "@welshman/net"
|
} from "@welshman/net"
|
||||||
import {
|
import {collection, custom, throttled, deriveEvents, deriveEventsMapped} from "@welshman/store"
|
||||||
collection,
|
|
||||||
custom,
|
|
||||||
throttled,
|
|
||||||
deriveEvents,
|
|
||||||
deriveEventsMapped,
|
|
||||||
withGetter,
|
|
||||||
} from "@welshman/store"
|
|
||||||
import {isKindFeed, findFeed} from "@welshman/feeds"
|
import {isKindFeed, findFeed} from "@welshman/feeds"
|
||||||
import {
|
import {
|
||||||
ALERT_ANDROID,
|
ALERT_ANDROID,
|
||||||
|
|
@ -241,8 +234,7 @@ export const deriveEvent = (idOrAddress: string, hints: string[] = []) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getUrlsForEvent = withGetter(
|
export const getUrlsForEvent = derived([trackerStore, thunks], ([$tracker, $thunks]) => {
|
||||||
derived([trackerStore, thunks], ([$tracker, $thunks]) => {
|
|
||||||
const getThunksByEventId = memoize(() => {
|
const getThunksByEventId = memoize(() => {
|
||||||
const thunksByEventId = new Map<string, Thunk[]>()
|
const thunksByEventId = new Map<string, Thunk[]>()
|
||||||
|
|
||||||
|
|
@ -264,8 +256,7 @@ export const getUrlsForEvent = withGetter(
|
||||||
|
|
||||||
return uniq(urls)
|
return uniq(urls)
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
|
|
||||||
export const getEventsForUrl = (url: string, filters: Filter[]) => {
|
export const getEventsForUrl = (url: string, filters: Filter[]) => {
|
||||||
const ids = uniq([
|
const ids = uniq([
|
||||||
|
|
@ -383,15 +374,13 @@ export const userSettings = makeUserData({
|
||||||
|
|
||||||
export const loadUserSettings = makeUserLoader(loadSettings)
|
export const loadUserSettings = makeUserLoader(loadSettings)
|
||||||
|
|
||||||
export const userSettingsValues = withGetter(
|
export const userSettingsValues = derived(userSettings, $s => $s?.values || defaultSettings)
|
||||||
derived(userSettings, $s => $s?.values || defaultSettings),
|
|
||||||
)
|
|
||||||
|
|
||||||
export const getSetting = <T>(key: keyof Settings["values"]) => userSettingsValues.get()[key] as T
|
export const getSetting = <T>(key: keyof Settings["values"]) => get(userSettingsValues)[key] as T
|
||||||
|
|
||||||
// Relays sending events with empty signatures that the user has to choose to trust
|
// Relays sending events with empty signatures that the user has to choose to trust
|
||||||
|
|
||||||
export const relaysPendingTrust = withGetter(writable<string[]>([]))
|
export const relaysPendingTrust = writable<string[]>([])
|
||||||
|
|
||||||
// Relays that mostly send restricted responses to requests and events
|
// Relays that mostly send restricted responses to requests and events
|
||||||
|
|
||||||
|
|
@ -416,8 +405,7 @@ export type Alert = {
|
||||||
tags: string[][]
|
tags: string[][]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const alerts = withGetter(
|
export const alerts = deriveEventsMapped<Alert>(repository, {
|
||||||
deriveEventsMapped<Alert>(repository, {
|
|
||||||
filters: [{kinds: [ALERT_EMAIL, ALERT_WEB, ALERT_IOS, ALERT_ANDROID]}],
|
filters: [{kinds: [ALERT_EMAIL, ALERT_WEB, ALERT_IOS, ALERT_ANDROID]}],
|
||||||
itemToEvent: item => item.event,
|
itemToEvent: item => item.event,
|
||||||
eventToItem: async event => {
|
eventToItem: async event => {
|
||||||
|
|
@ -429,8 +417,7 @@ export const alerts = withGetter(
|
||||||
return {event, tags}
|
return {event, tags}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
|
|
||||||
export const getAlertFeed = (alert: Alert) =>
|
export const getAlertFeed = (alert: Alert) =>
|
||||||
tryCatch(() => JSON.parse(getTagValue("feed", alert.tags)!))
|
tryCatch(() => JSON.parse(getTagValue("feed", alert.tags)!))
|
||||||
|
|
@ -450,8 +437,7 @@ export type AlertStatus = {
|
||||||
tags: string[][]
|
tags: string[][]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const alertStatuses = withGetter(
|
export const alertStatuses = deriveEventsMapped<AlertStatus>(repository, {
|
||||||
deriveEventsMapped<AlertStatus>(repository, {
|
|
||||||
filters: [{kinds: [ALERT_STATUS]}],
|
filters: [{kinds: [ALERT_STATUS]}],
|
||||||
itemToEvent: item => item.event,
|
itemToEvent: item => item.event,
|
||||||
eventToItem: async event => {
|
eventToItem: async event => {
|
||||||
|
|
@ -463,8 +449,7 @@ export const alertStatuses = withGetter(
|
||||||
return {event, tags}
|
return {event, tags}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
|
|
||||||
export const deriveAlertStatus = (address: string) =>
|
export const deriveAlertStatus = (address: string) =>
|
||||||
derived(alertStatuses, statuses => statuses.find(s => getTagValue("d", s.event.tags) === address))
|
derived(alertStatuses, statuses => statuses.find(s => getTagValue("d", s.event.tags) === address))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue