Skip to content

Commit

Permalink
start hook react native
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Aug 9, 2024
1 parent ab5748d commit aca9300
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 72 deletions.
4 changes: 3 additions & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
"react-native-web": "~0.19.6",
"starknet": "6.9.0",
"starknetkit": "^1.1.9",
"zustand": "^4.5.2"
"zustand": "^4.5.2",
"afk_nostr_sdk":"workspace:*"

},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
71 changes: 38 additions & 33 deletions apps/mobile/src/app/Wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {Host as PortalizeProvider} from 'react-native-portalize';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { Host as PortalizeProvider } from 'react-native-portalize';
import { SafeAreaProvider } from 'react-native-safe-area-context';

import {RootScreenContainer} from '../components';
import {DialogProvider} from '../context/Dialog';
import {KeyModalProvider} from '../context/KeysModal';
import {NostrProvider} from '../context/NostrContext';
import {ThemeProvider} from '../context/Theme';
import {TipModalProvider} from '../context/TipModal';
import {ToastProvider} from '../context/Toast/ToastContext';
import {TransactionModalProvider} from '../context/TransactionModal';
import {WalletModalProvider} from '../context/WalletModal';
import { RootScreenContainer } from '../components';
import { DialogProvider } from '../context/Dialog';
import { KeyModalProvider } from '../context/KeysModal';
import { ThemeProvider } from '../context/Theme';
import { TipModalProvider } from '../context/TipModal';
import { ToastProvider } from '../context/Toast/ToastContext';
import { TransactionModalProvider } from '../context/TransactionModal';
import { WalletModalProvider } from '../context/WalletModal';
import App from './App';
import {StarknetProvider} from './StarknetProvider';
import { StarknetProvider } from './StarknetProvider';
import { NostrProvider } from '../context/NostrContext';
// import { NostrProvider } from 'afk_nostr_sdk/context/NostrContext';

const queryClient = new QueryClient({
defaultOptions: {queries: {retry: 2}},
defaultOptions: { queries: { retry: 2 } },
});

const ModalProviders = ({children}: {children: React.ReactNode}) => {
const ModalProviders = ({ children }: { children: React.ReactNode }) => {
return (
<ToastProvider>
<WalletModalProvider>
Expand All @@ -35,25 +36,29 @@ const ModalProviders = ({children}: {children: React.ReactNode}) => {

export const Wrapper: React.FC = () => {
return (
<GestureHandlerRootView style={{flex: 1}}>
<GestureHandlerRootView style={{ flex: 1 }}>
<ThemeProvider>
<NostrProvider>
<QueryClientProvider client={queryClient}>
<SafeAreaProvider>
<RootScreenContainer>
<PortalizeProvider>
<DialogProvider>
<StarknetProvider>
<ModalProviders>
<App />
</ModalProviders>
</StarknetProvider>
</DialogProvider>
</PortalizeProvider>
</RootScreenContainer>
</SafeAreaProvider>
</QueryClientProvider>
</NostrProvider>
{/* <NostrProvider> */}

<QueryClientProvider client={queryClient}>
<SafeAreaProvider>
<RootScreenContainer>
<PortalizeProvider>
<DialogProvider>
<StarknetProvider>
<ModalProviders>
<App />
</ModalProviders>
</StarknetProvider>
</DialogProvider>
</PortalizeProvider>
</RootScreenContainer>
</SafeAreaProvider>
</QueryClientProvider>
</NostrProvider>

{/* </NostrProvider> */}
</ThemeProvider>
</GestureHandlerRootView>
);
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/screens/CreatePost/FormPost/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {Image, KeyboardAvoidingView, Pressable, TextInput, View} from 'react-nat
import {SafeAreaView} from 'react-native-safe-area-context';

import {GalleryIcon, SendIconContained} from '../../../assets/icons';
import {useSendNote, useStyles, useTheme} from '../../../hooks';
import { useSendNote, useStyles, useTheme} from '../../../hooks';
import {useFileUpload} from '../../../hooks/api';
import {useToast} from '../../../hooks/modals';
import {MainStackNavigationProps} from '../../../types';
import {SelectedTab} from '../../../types/tab';
import {getImageRatio} from '../../../utils/helpers';
import stylesheet from './styles';
// import {useSendNote} from "afk_nostr_sdk/hooks"

export const FormCreatePost: React.FC = () => {
const {theme} = useTheme();
Expand Down
4 changes: 3 additions & 1 deletion apps/mobile/src/screens/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FlatList, Image, Pressable, RefreshControl, ScrollView, View } from 're
import { AddPostIcon } from '../../assets/icons';
import { Header } from '../../components';
import { BubbleUser } from '../../components/BubbleUser';
import { useRootNotes, useStyles, useTheme } from '../../hooks';
import { useStyles, useTheme } from '../../hooks';
import { useAllProfiles } from '../../hooks/nostr/useAllProfiles';
import { PostCard } from '../../modules/PostCard';
import { FeedScreenProps } from '../../types';
Expand All @@ -13,6 +13,8 @@ import SearchComponent from '../../components/search';
import { ChannelComponent } from '../../modules/ChannelCard';
import { NDKKind } from '@nostr-dev-kit/ndk';
import { useSearchNotes } from '../../hooks/nostr/useSearchNotes';
// import { useSearchNotes } from '../../hooks/nostr/useSearchNotes';
// import {useSearchNotes, useRootNotes} from "afk_nostr_sdk/hooks"

export const Feed: React.FC<FeedScreenProps> = ({ navigation }) => {
const { theme } = useTheme();
Expand Down
19 changes: 10 additions & 9 deletions apps/mobile/src/screens/Profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import {FlatList, RefreshControl, View} from 'react-native';
import { FlatList, RefreshControl, View } from 'react-native';

import {useRootNotes, useStyles} from '../../hooks';
import {PostCard} from '../../modules/PostCard';
import {ProfileScreenProps} from '../../types';
import {ProfileInfo} from './Info';
import { useRootNotes, useStyles } from '../../hooks';
import { PostCard } from '../../modules/PostCard';
import { ProfileScreenProps } from '../../types';
import { ProfileInfo } from './Info';
import stylesheet from './styles';
// import {useRootNotes} from "afk_nostr_sdk/hooks"

export const Profile: React.FC<ProfileScreenProps> = ({route}) => {
const {publicKey} = route.params ?? {};
export const Profile: React.FC<ProfileScreenProps> = ({ route }) => {
const { publicKey } = route.params ?? {};

const styles = useStyles(stylesheet);

const notes = useRootNotes({authors: [publicKey]});
const notes = useRootNotes({ authors: [publicKey] });

return (
<View style={styles.container}>
<FlatList
ListHeaderComponent={<ProfileInfo publicKey={publicKey} />}
data={notes.data?.pages.flat()}
keyExtractor={(item) => item.id}
renderItem={({item}) => <PostCard event={item} />}
renderItem={({ item }) => <PostCard event={item} />}
refreshControl={
<RefreshControl refreshing={notes.isFetching} onRefresh={() => notes.refetch()} />
}
Expand Down
6 changes: 4 additions & 2 deletions apps/mobile/src/screens/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {Header} from '../../components';
import {BubbleUser} from '../../components/BubbleUser';
import SearchComponent from '../../components/search';
import {useStyles, useTheme} from '../../hooks';
import {useAllProfiles} from '../../hooks/nostr/useAllProfiles';
import {useSearchNotes} from '../../hooks/nostr/useSearchNotes';
import {ChannelComponent} from '../../modules/ChannelCard';
import {PostCard} from '../../modules/PostCard';
import {SearchScreenProps} from '../../types';
import {SelectedTab} from '../../types/tab';
import stylesheet from './styles';
// import {useRootNotes, useSearchNotes, } from "afk_nostr_sdk/hooks"
import { useAllProfiles } from '../../hooks/nostr/useAllProfiles';
import { useSearchNotes } from '../../hooks/nostr/useSearchNotes';
// import { useSearchNotes } from 'afk_nostr_sdk/hooks';

export const Search: React.FC<SearchScreenProps> = ({navigation}) => {
const {theme} = useTheme();
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"jsx": "react-native",
"module": "ES6"
"module": "ES6",
// "paths": {
// "afk_nostr_sdk": ["../../packages/afk_nostr_sdk/src"]
// },
},
"exclude": ["node_modules", "dist", "babel.config.js", "metro.config.js", "jest.config.js"],
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
Expand Down
6 changes: 0 additions & 6 deletions packages/afk_nostr_sdk/hooks/useEditContacts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {NDKEvent, NDKKind} from '@nostr-dev-kit/ndk';
import {useMutation} from '@tanstack/react-query';
import {useNostrContext} from '../context/NostrContext';

<<<<<<<< HEAD:packages/afk_nostr_sdk/src/hooks/useEditContacts.ts
========
import {useNostrContext} from '../context/NostrContext';

>>>>>>>> main:packages/afk_nostr_sdk/hooks/useEditContacts.ts
import {useAuth} from '../store/auth';

export const useEditContacts = () => {
Expand Down
6 changes: 0 additions & 6 deletions packages/afk_nostr_sdk/hooks/useNote.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {NDKKind} from '@nostr-dev-kit/ndk';
import {useQuery} from '@tanstack/react-query';

<<<<<<<< HEAD:packages/afk_nostr_sdk/src/hooks/useNote.ts
========
// import {useNostrContext} from '../../context/NostrContext';
>>>>>>>> main:packages/afk_nostr_sdk/hooks/useNote.ts
import {useNostrContext} from '../context/NostrContext';

import {useAuth} from '../store/auth';
export type UseNoteOptions = {
noteId: string;
Expand Down
9 changes: 0 additions & 9 deletions packages/afk_nostr_sdk/hooks/useProfile.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import {useQuery} from '@tanstack/react-query';
<<<<<<<< HEAD:packages/afk_nostr_sdk/src/hooks/useProfile.ts
import {useNostrContext} from '../context/NostrContext';
========

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

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

import {useAuth} from '../store/auth';
>>>>>>>> main:packages/afk_nostr_sdk/hooks/useProfile.ts
export type UseProfileOptions = {
publicKey?: string;
};
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 @@ -12,3 +12,4 @@ export {useSendNote} from './useSendNote';
export {useSearchUsers} from './search/useSearchUsers';
export {useSearch} from './search/useSearch';
export {useSearchNotes} from './useSearchNotes';
export {useAllProfiles} from './useAllProfiles';
38 changes: 38 additions & 0 deletions packages/afk_nostr_sdk/src/hooks/useAllProfiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {NDKKind} from '@nostr-dev-kit/ndk';
import {useInfiniteQuery} from '@tanstack/react-query';

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

export type UseRootProfilesOptions = {
authors?: string[];
search?: string;
};

export const useAllProfiles = (options?: UseRootProfilesOptions) => {
const {ndk} = useNostrContext();

return useInfiniteQuery({
initialPageParam: 0,
queryKey: ['rootProfiles', options?.authors, options?.search, 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}) => {
const notes = await ndk.fetchEvents({
kinds: [NDKKind.Metadata],
authors: options?.authors,
search: options?.search,
until: pageParam || Math.round(Date.now() / 1000),
limit: 20,
});

return [...notes].filter((note) => note.tags.every((tag) => tag[0] !== 'e'));
},
placeholderData: {pages: [], pageParams: []},
});
};
2 changes: 0 additions & 2 deletions packages/afk_nostr_sdk/src/hooks/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {NDKKind} from '@nostr-dev-kit/ndk';
import {useQuery} from '@tanstack/react-query';

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

import {useAuth} from '../store/auth';
export type UseNoteOptions = {
noteId: string;
};
Expand Down
25 changes: 25 additions & 0 deletions packages/afk_nostr_sdk/tsconfig copy 4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ES6",
"moduleResolution": "node",
"outDir": "./dist",
"rootDir": "./src",
"sourceMap": true,
"declaration": true,
"composite": true,
"jsx": "react",
"baseUrl": ".",
// "paths": {
// "@/*": ["src/*"]
// }
},
"include": ["next-env.d.ts", "**/*.tsx", "src/**/*.ts", "src/**/*.tsx",],
}
2 changes: 1 addition & 1 deletion packages/afk_nostr_sdk/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/afk_nostr_sdk/utils/relay.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const RELAYS_PROD: string[];
export declare const AFK_RELAYS: string[];

0 comments on commit aca9300

Please sign in to comment.