-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from samuelralak/identity-context
Problem: logic not totally clear
- Loading branch information
Showing
8 changed files
with
131 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts"> | ||
import {getContext, setContext} from "svelte"; | ||
import {consensusTipState, recursiveList} from "$lib/consensus/state"; | ||
import {derived, get, type Stores} from "svelte/store"; | ||
import {type Account} from "$lib/types"; | ||
import {ignitionPubkey, nostrocketIgnitionEvent} from "$lib/settings"; | ||
import {profiles} from "$lib/stores/profiles"; | ||
import ndk from "$lib/stores/ndk"; | ||
import {NDKUser} from "@nostr-dev-kit/ndk"; | ||
const currentTipState = getContext('consensusTipState') | ||
const nostrocketParticipants = derived(consensusTipState, ($cts) => { | ||
let orderedList: Account[] = []; | ||
recursiveList(nostrocketIgnitionEvent, ignitionPubkey, $cts, orderedList); | ||
return orderedList; | ||
}); | ||
nostrocketParticipants.subscribe((pkList) => { | ||
pkList.forEach((pk) => { | ||
let user = $ndk.getUser({hexpubkey: pk}) | ||
user.fetchProfile().then((profile) => { | ||
if (user.profile) { | ||
profiles.update((data) => { | ||
data.set(user.pubkey, user); | ||
return data; | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
const nostrocketParticipantProfiles = derived(profiles, ($p) => { | ||
let orderedProfiles: { profile: NDKUser; index: number }[] = []; | ||
get(nostrocketParticipants).forEach((pk, i) => { | ||
let profile = $p.get(pk); | ||
if (profile) { | ||
orderedProfiles.push({profile: profile, index: i}); | ||
} | ||
}); | ||
return orderedProfiles.reverse(); | ||
}); | ||
setContext('nostrocketParticipants', nostrocketParticipants) | ||
setContext('nostrocketParticipantProfiles', nostrocketParticipantProfiles) | ||
</script> | ||
|
||
<main> | ||
<slot/> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {type Writable, writable} from 'svelte/store'; | ||
|
||
export default class BaseStore { | ||
protected static instance: BaseStore; | ||
protected data: Writable<{}>; | ||
|
||
protected constructor(input: {}) { | ||
this.data = writable(input); // Initialize Svelte store | ||
} | ||
|
||
static getInstance(input): BaseStore { | ||
if (!BaseStore.instance) { | ||
BaseStore.instance = new BaseStore(input); | ||
} | ||
return BaseStore.instance; | ||
} | ||
|
||
get store() { | ||
return this.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {type Writable} from "svelte/store"; | ||
import BaseStore from "$lib/stores/base-store"; | ||
import {ignitionPubkey} from "$lib/settings"; | ||
|
||
interface Identity { | ||
publicKeys: string[] | ||
} | ||
|
||
interface ISoftState { | ||
identity: Identity | ||
} | ||
|
||
class SoftState extends BaseStore { | ||
// override protected allows us to enforce type | ||
protected data: Writable<ISoftState> | ||
|
||
protected constructor(input: ISoftState) { | ||
super(input) | ||
} | ||
} | ||
|
||
const _default: ISoftState = { | ||
identity: { | ||
publicKeys: [ignitionPubkey] | ||
} | ||
} | ||
|
||
export default SoftState.getInstance(_default).store |