-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: created hooks and separated components
- Loading branch information
1 parent
3c38729
commit 7fdf956
Showing
9 changed files
with
234 additions
and
213 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
app/views/NewServerView/components/CertificatePicker/index.tsx
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,30 @@ | ||
import React from 'react'; | ||
import { Text, TouchableOpacity, View } from 'react-native'; | ||
import I18n from 'i18n-js'; | ||
|
||
import { themes } from '../../../../lib/constants'; | ||
import { TCertificatePicker } from '../../types'; | ||
import { isAndroid, isTablet } from '../../../../lib/methods/helpers'; | ||
import styles from './styles'; | ||
|
||
const CertificatePicker = ({ previousServer, certificate, theme, chooseCertificate, handleRemove }: TCertificatePicker) => ( | ||
<View | ||
style={[ | ||
styles.certificatePicker, | ||
{ | ||
marginTop: isAndroid ? 20 : 0, | ||
marginBottom: previousServer && !isTablet ? 10 : 30 | ||
} | ||
]}> | ||
<Text style={[styles.chooseCertificateTitle, { color: themes[theme].fontSecondaryInfo, fontSize: 13 }]}> | ||
{certificate ? I18n.t('Your_certificate') : I18n.t('Do_you_have_a_certificate')} | ||
</Text> | ||
<TouchableOpacity onPress={certificate ? handleRemove : chooseCertificate} testID='new-server-choose-certificate'> | ||
<Text style={[styles.chooseCertificate, { color: themes[theme].fontInfo, fontSize: 13 }]}> | ||
{certificate ?? I18n.t('Apply_Your_Certificate')} | ||
</Text> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
|
||
export default CertificatePicker; |
19 changes: 19 additions & 0 deletions
19
app/views/NewServerView/components/CertificatePicker/styles.ts
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,19 @@ | ||
import { StyleSheet } from "react-native"; | ||
|
||
import sharedStyles from '../../../Styles'; | ||
|
||
|
||
const styles = StyleSheet.create({ | ||
certificatePicker: { | ||
alignItems: 'center', | ||
justifyContent: 'flex-end' | ||
}, | ||
chooseCertificateTitle: { | ||
...sharedStyles.textRegular | ||
}, | ||
chooseCertificate: { | ||
...sharedStyles.textSemibold | ||
} | ||
}); | ||
|
||
export default styles; |
12 changes: 6 additions & 6 deletions
12
app/views/NewServerView/ServerInput/Item.tsx → ...erverView/components/ServerInput/Item.tsx
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from 'react'; | ||
import I18n from 'i18n-js'; | ||
|
||
import { showConfirmationAlert } from '../../../lib/methods/helpers/info'; | ||
import SSLPinning from '../../../lib/methods/helpers/sslPinning'; | ||
|
||
const useCertificate = () => { | ||
const [certificate, setCertificate] = useState<string | null>(null); | ||
|
||
const chooseCertificate = async () => { | ||
try { | ||
const certificate = await SSLPinning?.pickCertificate(); | ||
setCertificate(certificate); | ||
} catch { | ||
// Do nothing | ||
} | ||
}; | ||
|
||
const removeCertificate = () => { | ||
showConfirmationAlert({ | ||
message: I18n.t('You_will_unset_a_certificate_for_this_server'), | ||
confirmationText: I18n.t('Remove'), | ||
onPress: () => setCertificate(null) // We not need delete file from DocumentPicker because it is a temp file | ||
}); | ||
}; | ||
|
||
return { | ||
certificate, | ||
chooseCertificate, | ||
removeCertificate | ||
}; | ||
}; | ||
|
||
export default useCertificate; |
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,47 @@ | ||
import { useState } from 'react'; | ||
import { Q } from '@nozbe/watermelondb'; | ||
import { sanitizeLikeString } from '@nozbe/watermelondb/QueryDescription'; | ||
|
||
import { TServerHistoryModel } from '../../../definitions'; | ||
import database from '../../../lib/database'; | ||
|
||
const useServersHistory = () => { | ||
const [serversHistory, setServersHistory] = useState<TServerHistoryModel[]>([]); | ||
|
||
const queryServerHistory = async (text?: string) => { | ||
const db = database.servers; | ||
try { | ||
const serversHistoryCollection = db.get('servers_history'); | ||
let whereClause = [Q.where('username', Q.notEq(null)), Q.sortBy('updated_at', Q.desc), Q.take(3)]; | ||
if (text) { | ||
const likeString = sanitizeLikeString(text); | ||
whereClause = [...whereClause, Q.where('url', Q.like(`%${likeString}%`))]; | ||
} | ||
const serversHistory = await serversHistoryCollection.query(...whereClause).fetch(); | ||
|
||
setServersHistory(serversHistory); | ||
} catch { | ||
// Do nothing | ||
} | ||
}; | ||
|
||
const deleteServerHistory = async (item: TServerHistoryModel) => { | ||
const db = database.servers; | ||
try { | ||
await db.write(async () => { | ||
await item.destroyPermanently(); | ||
}); | ||
setServersHistory(prevState => prevState.filter(prevServerHistory => prevServerHistory?.id !== item?.id)); | ||
} catch { | ||
// Nothing | ||
} | ||
}; | ||
|
||
return { | ||
serversHistory, | ||
queryServerHistory, | ||
deleteServerHistory | ||
}; | ||
}; | ||
|
||
export default useServersHistory; |
Oops, something went wrong.