Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/go please move #378

Merged
merged 8 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.data-backend.railway
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ RUN pnpm --filter indexer-prisma build
# Build the data-backend package
# Build indexer-prisma and owned prisma
# RUN pnpm --filter data-backend build:all_repo
# Build data-backend
# RUN pnpm --filter data-backend build:all
RUN pnpm --filter data-backend build:prisma
RUN pnpm --filter data-backend build

# Use a smaller production base image
Expand Down
1 change: 1 addition & 0 deletions apps/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build:index": "tsc",
"build:all_repo": "pnpm -w run build:indexer-prisma && pnpm run prisma:setup && tsc",
"build:all": "pnpm run prisma:setup && tsc",
"build:prisma": "pnpm run prisma:setup",
"start": "ts-node src/index.ts",
"start:dev": "ts-node-dev src/index.ts",
"start:prod": "ts-node dist/index.js",
Expand Down
87 changes: 44 additions & 43 deletions apps/mobile/src/screens/Feed/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {NDKKind} from '@nostr-dev-kit/ndk';
import {useAllProfiles, useSearch} from 'afk_nostr_sdk';
import {useAuth, useContacts} from 'afk_nostr_sdk';
import {useCallback, useEffect, useState} from 'react';
import {ActivityIndicator, FlatList, Image, Pressable, RefreshControl, View, Text} from 'react-native';

import {AddPostIcon} from '../../assets/icons';
import {BubbleUser} from '../../components/BubbleUser';
import { NDKKind } from '@nostr-dev-kit/ndk';
import { useAllProfiles, useSearch } from 'afk_nostr_sdk';
import { useAuth, useContacts } from 'afk_nostr_sdk';
import { useCallback, useEffect, useState } from 'react';
import { ActivityIndicator, FlatList, Image, Pressable, RefreshControl, View, Text } from 'react-native';

import { AddPostIcon } from '../../assets/icons';
import { BubbleUser } from '../../components/BubbleUser';
import SearchComponent from '../../components/search';
import {useStyles, useTheme} from '../../hooks';
import {ChannelComponent} from '../../modules/ChannelCard';
import {PostCard} from '../../modules/PostCard';
import {VideoPostCard} from '../../modules/VideoPostCard';
import {FeedScreenProps} from '../../types';
import { useStyles, useTheme } from '../../hooks';
import { ChannelComponent } from '../../modules/ChannelCard';
import { PostCard } from '../../modules/PostCard';
import { VideoPostCard } from '../../modules/VideoPostCard';
import { FeedScreenProps } from '../../types';
import stylesheet from './styles';
import {RenderEventCard} from '../../modules/Studio';
import { RenderEventCard } from '../../modules/Studio';
import { useNotesFilter } from 'afk_nostr_sdk/src/hooks';

export const Feed: React.FC<FeedScreenProps> = ({navigation}) => {
const {theme} = useTheme();
const {publicKey} = useAuth();
export const Feed: React.FC<FeedScreenProps> = ({ navigation }) => {
const { theme } = useTheme();
const { publicKey } = useAuth();
const styles = useStyles(stylesheet);
const profiles = useAllProfiles({limit: 10});
const profiles = useAllProfiles({ limit: 10 });
const [activeSortBy, setSortBy] = useState<string | undefined>();
const [search, setSearch] = useState<string | undefined>(undefined);
const [feedData, setFeedData] = useState(null);
Expand All @@ -35,28 +35,30 @@ export const Feed: React.FC<FeedScreenProps> = ({navigation}) => {
// 30311 as NDKKind,
]);

const contacts = useContacts({authors: [publicKey]});
const contacts = useContacts({ authors: [publicKey] });
const notes = useSearch({
kinds,
limit: 10,
// authors:[]
// limit: 20,
// authors: []
});
// const notes = useNotesFilter({
// kinds,
// limit: 20,
// });
// console.log("notes", notes);
console.log("notes", notes);

// Filter profiles based on the search query
const profilesSearch =
profiles?.data?.pages?.flat() ??
// .filter((item) => (search && search?.length > 0 ? item?.content?.includes(search) : true)) ??
[];
const filteredNotes = useCallback(() => {
if (!notes.data?.pages) return [];

const flattenedPages = notes.data.pages.flat();
console.log("flattenedPages",flattenedPages)

// if (!notes.data?.pages || flattenedPages?.length == 0) return [];
if (!notes.data?.pages || flattenedPages?.length == 0) return [];

console.log("flattenedPages", flattenedPages)

console.log(flattenedPages, 'note pages');
if (!search || search.length === 0) {
Expand Down Expand Up @@ -113,25 +115,24 @@ export const Feed: React.FC<FeedScreenProps> = ({navigation}) => {
setKinds={setKinds}
setSortBy={setSortBy}
sortBy={activeSortBy}
// contactList={contacts?.data?.map((item) => item)}
// contactList={contacts?.data?.map((item) => item)}
/>

{/* {notes?.isLoading && <ActivityIndicator></ActivityIndicator>} */}
{notes?.isFetching && <ActivityIndicator></ActivityIndicator>}
{!notes?.isLoading && !notes?.isFetching && notes?.data?.pages?.length == 0 &&
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text
style={{
color:theme.colors.text
}}
>No notes found</Text>
<Text
style={{
color:theme.colors.text
}}>Try to refresh the page or contact the support please!</Text>
{/* <Button title="Go to console" onPress={() => navigation.navigate('Console')} /> */}
</View>

{!notes?.isLoading || !notes?.isFetching && notes?.data?.pages?.length == 0 &&
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text
style={{
color: theme.colors.text
}}
>No notes found</Text>
<Text
style={{
color: theme.colors.text
}}>Try to refresh the page or contact the support please!</Text>
{/* <Button title="Go to console" onPress={() => navigation.navigate('Console')} /> */}
</View>
}

<FlatList
Expand All @@ -150,14 +151,14 @@ export const Feed: React.FC<FeedScreenProps> = ({navigation}) => {
/>
}
ItemSeparatorComponent={() => <View style={styles.storySeparator} />}
renderItem={({item}) => <BubbleUser event={item} />}
renderItem={({ item }) => <BubbleUser event={item} />}
/>
</>
}
contentContainerStyle={styles.flatListContent}
data={feedData}
keyExtractor={(item) => item?.id}
renderItem={({item}) => {
renderItem={({ item }) => {
if (item.kind === NDKKind.ChannelCreation || item.kind === NDKKind.ChannelMetadata) {
return <ChannelComponent event={item} />;
} else if (item.kind === NDKKind.ChannelMessage) {
Expand Down Expand Up @@ -186,7 +187,7 @@ export const Feed: React.FC<FeedScreenProps> = ({navigation}) => {

<Pressable
style={styles.createPostButton}
onPress={() => navigation.navigate('MainStack', {screen: 'CreateForm'})}
onPress={() => navigation.navigate('MainStack', { screen: 'CreateForm' })}
>
<AddPostIcon width={72} height={72} color={theme.colors.primary} />
</Pressable>
Expand Down
6 changes: 4 additions & 2 deletions apps/mobile/src/screens/Profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NDKKind} from '@nostr-dev-kit/ndk';
import {useBookmark, useSearch} from 'afk_nostr_sdk';
import {useBookmark, useMyNotes, useSearch} from 'afk_nostr_sdk';
import {useMemo, useState} from 'react';
import {
ActivityIndicator,
Expand Down Expand Up @@ -27,7 +27,9 @@ export const Profile: React.FC<ProfileScreenProps> = ({route}) => {
}, [ndkKinds]);

// const notesSearch = useRootNotes({ authors: [publicKey] });
const search = useSearch({authors: [publicKey], kinds: kindFilter});
// const search = useSearch({authors: [publicKey], kinds: kindFilter});
const search = useMyNotes({authors: [publicKey], kinds: kindFilter});

// const reposts = useReposts({ authors: [publicKey] });
const {bookmarksWithNotes} = useBookmark(publicKey);

Expand Down
1 change: 1 addition & 0 deletions packages/afk_nostr_sdk/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export {useSendPrivateMessage} from './messages/useSendPrivateMessage';
export {useSearch} from './search/useSearch';
export {useSearchUsers} from './search/useSearchUsers';
export {useSearchTag} from './search/useTagSearch';
export {useMyNotes} from './search/useMyNotes';
export {useNotesFilter} from './search/useNotesFilter';
export {useEditEvent, useGetLiveEvents, useGetSingleEvent, useLiveActivity} from './stream';
export {useAllProfiles} from './useAllProfiles';
Expand Down
51 changes: 51 additions & 0 deletions packages/afk_nostr_sdk/src/hooks/search/useMyNotes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {NDKKind} from '@nostr-dev-kit/ndk';
import {useInfiniteQuery} from '@tanstack/react-query';

import {useNostrContext} from '../../context/NostrContext';
import { useAuth } from '../../store';

export type UseSearch = {
authors?: string[];
search?: string;
kind?: NDKKind;
kinds?: NDKKind[];
sortBy?: string;
limit?: number;
};

export const useMyNotes = (options?: UseSearch) => {
const {ndk} = useNostrContext();
const {publicKey} = useAuth();

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['search', options?.authors, options?.search, options?.kind, options?.kinds, ndk],
getNextPageParam: (lastPage: any, allPages, lastPageParam) => {
if (!lastPage?.length) return undefined;

const pageParam = lastPage[lastPage.length - 1].created_at - 1;

if (!pageParam || pageParam === lastPageParam) return undefined;
return pageParam;
},
queryFn: async ({pageParam}) => {
console.log('search query', options?.search);
// const notes = await ndk.fetchEvents({
const notes = await ndk.fetchEvents({
kinds: options?.kinds ?? [options?.kind ?? NDKKind.Text],
authors: options?.authors ?? [publicKey],
search: options?.search,
// content: options?.search,
// until: pageParam || Math.round(Date.now() / 1000),
limit: options?.limit ?? 20,
});
console.log('notes', notes);

return [...notes];
// return [...notes].filter((note) => note.tags.every((tag) => tag[0] !== 'e'));
},
placeholderData: {pages: [], pageParams: []},
});
};

export default useMyNotes;
2 changes: 1 addition & 1 deletion packages/afk_nostr_sdk/src/hooks/search/useSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useSearch = (options?: UseSearch) => {
// const notes = await ndk.fetchEvents({
const notes = await ndk.fetchEvents({
kinds: options?.kinds ?? [options?.kind ?? NDKKind.Text],
authors: options?.authors ?? [],
// authors: options?.authors ?? [], # TODO fix issue feed if authors is empty
search: options?.search,
// content: options?.search,
// until: pageParam || Math.round(Date.now() / 1000),
Expand Down
Loading