-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add React Query command #26
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import getProjectDir from './getProjectDir'; | ||
import appendToFile from './appendToFile'; | ||
|
||
/** | ||
* lines should be separated by newlines | ||
*/ | ||
export default async function addToGitignore(lines: string) { | ||
return fs.appendFile( | ||
path.join(await getProjectDir(), '.gitignore'), | ||
`\n${lines}`, | ||
); | ||
return appendToFile('.gitignore', lines); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import getProjectDir from './getProjectDir'; | ||
/** | ||
* lines should be separated by newlines | ||
*/ | ||
export default async function appendToFile(filename: string, lines: string) { | ||
return fs.appendFile( | ||
path.join(await getProjectDir(), filename), | ||
`\n${lines}`, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
import { screen } from '@testing-library/react-native'; | ||
|
||
import RootNavigator from 'src/navigators/RootNavigator'; | ||
import render from 'src/test/render'; | ||
import mock from 'src/test/mock'; | ||
import { renderApplication } from 'src/test/render'; | ||
|
||
test('renders', async () => { | ||
// We would not normally recommend fake timers, but the tests are currently | ||
// throwing a "not wrapped in act" warning after this test finishes. One | ||
// option is to put a `await waitForUpdates()` at the end of the test, but | ||
// fake timers also work here until we find a better solution. The stack trace | ||
// seems to point to React Navigation bottom tabs. | ||
jest.useFakeTimers(); | ||
render(<RootNavigator />); | ||
expect(await screen.findByText(/Open up App.tsx/)).toBeDefined(); | ||
|
||
const mocks = [mockCoffees()]; | ||
|
||
renderApplication({ mocks }); | ||
|
||
expect(await screen.findByRole('header', { name: 'Mocha' })).toBeDefined(); | ||
}); | ||
|
||
function mockCoffees() { | ||
return mock.get('coffee/hot', { | ||
response: [ | ||
{ | ||
id: 1, | ||
title: 'Mocha', | ||
image: 'htps://placehold.it/200x200', | ||
}, | ||
], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { FlatList, Image, Text, View } from 'react-native'; | ||
import api, { Coffee as CoffeeType } from 'src/util/api/api'; | ||
|
||
// TODO: sample data, remove | ||
export default function ExampleCoffees() { | ||
const { data } = useQuery({ queryKey: ['coffee'], queryFn: api.coffee }); | ||
|
||
return ( | ||
<> | ||
<Text style={{ fontWeight: '600', fontSize: 24 }}>Coffees</Text> | ||
<FlatList | ||
data={data?.slice(0, 4)} | ||
numColumns={2} | ||
scrollEnabled={false} | ||
renderItem={({ item }) => <Coffee coffee={item} />} | ||
keyExtractor={(item) => item.id.toString()} | ||
style={{ flexGrow: 0 }} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
function Coffee({ coffee }: { coffee: CoffeeType }) { | ||
const { title, image } = coffee; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: 'salmon', | ||
borderRadius: 10, | ||
padding: 16, | ||
margin: 10, | ||
}} | ||
> | ||
<Text accessibilityRole="header" style={{ fontWeight: '600' }}> | ||
{title} | ||
</Text> | ||
<Image | ||
width={100} | ||
height={100} | ||
source={{ uri: image }} | ||
accessibilityIgnoresInvertColors | ||
/> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of having both the
addToGitignore
and theappendToFile
to the samefileUtils
file? This would keep thesrc/util
leaner and keep related utilities together instead of having 1 file per function.