Fix toSpliced and creating a list based on a feed selection

This commit is contained in:
Jon Staab 2024-05-22 12:54:05 -07:00
parent 3be28bd615
commit 49ecaf4d99
3 changed files with 18 additions and 27 deletions

View File

@ -11,7 +11,21 @@
export let feed
export let onChange
const list = (() => {
const openForm = () => {
formIsOpen = true
}
const closeForm = event => {
formIsOpen = false
if (event) {
onChange(makeListFeed({addresses: [getAddress(event)]}))
}
}
let formIsOpen = false
$: list = (() => {
if (isAuthorFeed(feed)) {
return makeList({kind: NAMED_PEOPLE, tags: feed.slice(1).map(mention)})
} else if (isMentionFeed(feed)) {
@ -27,20 +41,6 @@
throw new Error(`Invalid feed type ${feed[0]} passed to FeedFormSaveAsList`)
}
})()
const openForm = () => {
formIsOpen = true
}
const closeForm = event => {
formIsOpen = false
if (event) {
onChange(makeListFeed({addresses: [getAddress(event)]}))
}
}
let formIsOpen = false
</script>
<div class="flex flex-col items-end">

View File

@ -97,7 +97,7 @@ export class FeedLoader {
await Promise.all(
Array.from(getRequestItems({relays, filters})).map(opts =>
load({...opts, onEvent, tracker, signal, skipCache: true}),
load({...opts, onEvent, tracker, signal, skipCache: Boolean(relays)}),
),
)
},

View File

@ -362,14 +362,5 @@ export class SearchHelper<T, V> {
export const fromCsv = s => (s || "").split(",").filter(identity)
export const toSpliced = <T>(xs: T[], start: number, deleteCount?: number, ...items: T[]) => {
const copy = [...xs]
if (deleteCount) {
copy.splice(start, deleteCount, ...items)
} else {
copy.splice(start)
}
return copy
}
export const toSpliced = <T>(xs: T[], start: number, deleteCount: number = 0, ...items: T[]) =>
[...xs.slice(0, start), ...items, ...xs.slice(start + deleteCount)]