Skip to content

Commit

Permalink
problem: can't see people's discussions about rockets
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Jan 27, 2024
1 parent c27b3b1 commit e84bf72
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 50 deletions.
31 changes: 22 additions & 9 deletions src/components/views/RocketHome.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Tab,
Tabs,
Tag,
Tile,
} from "carbon-components-svelte";
import CommentsWrapper from "../comments/CommentsWrapper.svelte";
import ProfileSmall from "../elements/ProfileSmall.svelte";
Expand All @@ -22,7 +23,7 @@
type ExtendedBaseType,
type NDKEventStore,
} from "@nostr-dev-kit/ndk-svelte";
import { writable } from "svelte/store";
import { derived, writable, type Readable } from "svelte/store";
import type { NDKEvent } from "@nostr-dev-kit/ndk";
import { onMount } from "svelte";
Expand Down Expand Up @@ -115,16 +116,24 @@
let s = writable(_search);
let searchResults: NDKEventStore<ExtendedBaseType<NDKEvent>>;
let searchResultsToRender: Readable<
ExtendedBaseType<ExtendedBaseType<NDKEvent>>[]
>;
let initted = false;
$: {
if (rocket && !initted) {
initted = true;
_search.connect().then(() => {
console.log("nostr.band");
searchResults = $s.storeSubscribe<NDKEvent>({search: rocket.Name}, { closeOnEose: false });
searchResults.subscribe((x) => {
console.log(x);
console.log("search relay connected");
searchResults = $s.storeSubscribe<NDKEvent>(
{ kinds: [1], search: rocket.Name },
{ closeOnEose: true }
);
searchResultsToRender = derived(searchResults, ($results) => {
let r = $results.filter((x) => {
return x.content.length < 1000;
});
return r;
});
});
}
Expand Down Expand Up @@ -158,7 +167,7 @@
label="Discussion"
on:click={() => {
goto(`${base}/${rocket.Name}/discussion`);
}}>Discussion</Tab
}}>Discussion <Tag>{$searchResultsToRender?.length}</Tag></Tab
>
<Tab
label="Merits"
Expand Down Expand Up @@ -198,8 +207,12 @@
{#if selectedTab == "discussion"}
<CommentsWrapper parentId={rocket.UID} isRoot />
{#if $searchResults}
{#each [...$searchResults] as e}
{e.content}
{#each [...$searchResultsToRender] as e}
<Tile style="margin:2px;"
><p><ProfileSmall pubkey={e.pubkey} /></p>
<p>{e.content}</p>
<a href={`https://primal.net/e/${e.id}`}>primal</a></Tile
>
{/each}{/if}
{/if}

Expand Down
66 changes: 43 additions & 23 deletions src/lib/helpers/bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { get, writable } from "svelte/store";
import { unixTimeNow } from "./mundane";

var latestBitcoinHeight = 0;
Expand All @@ -15,40 +16,59 @@ function synchronousRequest(url: string): string {
}
}

let _b:BitcoinTip = {hash: "", height: 0}
export let bitcoinTip = writable(_b)



export function BitcoinHeightTag(): string[] {
let tip = BitcoinTipHeight();
let tip = get(bitcoinTip)
let bths: string[] = ["bitcoin", ""];
if (tip.hash && tip.height) {
bths = ["bitcoin", tip.height.toString() + ":" + tip.hash];
}
return bths;
}

export function BitcoinTipHeight(): BitcoinTip {
let bitcoinHeight = latestBitcoinHeight;
let bitcoinHash = latestBitcoinHash;
if (unixTimeNow() > lastCheckTime + 60) {
try {
let response = synchronousRequest(
"https://blockstream.info/api/blocks/tip"
);
let responseJSON = JSON.parse(response);
bitcoinHeight = responseJSON[0].height;
latestBitcoinHeight = bitcoinHeight;
bitcoinHash = responseJSON[0].id;
latestBitcoinHash = bitcoinHash;
lastCheckTime = unixTimeNow();
} catch (err) {
console.log(err);
}
export async function getBitcoinTip() {
const response = await fetch("https://blockstream.info/api/blocks/tip")
const _json = await response.json()
if (_json[0]) {
let r: BitcoinTip = {
height: _json[0].height,
hash: _json[0].id,
};
bitcoinTip.set(r)
return r;
}
let r: BitcoinTip = {
height: bitcoinHeight,
hash: bitcoinHash,
};
return r;
return null
}

// export function BitcoinTipHeight(): BitcoinTip {
// let bitcoinHeight = latestBitcoinHeight;
// let bitcoinHash = latestBitcoinHash;
// if (unixTimeNow() > lastCheckTime + 60) {
// try {
// let response = synchronousRequest(
// "https://blockstream.info/api/blocks/tip"
// );
// let responseJSON = JSON.parse(response);
// bitcoinHeight = responseJSON[0].height;
// latestBitcoinHeight = bitcoinHeight;
// bitcoinHash = responseJSON[0].id;
// latestBitcoinHash = bitcoinHash;
// lastCheckTime = unixTimeNow();
// } catch (err) {
// console.log(err);
// }
// }
// let r: BitcoinTip = {
// height: bitcoinHeight,
// hash: bitcoinHash,
// };
// return r;
// }

type BitcoinTip = {
height: number;
hash: string;
Expand Down
31 changes: 19 additions & 12 deletions src/routes/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
<script lang="ts">
import { weHaveTheLead } from "$lib/consensus/votepower";
import { BitcoinTipHeight } from "$lib/helpers/bitcoin";
import { bitcoinTip, getBitcoinTip } from "$lib/helpers/bitcoin";
import { unixTimeNow } from "$lib/helpers/mundane";
import { currentUser } from "$lib/stores/hot_resources/current-user";
import {
breakpointObserver,
Header,
HeaderAction,
HeaderGlobalAction,
Expand All @@ -20,15 +20,14 @@
SideNavMenuItem,
SkipToContent,
Tag,
breakpointObserver,
} from "carbon-components-svelte";
import { Network_1, UserAvatarFilledAlt } from "carbon-icons-svelte";
import SettingsAdjust from "carbon-icons-svelte/lib/SettingsAdjust.svelte";
import menu from "./menu";
import { defaultRelays, profileRelays, testnet } from "../settings";
import LoginNip07Button from "../components/elements/LoginNIP07Button.svelte";
import CommentUser from "../components/comments/CommentUser.svelte";
import { derived } from "svelte/store";
import { consensusTipState } from "$lib/stores/nostrocket_state/master_state";
import LoginNip07Button from "../components/elements/LoginNIP07Button.svelte";
import { defaultRelays, profileRelays, testnet } from "../settings";
import menu from "./menu";
const size = breakpointObserver();
const larger = size.largerThan("md");
Expand All @@ -38,9 +37,17 @@
isSideNavOpen = !larger;
}
let bth = derived(consensusTipState, (c)=>{
return BitcoinTipHeight().height
})
let lastRequestTime = 0
$:{
if (unixTimeNow() > lastRequestTime+30000) {
getBitcoinTip().then(x=>{
if (x) {
lastRequestTime = unixTimeNow()
}
})
}
}
</script>

Expand Down Expand Up @@ -79,7 +86,7 @@
<a
href="https://blockstream.info/"
style="text-decoration: none;color:coral;"
><h6>{$bth}</h6></a
><h6>{$bitcoinTip.height}</h6></a
>
</div>
<HeaderAction icon={Network_1}>
Expand Down
6 changes: 0 additions & 6 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ export const profileRelays = [
"wss://nostr.688.org",
"wss://relay.damus.io",
"wss://nos.lol",
"wss://nostr.mom",
"wss://atlas.nostr.land",
"wss://eden.nostr.land",
"wss://nostr-pub.wellorder.net",
"wss://saltivka.org",
"wss://relay.damus.io",
"wss://relay.nostr.bg",
"wss://nostr.wine",
"wss://nos.lol",
"wss://nostr.mom",
"wss://atlas.nostr.land",
"wss://relay.snort.social",
"wss://offchain.pub",
"wss://relay.primal.net",
"wss://public.relaying.io"
];

export const defaultRelays = [
Expand Down

0 comments on commit e84bf72

Please sign in to comment.