Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 8b14d31

Browse files
samoussfrancoischalifour
authored andcommitted
feat(templates): Add React Native template (#53)
1 parent 6172348 commit 8b14d31

File tree

16 files changed

+595
-3
lines changed

16 files changed

+595
-3
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Options with unknown template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch.js, React InstantSearch, Vue InstantSearch"`;
3+
exports[`Options with unknown template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
44

55
exports[`Options with unvalid name throws 1`] = `
66
"Could not create a project called \\"./WrongNpmName\\" because of npm naming restrictions.
77
- name cannot start with a period
88
- name can only contain URL-friendly characters"
99
`;
1010

11-
exports[`Options with wrong template path throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch.js, React InstantSearch, Vue InstantSearch"`;
11+
exports[`Options with wrong template path throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
1212

1313
exports[`Options without path throws 1`] = `"The option \`path\` is required."`;
1414

15-
exports[`Options without template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch.js, React InstantSearch, Vue InstantSearch"`;
15+
exports[`Options without template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;

scripts/__snapshots__/e2e-templates.test.js.snap

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,320 @@ Array [
16101610
]
16111611
`;
16121612
1613+
exports[`Templates React InstantSearch Native File content: .babelrc 1`] = `
1614+
"{
1615+
\\"presets\\": [\\"babel-preset-expo\\"],
1616+
\\"env\\": {
1617+
\\"development\\": {
1618+
\\"plugins\\": [\\"transform-react-jsx-source\\"]
1619+
}
1620+
}
1621+
}"
1622+
`;
1623+
1624+
exports[`Templates React InstantSearch Native File content: .editorconfig 1`] = `
1625+
"root = true
1626+
1627+
[*]
1628+
charset = utf-8
1629+
indent_style = space
1630+
indent_size = 2
1631+
end_of_line = lf
1632+
insert_final_newline = true
1633+
trim_trailing_whitespace = true"
1634+
`;
1635+
1636+
exports[`Templates React InstantSearch Native File content: .eslintrc.js 1`] = `
1637+
"module.exports = {
1638+
extends: 'algolia/react',
1639+
};"
1640+
`;
1641+
1642+
exports[`Templates React InstantSearch Native File content: .gitignore 1`] = `
1643+
"# See https://help.github.com/ignore-files/ for more about ignoring files.
1644+
1645+
# expo
1646+
.expo/
1647+
1648+
# dependencies
1649+
/node_modules
1650+
1651+
# misc
1652+
.env.local
1653+
.env.development.local
1654+
.env.test.local
1655+
.env.production.local
1656+
1657+
npm-debug.log*
1658+
yarn-debug.log*
1659+
yarn-error.log*"
1660+
`;
1661+
1662+
exports[`Templates React InstantSearch Native File content: .prettierrc 1`] = `
1663+
"{
1664+
\\"singleQuote\\": true,
1665+
\\"proseWrap\\": \\"never\\",
1666+
\\"trailingComma\\": \\"es5\\"
1667+
}"
1668+
`;
1669+
1670+
exports[`Templates React InstantSearch Native File content: .watchmanconfig 1`] = `"{}"`;
1671+
1672+
exports[`Templates React InstantSearch Native File content: App.js 1`] = `
1673+
"import React from 'react';
1674+
import { StyleSheet, View, SafeAreaView, StatusBar } from 'react-native';
1675+
import algoliasearch from 'algoliasearch/reactnative';
1676+
import { InstantSearch } from 'react-instantsearch-native';
1677+
import SearchBox from './src/SearchBox';
1678+
import InfiniteHits from './src/InfiniteHits';
1679+
1680+
const searchClient = algoliasearch(
1681+
'appId',
1682+
'apiKey'
1683+
);
1684+
1685+
const styles = StyleSheet.create({
1686+
safe: {
1687+
flex: 1,
1688+
backgroundColor: '#252b33',
1689+
},
1690+
container: {
1691+
flex: 1,
1692+
backgroundColor: '#FFFFFF',
1693+
},
1694+
});
1695+
1696+
class App extends React.Component {
1697+
root = {
1698+
Root: View,
1699+
props: {
1700+
style: {
1701+
flex: 1,
1702+
},
1703+
},
1704+
};
1705+
1706+
render() {
1707+
return (
1708+
<SafeAreaView style={styles.safe}>
1709+
<StatusBar barStyle=\\"light-content\\" />
1710+
<View style={styles.container}>
1711+
<InstantSearch
1712+
searchClient={searchClient}
1713+
indexName=\\"indexName\\"
1714+
root={this.root}
1715+
>
1716+
<SearchBox />
1717+
<InfiniteHits />
1718+
</InstantSearch>
1719+
</View>
1720+
</SafeAreaView>
1721+
);
1722+
}
1723+
}
1724+
1725+
export default App;"
1726+
`;
1727+
1728+
exports[`Templates React InstantSearch Native File content: README.md 1`] = `
1729+
"# react-instantsearch-native-app
1730+
1731+
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._
1732+
1733+
## Get started
1734+
1735+
To run this project locally, install the dependencies and run the local server:
1736+
1737+
\`\`\`sh
1738+
npm install
1739+
npm start
1740+
\`\`\`
1741+
1742+
Alternatively, you may use [Yarn](https://http://yarnpkg.com/):
1743+
1744+
\`\`\`sh
1745+
yarn
1746+
yarn start
1747+
\`\`\`"
1748+
`;
1749+
1750+
exports[`Templates React InstantSearch Native File content: app.json 1`] = `
1751+
"{
1752+
\\"expo\\": {
1753+
\\"sdkVersion\\": \\"27.0.0\\"
1754+
}
1755+
}"
1756+
`;
1757+
1758+
exports[`Templates React InstantSearch Native File content: package.json 1`] = `
1759+
"{
1760+
\\"name\\": \\"react-instantsearch-native-app\\",
1761+
\\"version\\": \\"1.0.0\\",
1762+
\\"private\\": true,
1763+
\\"main\\": \\"./node_modules/react-native-scripts/build/bin/crna-entry.js\\",
1764+
\\"scripts\\": {
1765+
\\"start\\": \\"react-native-scripts start\\",
1766+
\\"android\\": \\"react-native-scripts android\\",
1767+
\\"ios\\": \\"react-native-scripts ios\\",
1768+
\\"lint\\": \\"eslint .\\",
1769+
\\"lint:fix\\": \\"npm run lint -- --fix\\"
1770+
},
1771+
\\"dependencies\\": {
1772+
\\"algoliasearch\\": \\"^3.27.1\\",
1773+
\\"expo\\": \\"^27.0.1\\",
1774+
\\"prop-types\\": \\"^15.6.1\\",
1775+
\\"react\\": \\"16.3.1\\",
1776+
\\"react-instantsearch-native\\": \\"^1.0.0\\",
1777+
\\"react-native\\": \\"^0.55.2\\"
1778+
},
1779+
\\"devDependencies\\": {
1780+
\\"eslint\\": \\"^4.19.1\\",
1781+
\\"eslint-config-algolia\\": \\"^13.1.0\\",
1782+
\\"eslint-config-prettier\\": \\"^2.9.0\\",
1783+
\\"eslint-plugin-import\\": \\"^2.12.0\\",
1784+
\\"eslint-plugin-prettier\\": \\"^2.6.0\\",
1785+
\\"eslint-plugin-react\\": \\"^7.9.1\\",
1786+
\\"prettier\\": \\"^1.13.4\\",
1787+
\\"react-native-scripts\\": \\"1.14.0\\"
1788+
}
1789+
}"
1790+
`;
1791+
1792+
exports[`Templates React InstantSearch Native File content: src/Highlight.js 1`] = `
1793+
"import React from 'react';
1794+
import { Text } from 'react-native';
1795+
import PropTypes from 'prop-types';
1796+
import { connectHighlight } from 'react-instantsearch-native';
1797+
1798+
const Highlight = ({ attribute, hit, highlight }) => {
1799+
const highlights = highlight({
1800+
highlightProperty: '_highlightResult',
1801+
attribute,
1802+
hit,
1803+
});
1804+
1805+
return (
1806+
<Text>
1807+
{highlights.map(({ value, isHighlighted }, index) => {
1808+
const style = {
1809+
backgroundColor: isHighlighted ? 'yellow' : 'transparent',
1810+
};
1811+
1812+
return (
1813+
<Text key={index} style={style}>
1814+
{value}
1815+
</Text>
1816+
);
1817+
})}
1818+
</Text>
1819+
);
1820+
};
1821+
1822+
Highlight.propTypes = {
1823+
attribute: PropTypes.string.isRequired,
1824+
hit: PropTypes.object.isRequired,
1825+
highlight: PropTypes.func.isRequired,
1826+
};
1827+
1828+
export default connectHighlight(Highlight);"
1829+
`;
1830+
1831+
exports[`Templates React InstantSearch Native File content: src/InfiniteHits.js 1`] = `
1832+
"import React from 'react';
1833+
import { StyleSheet, View, FlatList } from 'react-native';
1834+
import PropTypes from 'prop-types';
1835+
import { connectInfiniteHits } from 'react-instantsearch-native';
1836+
import Highlight from './Highlight';
1837+
1838+
const styles = StyleSheet.create({
1839+
separator: {
1840+
borderBottomWidth: 1,
1841+
},
1842+
item: {
1843+
padding: 10,
1844+
flexDirection: 'row',
1845+
alignItems: 'center',
1846+
},
1847+
});
1848+
1849+
const InfiniteHits = ({ hits, hasMore, refine }) => (
1850+
<FlatList
1851+
data={hits}
1852+
keyExtractor={item => item.objectID}
1853+
ItemSeparatorComponent={() => <View style={styles.separator} />}
1854+
onEndReached={() => hasMore && refine()}
1855+
renderItem={({ item }) => (
1856+
<View style={styles.item}>
1857+
<Highlight attribute=\\"mainAttribute\\" hit={item} />
1858+
</View>
1859+
)}
1860+
/>
1861+
);
1862+
1863+
InfiniteHits.propTypes = {
1864+
hits: PropTypes.arrayOf(PropTypes.object).isRequired,
1865+
hasMore: PropTypes.bool.isRequired,
1866+
refine: PropTypes.func.isRequired,
1867+
};
1868+
1869+
export default connectInfiniteHits(InfiniteHits);"
1870+
`;
1871+
1872+
exports[`Templates React InstantSearch Native File content: src/SearchBox.js 1`] = `
1873+
"import React from 'react';
1874+
import { StyleSheet, View, TextInput } from 'react-native';
1875+
import PropTypes from 'prop-types';
1876+
import { connectSearchBox } from 'react-instantsearch-native';
1877+
1878+
const styles = StyleSheet.create({
1879+
container: {
1880+
padding: 10,
1881+
backgroundColor: '#252b33',
1882+
},
1883+
input: {
1884+
height: 40,
1885+
padding: 10,
1886+
backgroundColor: '#FFFFFF',
1887+
},
1888+
});
1889+
1890+
const SearchBox = ({ currentRefinement, refine }) => (
1891+
<View style={styles.container}>
1892+
<TextInput
1893+
style={styles.input}
1894+
onChangeText={value => refine(value)}
1895+
value={currentRefinement}
1896+
placeholder=\\"Search placeholder\\"
1897+
/>
1898+
</View>
1899+
);
1900+
1901+
SearchBox.propTypes = {
1902+
currentRefinement: PropTypes.string.isRequired,
1903+
refine: PropTypes.func.isRequired,
1904+
};
1905+
1906+
export default connectSearchBox(SearchBox);"
1907+
`;
1908+
1909+
exports[`Templates React InstantSearch Native Folder structure: contains the right files 1`] = `
1910+
Array [
1911+
".babelrc",
1912+
".editorconfig",
1913+
".eslintrc.js",
1914+
".gitignore",
1915+
".prettierrc",
1916+
".watchmanconfig",
1917+
"App.js",
1918+
"README.md",
1919+
"app.json",
1920+
"package.json",
1921+
"src/Highlight.js",
1922+
"src/InfiniteHits.js",
1923+
"src/SearchBox.js",
1924+
]
1925+
`;
1926+
16131927
exports[`Templates Vue InstantSearch File content: .babelrc 1`] = `
16141928
"{
16151929
\\"presets\\": [
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": ["babel-preset-expo"],
3+
"env": {
4+
"development": {
5+
"plugins": ["transform-react-jsx-source"]
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: 'algolia/react',
3+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# expo
4+
.expo/
5+
6+
# dependencies
7+
/node_modules
8+
9+
# misc
10+
.env.local
11+
.env.development.local
12+
.env.test.local
13+
.env.production.local
14+
15+
npm-debug.log*
16+
yarn-debug.log*
17+
yarn-error.log*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"proseWrap": "never",
4+
"trailingComma": "es5"
5+
}

0 commit comments

Comments
 (0)