Removing // @ts-nocheck

This commit is contained in:
minimo-io 2024-04-27 17:19:41 -03:00
parent 8e75b1e4d4
commit c6024fa644
4 changed files with 61 additions and 43 deletions

View File

@ -6,7 +6,6 @@ Let promote some reciprocity here! 😹
## ToDo ## ToDo
- Create groups to checks to fire simultaneously instad of one by one (to remember: fireing all the `fetchProfile` at once for a given npub resulted in a permanent halt of the process -mainly for big users). Maybe using https://lodash.com/docs `_.chunk(array, [size=1])` - Create groups to checks to fire simultaneously instad of one by one (to remember: fireing all the `fetchProfile` at once for a given npub resulted in a permanent halt of the process -mainly for big users). Maybe using https://lodash.com/docs `_.chunk(array, [size=1])`
- Polish the proof-of-concept code, making it TS code and remove `// @ts-nocheck`!
- Create interfaces or new types instead of loose variables - Create interfaces or new types instead of loose variables
- Save followbackers and not followbackers in lists to see details. - Save followbackers and not followbackers in lists to see details.
- Create an UI/UX that's worth looking at. - Create an UI/UX that's worth looking at.

View File

@ -1,12 +1,13 @@
<script lang="ts"> <script lang="ts">
// @ts-nocheck
import NDK, { type NDKUserProfile } from "@nostr-dev-kit/ndk"; import NDK, { type NDKUserProfile } from "@nostr-dev-kit/ndk";
import type { userFollowData } from "./lib/types"; import type { Querying, FollowListed } from "./lib/types";
import { relays } from "./lib/data/relays"; import { relays } from "./lib/data/relays";
import Form from "./lib/components/form.svelte";
let npubToQuery = "npub1wujhdsytm3w6g0mpsqh8v7ezx83jcm64dlkwuqgm5v8lv0pds55ssudkw0"; let npubToQuery = "npub1wujhdsytm3w6g0mpsqh8v7ezx83jcm64dlkwuqgm5v8lv0pds55ssudkw0";
let querying: "completed" | "processing" | "uninitiated" = "uninitiated"; let querying: Querying = "uninitiated";
let userProfile: NDKUserProfile | null; let userProfile: NDKUserProfile | null;
@ -16,19 +17,19 @@
let unknownFollowBack = 0; let unknownFollowBack = 0;
let totalCountOfContactsChecked = 0; let totalCountOfContactsChecked = 0;
$: progress = ((totalCountOfContactsChecked / followsCount) * 100).toFixed() | 0; $: progress = ((totalCountOfContactsChecked / followsCount) * 100) | 0;
$: notFollowBackPercentage = ((notFollowersBack.length / originalFollow.length) * 100) | 0; $: notFollowBackPercentage = ((notFollowersBack.length / originalFollow.length) * 100) | 0;
let originalFollow = []; let originalFollow: FollowListed[] = [];
let notFollowersBack = []; let notFollowersBack: string[] = [];
async function checkFollowBacks() { async function checkFollowBacks() {
try { try {
const ndk = new NDK({ const ndk = new NDK({
explicitRelayUrls: relays, explicitRelayUrls: relays,
}); });
await ndk.connect(6000);
querying = "processing"; querying = "processing";
await ndk.connect(6000);
// create user instance // create user instance
const user = ndk.getUser({ npub: npubToQuery }); const user = ndk.getUser({ npub: npubToQuery });
@ -64,7 +65,7 @@
} }
} }
originalFollow[i].followBack = doesFollowBack ? "1" : "0"; originalFollow[i].followsBack = doesFollowBack ? "1" : "0";
// decision making time // decision making time
if (doesFollowBack) { if (doesFollowBack) {
@ -101,30 +102,22 @@
} }
</script> </script>
<form class="npub-form"> <Form
<input {progress}
disabled={querying == "processing" && progress < 100} {querying}
type="text" bind:npubToQuery
placeholder="npub to check" on:click={async () => {
bind:value={npubToQuery} querying = "uninitiated";
/> userProfile = null;
<input originalFollow = [];
type="button" notFollowersBack = [];
on:click={async () => { followBackCount = 0;
querying = true; notFollowBackCount = 0;
userProfile = null; unknownFollowBack = 0;
originalFollow = []; totalCountOfContactsChecked = 0;
notFollowersBack = []; await checkFollowBacks();
followBackCount = 0; }}
notFollowBackCount = 0; />
unknownFollowBack = 0;
totalCountOfContactsChecked = 0;
await checkFollowBacks();
}}
disabled={!npubToQuery && progress < 100}
value="Analyze"
/>
</form>
{#if userProfile} {#if userProfile}
<div class="user-box"> <div class="user-box">
@ -154,7 +147,7 @@
<ul> <ul>
{#each originalFollow as item, i} {#each originalFollow as item, i}
<li> <li>
#{ItemCount(i + 1)} - {@html item.followBack == "0" ? "<span>🔴</span>" : "<span>🟢</span>"} #{ItemCount(i + 1)} - {@html item.followsBack == "0" ? "<span>🔴</span>" : "<span>🟢</span>"}
<a target="_blank noreferrer noopener" href="https://primal.net/p/{item.npub}"> <a target="_blank noreferrer noopener" href="https://primal.net/p/{item.npub}">
{item.npub} {item.npub}
</a> </a>
@ -168,10 +161,3 @@
{:else} {:else}
<div class="loader">Loading data...</div> <div class="loader">Loading data...</div>
{/if} {/if}
<style>
.npub-form input[type="text"] {
padding: 5px;
width: 50%;
}
</style>

View File

@ -0,0 +1,30 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import type { Querying } from "../types";
const dispatch = createEventDispatcher();
export let npubToQuery = "";
export let progress = 0;
export let querying: Querying;
export let analyzeFn = function () {
dispatch("click");
};
</script>
<form class="npub-form">
<input
type="text"
placeholder="npub to check"
bind:value={npubToQuery}
disabled={querying == "processing" && progress < 100}
/>
<input type="button" on:click={analyzeFn} value="Analyze" />
</form>
<style>
.npub-form input[type="text"] {
padding: 5px;
width: 50%;
}
</style>

View File

@ -1,3 +1,6 @@
export type userFollowData = { export type Querying = "completed" | "processing" | "uninitiated";
followsCount: number;
export type FollowListed = {
npub: string;
followsBack: string;
}; };