mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-26 09:13:33 +03:00
validation added
This commit is contained in:
parent
a3b4d9a2fd
commit
41cb6b53fd
11
package-lock.json
generated
11
package-lock.json
generated
@ -7653,9 +7653,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lodash": {
|
"lodash": {
|
||||||
"version": "4.17.10",
|
"version": "4.17.11",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||||
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
|
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
||||||
},
|
},
|
||||||
"lodash-es": {
|
"lodash-es": {
|
||||||
"version": "4.17.11",
|
"version": "4.17.11",
|
||||||
@ -8573,6 +8573,11 @@
|
|||||||
"tween-functions": "^1.0.1"
|
"tween-functions": "^1.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"lodash": {
|
||||||
|
"version": "4.17.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
|
||||||
|
"integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
|
||||||
|
},
|
||||||
"react-native-keyboard-aware-scroll-view": {
|
"react-native-keyboard-aware-scroll-view": {
|
||||||
"version": "0.5.0",
|
"version": "0.5.0",
|
||||||
"resolved": "http://registry.npmjs.org/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.5.0.tgz",
|
"resolved": "http://registry.npmjs.org/react-native-keyboard-aware-scroll-view/-/react-native-keyboard-aware-scroll-view-0.5.0.tgz",
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
"@esteemapp/react-native-tags": "^1.3.1",
|
"@esteemapp/react-native-tags": "^1.3.1",
|
||||||
"crypto-js": "^3.1.9-1",
|
"crypto-js": "^3.1.9-1",
|
||||||
"dsteem": "^0.10.1",
|
"dsteem": "^0.10.1",
|
||||||
|
"lodash": "^4.17.11",
|
||||||
"moment": "^2.22.2",
|
"moment": "^2.22.2",
|
||||||
"native-base": "^2.8.1",
|
"native-base": "^2.8.1",
|
||||||
"react": "^16.5.0",
|
"react": "^16.5.0",
|
||||||
|
@ -26,6 +26,9 @@ export default class TagAreaView extends Component {
|
|||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
_handleOnChange = (text, i) => {
|
_handleOnChange = (text, i) => {
|
||||||
|
const { onChange } = this.props;
|
||||||
|
const { chips } = this.state;
|
||||||
|
|
||||||
this.setState({ currentText: text.trim() });
|
this.setState({ currentText: text.trim() });
|
||||||
|
|
||||||
// if (text.indexOf(' ') > 0 && text) {
|
// if (text.indexOf(' ') > 0 && text) {
|
||||||
@ -35,6 +38,10 @@ export default class TagAreaView extends Component {
|
|||||||
if (!text && i !== 0) {
|
if (!text && i !== 0) {
|
||||||
this._handleTagRemove(i);
|
this._handleTagRemove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (onChange) {
|
||||||
|
// this.props.onChange(chips);
|
||||||
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleOnBlur = () => {
|
_handleOnBlur = () => {
|
||||||
@ -48,6 +55,8 @@ export default class TagAreaView extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
chips: [...chips, currentText.trim()],
|
chips: [...chips, currentText.trim()],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.props.onChange(chips);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,6 +66,7 @@ export default class TagAreaView extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
chips: chips.filter((_, _i) => _i !== i),
|
chips: chips.filter((_, _i) => _i !== i),
|
||||||
});
|
});
|
||||||
|
this.props.onChange(chips);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -22,22 +22,32 @@ export default class TitleAreaView extends Component {
|
|||||||
// Component Life Cycles
|
// Component Life Cycles
|
||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
|
_handleOnChange = (text) => {
|
||||||
|
const { onChange, handleIsValid, componentID } = this.props;
|
||||||
|
if (onChange) {
|
||||||
|
onChange(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handleIsValid) {
|
||||||
|
handleIsValid(componentID, !!(text && text.length));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { onChange, value, isPreviewActive } = this.props;
|
const { value, isPreviewActive } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={globalStyles.containerHorizontal16}>
|
<View style={globalStyles.containerHorizontal16}>
|
||||||
<TextInput
|
<TextInput
|
||||||
style={styles.textInput}
|
style={styles.textInput}
|
||||||
placeholderTextColor="c1c5c7"
|
placeholderTextColor="#c1c5c7"
|
||||||
editable={!isPreviewActive}
|
editable={!isPreviewActive}
|
||||||
maxLength={250}
|
maxLength={250}
|
||||||
placeholder="Title"
|
placeholder="Title"
|
||||||
multiline
|
multiline
|
||||||
autoFocus
|
autoFocus
|
||||||
numberOfLines={4}
|
numberOfLines={4}
|
||||||
onChangeText={text => onChange && onChange(text)}
|
onChangeText={text => this._handleOnChange(text)}
|
||||||
value={value}
|
value={value}
|
||||||
{...this.props}
|
{...this.props}
|
||||||
/>
|
/>
|
||||||
|
@ -36,7 +36,6 @@ export default EStyleSheet.create({
|
|||||||
},
|
},
|
||||||
textButtonEnable: {
|
textButtonEnable: {
|
||||||
color: '$primaryBlue',
|
color: '$primaryBlue',
|
||||||
fontWeight: 'bold',
|
|
||||||
},
|
},
|
||||||
textButtonWrapper: {
|
textButtonWrapper: {
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
@ -27,13 +27,21 @@ export default class MarkdownEditorView extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeText = (input) => {
|
changeText = (input) => {
|
||||||
const { handleOnTextChange } = this.props;
|
const {
|
||||||
|
onChange, handleOnTextChange, handleIsValid, componentID,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
this.setState({ text: input });
|
this.setState({ text: input });
|
||||||
|
|
||||||
if (handleOnTextChange) {
|
if (onChange) {
|
||||||
handleOnTextChange(input);
|
onChange(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handleIsValid) {
|
||||||
|
handleIsValid(componentID, !!(input && input.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleOnTextChange && handleOnTextChange(input);
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleOnSelectionChange = (event) => {
|
_handleOnSelectionChange = (event) => {
|
||||||
@ -115,9 +123,9 @@ export default class MarkdownEditorView extends Component {
|
|||||||
{!isPreviewActive ? (
|
{!isPreviewActive ? (
|
||||||
<TextInput
|
<TextInput
|
||||||
multiline
|
multiline
|
||||||
onChangeText={this.changeText}
|
onChangeText={text => this.changeText(text)}
|
||||||
onSelectionChange={this._handleOnSelectionChange}
|
onSelectionChange={this._handleOnSelectionChange}
|
||||||
placeHolder="What would you like to write about today?"
|
placeholder="What would you like to write about today?"
|
||||||
placeholderTextColor="#c1c5c7"
|
placeholderTextColor="#c1c5c7"
|
||||||
ref={textInput => (this.textInput = textInput)}
|
ref={textInput => (this.textInput = textInput)}
|
||||||
selection={selection}
|
selection={selection}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
|
|
||||||
class PostFormView extends Component {
|
class PostFormView extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {};
|
||||||
|
}
|
||||||
|
|
||||||
_handleOnSubmitEditing = (returnKeyType = null, inputElement = null) => {
|
_handleOnSubmitEditing = (returnKeyType = null, inputElement = null) => {
|
||||||
const { handleOnSubmit, isFormValid } = this.props;
|
const { handleOnSubmit, isFormValid } = this.props;
|
||||||
|
|
||||||
@ -12,6 +17,12 @@ class PostFormView extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_handleOnChange = (componentID, value, isValid = null) => {
|
||||||
|
const { handleFormUpdate } = this.props;
|
||||||
|
|
||||||
|
handleFormUpdate(componentID, value, !!isValid || !!value);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, isFormValid, isPreviewActive } = this.props;
|
const { children, isFormValid, isPreviewActive } = this.props;
|
||||||
|
|
||||||
@ -21,6 +32,7 @@ class PostFormView extends Component {
|
|||||||
if (child) {
|
if (child) {
|
||||||
return React.cloneElement(child, {
|
return React.cloneElement(child, {
|
||||||
onSubmitEditing: item => this._handleOnSubmitEditing(child.props.returnKeyType, item),
|
onSubmitEditing: item => this._handleOnSubmitEditing(child.props.returnKeyType, item),
|
||||||
|
onChange: value => this._handleOnChange(child.props.componentID, value),
|
||||||
returnKeyType: isFormValid ? 'done' : 'next',
|
returnKeyType: isFormValid ? 'done' : 'next',
|
||||||
isPreviewActive,
|
isPreviewActive,
|
||||||
});
|
});
|
||||||
|
@ -24,6 +24,8 @@ export class EditorScreen extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
isPreviewActive: false,
|
isPreviewActive: false,
|
||||||
wordsCount: null,
|
wordsCount: null,
|
||||||
|
formFields: {},
|
||||||
|
isFormValid: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +38,8 @@ export class EditorScreen extends Component {
|
|||||||
this.setState({ isPreviewActive: !isPreviewActive });
|
this.setState({ isPreviewActive: !isPreviewActive });
|
||||||
};
|
};
|
||||||
|
|
||||||
_handleOnTextChange = (text) => {
|
_setWordsCount = (content) => {
|
||||||
const _wordsCount = getWordsCount(text);
|
const _wordsCount = getWordsCount(content);
|
||||||
const { wordsCount } = this.state;
|
const { wordsCount } = this.state;
|
||||||
|
|
||||||
if (_wordsCount !== wordsCount) {
|
if (_wordsCount !== wordsCount) {
|
||||||
@ -47,8 +49,36 @@ export class EditorScreen extends Component {
|
|||||||
|
|
||||||
_handleOnSubmit = () => {};
|
_handleOnSubmit = () => {};
|
||||||
|
|
||||||
|
_handleIsFormValid = () => {
|
||||||
|
const { formFields } = this.state;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isFormValid:
|
||||||
|
formFields['title-area']
|
||||||
|
&& formFields['text-area']
|
||||||
|
&& formFields['tag-area']
|
||||||
|
&& formFields['title-area'].isValid
|
||||||
|
&& formFields['text-area'].isValid
|
||||||
|
&& formFields['tag-area'].isValid,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_handleFormUpdate = (componentID, content, isValid) => {
|
||||||
|
const { formFields } = this.state;
|
||||||
|
const newFormFields = formFields;
|
||||||
|
|
||||||
|
newFormFields[componentID] = {
|
||||||
|
content,
|
||||||
|
isValid,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setState({ formFields: newFormFields });
|
||||||
|
|
||||||
|
this._handleIsFormValid();
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isPreviewActive, wordsCount } = this.state;
|
const { isPreviewActive, wordsCount, isFormValid } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={globalStyles.defaultContainer}>
|
<View style={globalStyles.defaultContainer}>
|
||||||
@ -56,16 +86,17 @@ export class EditorScreen extends Component {
|
|||||||
isPreviewActive={isPreviewActive}
|
isPreviewActive={isPreviewActive}
|
||||||
quickTitle={wordsCount > 0 && `${wordsCount} words`}
|
quickTitle={wordsCount > 0 && `${wordsCount} words`}
|
||||||
handleOnPressPreviewButton={this._handleOnPressPreviewButton}
|
handleOnPressPreviewButton={this._handleOnPressPreviewButton}
|
||||||
isFormValid
|
isFormValid={isFormValid}
|
||||||
/>
|
/>
|
||||||
<PostForm
|
<PostForm
|
||||||
|
handleFormUpdate={this._handleFormUpdate}
|
||||||
handleOnSubmit={this._handleOnSubmit}
|
handleOnSubmit={this._handleOnSubmit}
|
||||||
isPreviewActive={isPreviewActive}
|
isPreviewActive={isPreviewActive}
|
||||||
isFormValid
|
isFormValid={isFormValid}
|
||||||
>
|
>
|
||||||
<TitleArea />
|
<TitleArea componentID="title-area" />
|
||||||
<TagArea />
|
<TagArea componentID="tag-area" />
|
||||||
<TextArea handleOnTextChange={this._handleOnTextChange} />
|
<TextArea handleOnTextChange={this._setWordsCount} componentID="text-area" />
|
||||||
</PostForm>
|
</PostForm>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
@ -1 +1 @@
|
|||||||
export const getWordsCount = text => (text ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0);
|
export const getWordsCount = text => (text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user