Skip to content

Commit

Permalink
Move data to separate screen (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairaziz authored May 16, 2024
1 parent 75b5e79 commit af41481
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 77 deletions.
9 changes: 9 additions & 0 deletions examples/react-native-expo/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export default function TabLayout() {
),
}}
/>
<Tabs.Screen
name="data"
options={{
title: 'Data',
tabBarIcon: ({ color, focused }) => (
<TabBarIcon name={focused ? 'server' : 'server-outline'} color={color} />
),
}}
/>
</Tabs>
)
}
95 changes: 95 additions & 0 deletions examples/react-native-expo/app/(tabs)/data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { StyleSheet } from 'react-native'

import { PageView } from '@/components/PageView'
import { ThemedText } from '@/components/ThemedText'
import { ThemedView } from '@/components/ThemedView'
import { useQuery, gql } from '@quiltt/react-native'
import { useEffect } from 'react'
import { Colors } from '@/constants/Colors'

const SAMPLE_QUERY = gql`
query SampleQuery {
profile {
id
name
email
}
connections(filter: { status: [INITIALIZING, SYNCING, SYNCED] }) {
id
institution {
id
name
}
}
}
`

export default function HomeScreen() {
const { data, error, loading } = useQuery<{
profile: { id: string; name: string; email: string }
connections: { id: string; institution: { id: string; name: string } }[]
}>(SAMPLE_QUERY as any) // TODO: Fix type error

useEffect(() => {
if (error) {
console.error(error)
}
}, [error])

return (
<PageView title={<ThemedText type="title">Your Data</ThemedText>}>
{loading ? (
<ThemedText>Loading...</ThemedText>
) : (
<ThemedView style={styles.container}>
<ThemedView style={styles.container}>
<ThemedText style={styles.title}>Profile</ThemedText>
<ThemedText>ID: {data?.profile?.id}</ThemedText>
<ThemedText>Name: {data?.profile?.name}</ThemedText>
<ThemedText>Email: {data?.profile?.email}</ThemedText>
</ThemedView>
{data?.connections && data?.connections?.length >= 1 ? (
<ThemedView style={styles.container}>
<ThemedText style={styles.title}>Connections</ThemedText>
{data.connections.map((item, index) => (
<ThemedView
key={`${item.id}-${item.institution.id}`}
style={
index === data.connections.length - 1 ? styles.listItemLast : styles.listItem
}
>
<ThemedText>ID: {item.institution.id}</ThemedText>
<ThemedText>Name: {item.institution.name}</ThemedText>
</ThemedView>
))}
</ThemedView>
) : null}
</ThemedView>
)}
</PageView>
)
}

const styles = StyleSheet.create({
container: {
gap: 4,
marginBottom: 16,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginTop: 8,
},
listItem: {
gap: 2,
borderBottomColor: Colors.light.muted,
borderBottomWidth: 1,
paddingVertical: 8,
},
listItemLast: {
gap: 2,
borderBottomColor: Colors.light.muted,
borderBottomWidth: 0,
paddingVertical: 8,
},
})
77 changes: 0 additions & 77 deletions examples/react-native-expo/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,8 @@ import { PageView } from '@/components/PageView'
import { ThemedText } from '@/components/ThemedText'
import { ThemedView } from '@/components/ThemedView'
import { ButtonLink } from '@/components/ButtonLink'
import { useQuery, gql } from '@quiltt/react-native'
import { useEffect } from 'react'
import { Colors } from '@/constants/Colors'

const SAMPLE_QUERY = gql`
query SampleQuery {
profile {
id
name
email
}
connections(filter: { status: [INITIALIZING, SYNCING, SYNCED] }) {
id
institution {
id
name
}
}
}
`

export default function HomeScreen() {
const { data, error, loading } = useQuery<{
profile: { id: string; name: string; email: string }
connections: { id: string; institution: { id: string; name: string } }[]
}>(SAMPLE_QUERY as any) // TODO: Fix type error

useEffect(() => {
if (error) {
console.error(error)
}
}, [error])

return (
<PageView
title={
Expand All @@ -50,35 +19,6 @@ export default function HomeScreen() {
<ThemedView style={styles.container}>
<ButtonLink href="/connector">Launch Connector</ButtonLink>
</ThemedView>

{loading ? (
<ThemedText>Loading...</ThemedText>
) : (
<ThemedView style={styles.container}>
<ThemedView style={styles.container}>
<ThemedText style={styles.title}>Profile</ThemedText>
<ThemedText>ID: {data?.profile?.id}</ThemedText>
<ThemedText>Name: {data?.profile?.name}</ThemedText>
<ThemedText>Email: {data?.profile?.email}</ThemedText>
</ThemedView>
{data?.connections && data?.connections?.length >= 1 ? (
<ThemedView style={styles.container}>
<ThemedText style={styles.title}>Connections</ThemedText>
{data.connections.map((item, index) => (
<ThemedView
key={`${item.id}-${item.institution.id}`}
style={
index === data.connections.length - 1 ? styles.listItemLast : styles.listItem
}
>
<ThemedText>ID: {item.institution.id}</ThemedText>
<ThemedText>Name: {item.institution.name}</ThemedText>
</ThemedView>
))}
</ThemedView>
) : null}
</ThemedView>
)}
</PageView>
)
}
Expand All @@ -88,21 +28,4 @@ const styles = StyleSheet.create({
gap: 4,
marginBottom: 16,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginTop: 8,
},
listItem: {
gap: 2,
borderBottomColor: Colors.light.muted,
borderBottomWidth: 1,
paddingVertical: 8,
},
listItemLast: {
gap: 2,
borderBottomColor: Colors.light.muted,
borderBottomWidth: 0,
paddingVertical: 8,
},
})
64 changes: 64 additions & 0 deletions examples/react-native-expo/wip.metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// TODO: Not currently in use, but would be great if we could just link local packages

/**
* Link local packages in React Native, metro doesn't like symlink.
* This is only for using the example app, you shouldn't need this in your app.
* Adding `@quiltt/react-native` in `package.json` should work just fine.
*
* @see https://medium.com/@alielmajdaoui/linking-local-packages-in-react-native-the-right-way-2ac6587dcfa2
*
* @see https://docs.expo.io/guides/customizing-metro
*/

const path = require('path')
const { getDefaultConfig } = require('@expo/metro-config')

const root = path.resolve(__dirname, '..', '..')
const packages = path.resolve(root, 'packages')

const defaultConfig = getDefaultConfig(__dirname)

const siblings = {
// Enable this to import local package
'@quiltt/react-native': path.resolve(packages, 'react-native', 'dist'),
}

module.exports = {
...defaultConfig,
projectRoot: __dirname,
transformer: {
...defaultConfig.transformer,
getTransformOptions: async () => ({
...defaultConfig.transformer.getTransformOptions(),
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
...defaultConfig.resolver,
extraNodeModules: new Proxy(
{},
{
get: (_target, name) =>
name in siblings ? siblings[name] : path.resolve(process.cwd(), 'node_modules', name),
}
),
},
server: {
...defaultConfig.server,
enhanceMiddleware: (middleware) => {
return (req, res, next) => {
// When an asset is imported outside the project root, it has wrong path on Android
// So we fix the path to correct one
if (/\/packages\/.+\.png\?.+$/.test(req.url)) {
req.url = `/assets/../${req.url}`
}

return middleware(req, res, next)
}
},
},
watchFolders: [...defaultConfig.watchFolders, root, ...Object.values(siblings)],
}

0 comments on commit af41481

Please sign in to comment.