Skip to content

Commit

Permalink
Updated maximum follower count value for WoT filter
Browse files Browse the repository at this point in the history
  • Loading branch information
calvadev authored and Replit user committed May 31, 2024
1 parent 2fd03f7 commit 83a22db
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
11 changes: 9 additions & 2 deletions components/utility-components/shopstr-slider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useState, useEffect } from "react";
import { useState, useEffect, useContext } from "react";
import { Button } from "@nextui-org/react";
import { Slider } from "@nextui-org/react";
import { useTheme } from "next-themes";
import { FollowsContext } from "../../utils/context/context";
import { getLocalStorageData } from "../../components/utility/nostr-helper-functions";
import { SHOPSTRBUTTONCLASSNAMES } from "../../components/utility/STATIC-VARIABLES";

const ShopstrSlider = () => {
const { theme, setTheme } = useTheme();

const followsContext = useContext(FollowsContext);

const [wot, setWot] = useState(getLocalStorageData().wot);
const [wotIsChanged, setWotIsChanged] = useState(false);

Expand All @@ -29,7 +32,11 @@ const ShopstrSlider = () => {
color={theme === "dark" ? "warning" : "secondary"}
label="Minimum Follower Count:"
showSteps={true}
maxValue={10}
maxValue={
!followsContext.isLoading && followsContext.firstDegreeFollowsLength
? followsContext.firstDegreeFollowsLength
: 10
}
minValue={1}
defaultValue={wot}
className="max-w-md text-light-text dark:text-dark-text"
Expand Down
9 changes: 7 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function App({ Component, pageProps }: AppProps) {
const [followsContext, setFollowsContext] = useState<FollowsContextInterface>(
{
followList: [],
firstDegreeFollowsLength: 0,
isLoading: true,
},
);
Expand Down Expand Up @@ -124,8 +125,12 @@ function App({ Component, pageProps }: AppProps) {
setChatsContext({ chatsMap, isLoading });
};

const editFollowsContext = (followList: string[], isLoading: boolean) => {
setFollowsContext({ followList, isLoading });
const editFollowsContext = (
followList: string[],
firstDegreeFollowsLength: number,
isLoading: boolean,
) => {
setFollowsContext({ followList, firstDegreeFollowsLength, isLoading });
};

/** FETCH initial PRODUCTS and PROFILES **/
Expand Down
25 changes: 22 additions & 3 deletions pages/api/nostr/fetch-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ export const fetchChatsAndMessages = async (
};

export const fetchAllFollows = async (
editFollowsContext: (followList: string[], isLoading: boolean) => void,
editFollowsContext: (
followList: string[],
firstDegreeFollowsLength: number,
isLoading: boolean,
) => void,
): Promise<{
followList: string[];
}> => {
Expand All @@ -288,6 +292,7 @@ export const fetchAllFollows = async (

let followsArrayFromRelay: string[] = [];
const followsSet: Set<string> = new Set();
let firstDegreeFollowsLength = 0;

const firstFollowfilter: Filter = {
kinds: [3],
Expand All @@ -302,6 +307,8 @@ export const fetchAllFollows = async (
validTags.forEach((pubkey) => followsSet.add(pubkey));
followsArrayFromRelay.push(...validTags);

firstDegreeFollowsLength = followsArrayFromRelay.length;

const secondFollowFilter: Filter = {
kinds: [3],
authors: followsArrayFromRelay,
Expand Down Expand Up @@ -334,13 +341,19 @@ export const fetchAllFollows = async (
},
oneose() {
first.close();
returnCall(relay, followsArrayFromRelay, followsSet);
returnCall(
relay,
followsArrayFromRelay,
followsSet,
firstDegreeFollowsLength,
);
},
});
const returnCall = async (
relay: Relay,
followsArray: string[],
followsSet: Set<string>,
firstDegreeFollowsLength: number,
) => {
// If followsArrayFromRelay is still empty, add the default value
if (followsArray.length === 0) {
Expand All @@ -361,6 +374,8 @@ export const fetchAllFollows = async (
validTags.forEach((pubkey) => followsSet.add(pubkey));
followsArray.push(...validTags);

firstDegreeFollowsLength = followsArray.length;

const secondFollowFilter: Filter = {
kinds: [3],
authors: followsArray,
Expand Down Expand Up @@ -399,7 +414,11 @@ export const fetchAllFollows = async (
resolve({
followList: followsArrayFromRelay,
});
editFollowsContext(followsArrayFromRelay, false);
editFollowsContext(
followsArrayFromRelay,
firstDegreeFollowsLength,
false,
);
};
} catch (error) {
console.log("failed to fetch follow list: ", error);
Expand Down
2 changes: 2 additions & 0 deletions utils/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export const ChatsContext = createContext({

export interface FollowsContextInterface {
followList: string[];
firstDegreeFollowsLength: number;
isLoading: boolean;
}

export const FollowsContext = createContext({
followList: [],
firstDegreeFollowsLength: 0,
isLoading: true,
} as FollowsContextInterface);

0 comments on commit 83a22db

Please sign in to comment.