Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Minor fixes:
Browse files Browse the repository at this point in the history
- Lint errors.
- Clipboard, Picker and Slider now are part of react-native-community.
- Better DB handling.
- Fixed a bug that caused a new site to not display after add it.
- Typo on the share button.
- Catch URL open when the subject is not a URL.
  • Loading branch information
daper committed Aug 12, 2020
1 parent ce9240b commit f85b9ef
Show file tree
Hide file tree
Showing 16 changed files with 2,161 additions and 2,619 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
'react/prop-types': 0,
'comma-dangle': 0,
'template-curly-spacing' : 'off',
'indent' : "off"
'indent' : "off",
'react/jsx-closing-tag-location': 'off'
},
'globals': {
'__DEV__': false
Expand Down
4,417 changes: 1,967 additions & 2,450 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
"flow": "flow",
"run-android": "npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && npx react-native run-android",
"log-android": "npx react-native log-android",
"cache-clean": "cd android && ./gradlew clean cleanBuildCache && cd .. && rm -rf node_modules/ && npm cache clean --force && npm install && npm start -- --reset-cache"
"cache-clean": "cd android && ./gradlew clean cleanBuildCache && cd .. && rm -rf node_modules/ && npm cache clean --force && npm install && npm start -- --reset-cache",
"postinstall": "./tools/fix-packages.sh"
},
"dependencies": {
"@react-native-community/clipboard": "^1.2.3",
"@react-native-community/picker": "^1.6.6",
"@react-native-community/slider": "^3.0.3",
"axios": "~0.19.2",
"native-base": "^2.13.13",
"prop-types": "^15.7.2",
Expand Down Expand Up @@ -41,7 +45,7 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.20.5",
"eslint-plugin-standard": "^4.0.1",
"flow-bin": "^0.120.1",
"flow-bin": "^0.122.0",
"jest": "^25.5.4",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "^16.13.1"
Expand Down
13 changes: 7 additions & 6 deletions src/API/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const Colors = {
grey: '#414142'
}

const DB_NAME = 'nextcloud.db'

export class API {
models = [Passwords, Folders]

Expand Down Expand Up @@ -69,29 +67,32 @@ export class API {
})
})

if (__DEV__) {
if (__DEV__) { /*
console.log(`Got DB(${dbName}):`, this.db)
const rootDir = Platform.select({
ios: fs.MainBundlePath,
android: fs.DocumentDirectoryPath,
})
let dbPath = `${rootDir}/${dbName}`
const dbPath = `${rootDir}/${dbName}`
try {
await fs.stat(dbPath)
.then((statResult) => {
console.log('DB File Stat', statResult)
})
} catch(e) {
} catch (e) {
console.log(`Looks like the fs call failed to ${dbPath}`)
console.log(e)
}
}
*/ }

this.models.forEach((model) => model.setDb(this.db))

await Promise.all(this.models.map((model) => model.createTable()))
} else {
if (__DEV__) console.log('DB is opened: no-op')
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/API/passwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ export class Passwords {
const { status, data } = await this.http.post('/api/1.0/password/create', item)

if (status === 201) {
// Default fields //
if (! ("hidden" in item)) item.hidden = 0
if (! ("trashed" in item)) item.trashed = 0
if (! ("favorite" in item)) item.favorite = 0
if (! ("editable" in item)) item.editable = 1

item.id = data.id
let cols = Object.keys(item).filter((col) => [...PASSWORD_FIELDS, 'password'].indexOf(col) !== -1)
const values = cols.map((key) => item[key])
Expand Down
37 changes: 19 additions & 18 deletions src/AddSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ export class AddSite extends Component {
this.state = {
item: {
folder: this.props.currentFolder,
customFields: "[]"
customFields: '[]'
},
showPassword: false,
passwordIsError: false,
labelIsError: false,
}

this.goBack = this.goBack.bind(this)
this.handleGoBack = this.handleGoBack.bind(this)
this.updateHandler = this.updateHandler.bind(this)
this.submit = this.submit.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
}

componentDidMount () {
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
this.goBack()
this.handleGoBack()
return true
})
}
Expand All @@ -63,7 +63,7 @@ export class AddSite extends Component {
this.backHandler.remove()
}

async goBack () {
async handleGoBack () {
this.props.history.push('/dashboard')
}

Expand Down Expand Up @@ -92,31 +92,32 @@ export class AddSite extends Component {
return result
}

async submit () {
async handleSubmit () {
if (this.validate()) {
this.props.setLoading(true, 'Creating site...')
const data = await Passwords.create(this.state.item)
this.props.setLoading(false)

if (!(data instanceof Error)) {
this.props.history.push('/dashboard')
this.props.history.push('/dashboard?refresh=true')
}
}
}

render () {
return (
<Container>
{!this.props.loading && <Header style={{ backgroundColor: Colors.bgColor }}>
<Left>
<Button transparent onPress={this.goBack}>
<Icon type='MaterialIcons' name='arrow-back' />
</Button>
</Left>
<Body>
<Title>Create Site</Title>
</Body>
</Header>}
{!this.props.loading &&
<Header style={{ backgroundColor: Colors.bgColor }}>
<Left>
<Button transparent onPress={this.handleGoBack}>
<Icon type='MaterialIcons' name='arrow-back' />
</Button>
</Left>
<Body>
<Title>Create Site</Title>
</Body>
</Header>}
<Content padder>
{this.props.loading
? <View style={styles.spinnerView}>
Expand Down Expand Up @@ -194,7 +195,7 @@ export class AddSite extends Component {
</Content>
{!this.props.loading && <Footer>
<FooterTab>
<Button full success onPress={this.submit}>
<Button full success onPress={this.handleSubmit}>
<Text style={{ color: 'white', fontSize: 16 }}>Create</Text>
</Button>
</FooterTab>
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class App extends Component {
this.checkLock = this.checkLock.bind(this)

API.init(this.props.settings)
//API.openDB("App.js")
// API.openDB("App.js")

if (this.props.enableSecurity === true) {
this.props.setLocked(true)
Expand Down
41 changes: 21 additions & 20 deletions src/Dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react'
import {
Platform,
StyleSheet,
BackHandler,
} from 'react-native'
Expand Down Expand Up @@ -38,12 +39,12 @@ class Dashboard extends Component {
constructor (props) {
super(props)

this.search = this.search.bind(this)
this.refresh = this.refresh.bind(this)
this.changeFolder = this.changeFolder.bind(this)
this.handleSearch = this.handleSearch.bind(this)
this.handleRefresh = this.handleRefresh.bind(this)
this.handleChangeFolder = this.handleChangeFolder.bind(this)
this.getData = this.getData.bind(this)
this.getFolder = this.getFolder.bind(this)
this.clearSearchFilter = this.clearSearchFilter.bind(this)
this.handleClearSearchFilter = this.handleClearSearchFilter.bind(this)

this.searchTimeout = null
this.state = {
Expand All @@ -61,7 +62,7 @@ class Dashboard extends Component {
async componentDidMount () {
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
if (this.props.currentFolder !== ROOT_FOLDER) {
this.changeFolder(this.state.folder.parent)
this.handleChangeFolder(this.state.folder.parent)
} else if (this.props.history.location === this.props.history.entries[0]) {
BackHandler.exitApp()
} else {
Expand All @@ -76,19 +77,19 @@ class Dashboard extends Component {
android: fs.DocumentDirectoryPath,
})

let dbName = this.props.settings.dbName
const dbName = this.props.settings.dbName
try {
await fs.stat(`${rootDir}/${dbName}`)
.then((statResult) => {
if (__DEV__) console.log('DB File Stat', statResult)
})
} catch(err) {
} catch (err) {
if (__DEV__) console.log('DB File not exists')
await this.props.setSettings({ dbName: new Date().getTime().toString() })
}

await API.openDB(this.props.settings.dbName, "Dashboard.js")
await this.changeFolder(this.props.currentFolder)
await API.openDB(dbName, 'Dashboard.js')
await this.handleChangeFolder(this.props.currentFolder)
}

componentWillUnmount () {
Expand Down Expand Up @@ -193,7 +194,7 @@ class Dashboard extends Component {
this.props.setLoading(false)
}

async refresh () {
async handleRefresh () {
await this.fetchData()
await this.getData()
}
Expand All @@ -207,7 +208,7 @@ class Dashboard extends Component {
this.props.history.push('/login')
}

async search (filter) {
async handleSearch (filter) {
await this.props.setPasswordFilter(filter)

if (this.searchTimeout) {
Expand All @@ -218,13 +219,13 @@ class Dashboard extends Component {
this.searchTimeout = setTimeout(this.getData, 300)
}

async clearSearchFilter () {
await this.search('')
async handleClearSearchFilter () {
await this.handleSearch('')
}

async changeFolder (id) {
async handleChangeFolder (id) {
await this.props.setCurrentFolder(id)
if (__DEV__) console.log('changeFolder', id)
if (__DEV__) console.log('handleChangeFolder', id)

if (this.props.lastLogin === 0) {
await this.fetchData()
Expand All @@ -241,22 +242,22 @@ class Dashboard extends Component {
{this.state.filtering
? <Spinner color='black' size='small' style={{ padding: 10 }} />
: <Icon type='MaterialIcons' name='search' />}
<Input placeholder='Search' defaultValue={this.props.filter} onChangeText={this.search} />
<Input placeholder='Search' defaultValue={this.props.filter} onChangeText={this.handleSearch} />
{this.props.filter.length !== 0
? <Button transparent onPress={this.clearSearchFilter} style={{ paddingTop: 3 }}>
? <Button transparent onPress={this.handleClearSearchFilter} style={{ paddingTop: 3 }}>
<Icon type='MaterialIcons' name='close' style={{ color: Colors.grey, marginRight: 8 }} />
</Button>
</Button>
: null}
</Item>
<View style={{ alignSelf: 'center', marginLeft: 10 }}>
<Button transparent onPress={this.refresh}>
<Button transparent onPress={this.handleRefresh}>
<Icon type='MaterialIcons' name='sync' style={{ color: 'white', fontSize: 32 }} />
</Button>
</View>
</Header>
<View padder style={{ flex: 1 }}>
<SiteList
onChangeFolder={this.changeFolder}
onChangeFolder={this.handleChangeFolder}
passwordList={this.state.passwordList}
folder={this.state.folder}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/Favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Favorites extends Component {
constructor (props) {
super(props)

this.changeFolder = this.changeFolder.bind(this)
this.handleChangeFolder = this.handleChangeFolder.bind(this)

this.state = {
passwordList: [],
Expand All @@ -44,7 +44,7 @@ export class Favorites extends Component {
return true
})

await this.changeFolder(this.props.currentFolder)
await this.handleChangeFolder(this.props.currentFolder)
}

componentWillUnmount () {
Expand Down Expand Up @@ -93,9 +93,9 @@ export class Favorites extends Component {
this.props.setLoading(false)
}

async changeFolder (id) {
async handleChangeFolder (id) {
await this.props.setCurrentFolder(id)
if (__DEV__) console.log('changeFolder', id)
if (__DEV__) console.log('handleChangeFolder', id)

this.getData()
}
Expand All @@ -110,7 +110,7 @@ export class Favorites extends Component {
</Header>
<View padder style={{ flex: 1 }}>
<SiteList
onChangeFolder={this.changeFolder}
onChangeFolder={this.handleChangeFolder}
passwordList={this.state.passwordList}
folder={this.state.folder}
/>
Expand Down
Loading

0 comments on commit f85b9ef

Please sign in to comment.