Start breaking out tabs into separate components

This commit is contained in:
Jonathan Staab 2022-12-20 09:39:18 -08:00
parent 831ef12ab5
commit bc7591bb8c
5 changed files with 75 additions and 15 deletions

View File

@ -20,6 +20,7 @@ Coracle is currently in _alpha_ - expect bugs, slow loading times, and rough edg
- [ ] An actual readme
- [ ] Server discovery and relay publishing - https://github.com/nostr-protocol/nips/pull/32/files
- [ ] Support invoices https://twitter.com/jb55/status/1604131336247476224
- [ ] Indexing server
# Bugs
@ -33,6 +34,7 @@ Coracle is currently in _alpha_ - expect bugs, slow loading times, and rough edg
- [ ] Stack views so scroll position isn't lost on navigation
- [ ] We're sending client=astral tags, event id 125ff9dc495f65d302e8d95ea6f9385106cc31b81c80e8c582b44be92fa50c44
- [ ] Add notification for slow relays
- [ ] Wait for 60% or so of relays to eose to balance completeness with speed
# Curreent update
@ -49,6 +51,11 @@ Coracle is currently in _alpha_ - expect bugs, slow loading times, and rough edg
- [x] Sync user
- [x] Based on petnames, sync network to 2 or 3 degrees of separation
- When a user is added/removed, sync them and add to or remove from network
- [ ] Add cursor object to handle since/until/last sync
- [ ] Separate fetching and loading from the db
- Each route should have a fetcher and loader.
- The fetcher should keep track of the range of notes it has already gotten
- Separate helper functions into loaders and fetchers
- [ ] Main fetch requests:
- Fetch feed by name, since last sync
- Fetch person, including feed

View File

@ -174,22 +174,12 @@ const syncNetwork = async () => {
for (let depth = 0; depth < 1; depth++) {
const events = await loadPeople(pubkeys)
pubkeys = uniq(filterTags({type: "p"}, events.filter(e => e.kind === 3)))
authors = authors.concat(pubkeys)
pubkeys = filterTags({type: "p"}, events.filter(e => e.kind === 3))
authors = uniq(authors.concat(pubkeys))
}
// Save this for next time
db.network.set(authors)
// Grab everything since our most recent sync
const since = getLocalJson('syncNetwork/lastSync') || now() - timedelta(30, 'days')
loadEvents({kinds: [1, 5, 7], authors, since, until: now()})
listenForEvents('pool/networkNotes', {kinds: [1, 5, 7], authors, since: now()})
// Save our position to speed up next page load
setLocalJson('syncNetwork/lastSync', now() - timedelta(5, 'minutes'))
}
export default {

View File

@ -80,7 +80,7 @@
{:else}
<Tabs tabs={['network', 'global']} {activeTab} {setActiveTab} />
{#if activeTab === 'network'}
<Notes shouldMuffle loadNotes={loadNetworkNotes} />
<Network />
{:else}
<Notes shouldMuffle loadNotes={loadGlobalNotes} />
{/if}

View File

@ -83,8 +83,8 @@ export const createScroller = loadMore => {
export const randomChoice = xs => xs[Math.floor(Math.random() * xs.length)]
export const getLastSync = (keyParts, fallback) => {
const key = `${keyParts.join('.')}/lastSync`
export const getLastSync = (k, fallback) => {
const key = `${k}/lastSync`
const lastSync = getLocalJson(key) || fallback
setLocalJson(key, now())

63
src/views/Network.svelte Normal file
View File

@ -0,0 +1,63 @@
<script>
import {onMount, onDestroy} from 'svelte'
import {navigate} from 'svelte-routing'
import {findReply} from 'src/util/nostr'
import Anchor from "src/partials/Anchor.svelte"
import Tabs from "src/partials/Tabs.svelte"
import Notes from "src/views/Notes.svelte"
import {now, timedelta} from 'src/util/misc'
import relay, {network, connections} from 'src/relay'
let sub
let since = getLastSync('views/Network')
onMount(async () => {
sub = await subscribe(now())
})
onDestroy(() => {
if (sub) {
sub.unsub()
}
})
const setActiveTab = tab => navigate(`/notes/${tab}`)
const subscribe = until =>
relay.pool.listenForEvents(
'views/Network',
[{kinds: [1, 5, 7], authors: $network, since, until}],
async e => {
if (e.kind === 1) {
const filter = await relay.buildNoteContextFilter(e, {since})
await relay.pool.loadEvents(filter)
}
if (e.kind === 7) {
const replyId = findReply(e)
if (replyId && !await relay.db.events.get(replyId)) {
await relay.pool.loadEvents({kinds: [1], ids: [replyId]})
}
}
}
)
const loadNotes = async limit => {
const filter = {kinds: [1], authors: $network}
const notes = await relay.filterEvents(filter).reverse().sortBy('created_at')
if (notes.length < limit) {
until = notes.reduce((t, n) => Math.min(n.created_at), since)
since = until - timedelta(1, 'hours')
sub = await subscribe(since)
}
return relay.annotateChunk(notes.slice(0, limit))
}
</script>
<Notes shouldMuffle loadNotes={loadNotes} />