mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-18 19:01:38 +03:00
refined external sharing flow
This commit is contained in:
parent
f78f1599e7
commit
a245dec56a
@ -68,6 +68,7 @@ const MarkdownEditorView = ({
|
||||
getCommunity,
|
||||
currentAccount,
|
||||
autoFocusText,
|
||||
sharedSnippetText,
|
||||
}) => {
|
||||
const [text, setText] = useState(draftBody || '');
|
||||
const [selection, setSelection] = useState({ start: 0, end: 0 });
|
||||
@ -97,6 +98,12 @@ const MarkdownEditorView = ({
|
||||
}
|
||||
}, [draftBody]);
|
||||
|
||||
useEffect(() => {
|
||||
if (sharedSnippetText) {
|
||||
_handleOnSnippetReceived(sharedSnippetText);
|
||||
}
|
||||
}, [sharedSnippetText]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editable === null) {
|
||||
// workaround for android context menu issue
|
||||
@ -208,7 +215,7 @@ const MarkdownEditorView = ({
|
||||
</ScrollView>
|
||||
);
|
||||
|
||||
const _handleOnSnippetSelect = (snippetText) => {
|
||||
const _handleOnSnippetReceived = (snippetText) => {
|
||||
applySnippet({
|
||||
text,
|
||||
selection,
|
||||
@ -398,7 +405,10 @@ const MarkdownEditorView = ({
|
||||
animationType="slide"
|
||||
style={styles.modalStyle}
|
||||
>
|
||||
<SnippetsModal username={currentAccount.username} handleOnSelect={_handleOnSnippetSelect} />
|
||||
<SnippetsModal
|
||||
username={currentAccount.username}
|
||||
handleOnSelect={_handleOnSnippetReceived}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
<UploadsGalleryModal
|
||||
|
@ -22,7 +22,7 @@ const persistedReducer = persistReducer(persistConfig, reducer);
|
||||
|
||||
const middleware = [thunk];
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
middleware.push(logger);
|
||||
// middleware.push(logger);
|
||||
}
|
||||
|
||||
const store = createStore(persistedReducer, applyMiddleware(...middleware));
|
||||
|
@ -158,10 +158,10 @@ class ApplicationContainer extends Component {
|
||||
});
|
||||
|
||||
ReceiveSharingIntent.getReceivedFiles(
|
||||
(files) => {
|
||||
() => {
|
||||
navigate({
|
||||
routeName: ROUTES.SCREENS.EDITOR,
|
||||
params: { upload: files },
|
||||
params: { hasSharedIntent: true },
|
||||
});
|
||||
// files returns as JSON Array example
|
||||
//[{ filePath: null, text: null, weblink: null, mimeType: null, contentUri: null, fileName: null, extension: null }]
|
||||
|
@ -8,6 +8,7 @@ import AsyncStorage from '@react-native-community/async-storage';
|
||||
|
||||
// Services and Actions
|
||||
import { Buffer } from 'buffer';
|
||||
import ReceiveSharingIntent from 'react-native-receive-sharing-intent';
|
||||
import {
|
||||
uploadImage,
|
||||
addDraft,
|
||||
@ -69,6 +70,7 @@ class EditorContainer extends Component {
|
||||
community: [],
|
||||
rewardType: 'default',
|
||||
beneficiaries: [],
|
||||
sharedSnippetText: null,
|
||||
};
|
||||
}
|
||||
|
||||
@ -81,9 +83,11 @@ class EditorContainer extends Component {
|
||||
let isEdit;
|
||||
let post;
|
||||
let _draft;
|
||||
let hasSharedIntent = false;
|
||||
|
||||
if (navigation.state && navigation.state.params) {
|
||||
const navigationParams = navigation.state.params;
|
||||
hasSharedIntent = navigationParams.hasSharedIntent;
|
||||
|
||||
if (navigationParams.draft) {
|
||||
_draft = navigationParams.draft;
|
||||
@ -98,30 +102,6 @@ class EditorContainer extends Component {
|
||||
community: navigationParams.community,
|
||||
});
|
||||
}
|
||||
if (navigationParams.upload) {
|
||||
const { upload } = navigationParams;
|
||||
|
||||
upload.forEach((el) => {
|
||||
if (el.filePath && el.fileName) {
|
||||
// this.setState({ isUploading: true });
|
||||
const _media = {
|
||||
path: el.filePath,
|
||||
mime: el.mimeType,
|
||||
filename: el.fileName || `img_${Math.random()}.jpg`,
|
||||
};
|
||||
|
||||
this._uploadImage(_media, { shouldInsert: true });
|
||||
} else if (el.text) {
|
||||
this.setState({
|
||||
draftPost: {
|
||||
title: '',
|
||||
body: el.text,
|
||||
tags: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (navigationParams.post) {
|
||||
({ post } = navigationParams);
|
||||
@ -154,11 +134,36 @@ class EditorContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isEdit && !_draft) {
|
||||
if (!isEdit && !_draft && !hasSharedIntent) {
|
||||
this._fetchDraftsForComparison(isReply);
|
||||
} else {
|
||||
this._requestKeyboardFocus();
|
||||
}
|
||||
|
||||
ReceiveSharingIntent.getReceivedFiles(
|
||||
(files) => {
|
||||
files.forEach((el) => {
|
||||
if (el.filePath && el.fileName) {
|
||||
const _media = {
|
||||
path: el.filePath,
|
||||
mime: el.mimeType,
|
||||
filename: el.fileName || `img_${Math.random()}.jpg`,
|
||||
};
|
||||
|
||||
this._uploadImage(_media, { shouldInsert: true });
|
||||
} else if (el.text) {
|
||||
this.setState({
|
||||
sharedSnippetText: el.text,
|
||||
});
|
||||
}
|
||||
});
|
||||
// To clear Intents
|
||||
ReceiveSharingIntent.clearReceivedFiles();
|
||||
},
|
||||
(error) => {
|
||||
console.log('error :>> ', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@ -433,57 +438,6 @@ class EditorContainer extends Component {
|
||||
isUploading: false,
|
||||
});
|
||||
}
|
||||
|
||||
// uploadImage(media, currentAccount.name, sign).then((res) => {
|
||||
// if (res.data && res.data.url) {
|
||||
// res.data.hash = res.data.url.split('/').pop();
|
||||
// this.setState({
|
||||
// uploadedImage: res.data,
|
||||
// isUploading: false,
|
||||
// });
|
||||
// }
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.log(error, error.message);
|
||||
// if (error.toString().includes('code 413')) {
|
||||
// Alert.alert(
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.fail',
|
||||
// }),
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.payloadTooLarge',
|
||||
// }),
|
||||
// );
|
||||
// } else if (error.toString().includes('code 429')) {
|
||||
// Alert.alert(
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.fail',
|
||||
// }),
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.quotaExceeded',
|
||||
// }),
|
||||
// );
|
||||
// } else if (error.toString().includes('code 400')) {
|
||||
// Alert.alert(
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.fail',
|
||||
// }),
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.invalidImage',
|
||||
// }),
|
||||
// );
|
||||
// } else {
|
||||
// Alert.alert(
|
||||
// intl.formatMessage({
|
||||
// id: 'alert.fail',
|
||||
// }),
|
||||
// error.message || error.toString(),
|
||||
// );
|
||||
// }
|
||||
// this.setState({
|
||||
// isUploading: false,
|
||||
// });
|
||||
// });
|
||||
};
|
||||
|
||||
_handleMediaOnSelectFailure = (error) => {
|
||||
@ -1100,6 +1054,7 @@ class EditorContainer extends Component {
|
||||
uploadedImage,
|
||||
community,
|
||||
isDraft,
|
||||
sharedSnippetText,
|
||||
} = this.state;
|
||||
|
||||
const tags = navigation.state.params && navigation.state.params.tags;
|
||||
@ -1133,6 +1088,7 @@ class EditorContainer extends Component {
|
||||
community={community}
|
||||
currentAccount={currentAccount}
|
||||
isDraft={isDraft}
|
||||
sharedSnippetText={sharedSnippetText}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -320,6 +320,7 @@ class EditorScreen extends Component {
|
||||
handleBeneficiaries,
|
||||
currentAccount,
|
||||
autoFocusText,
|
||||
sharedSnippetText,
|
||||
} = this.props;
|
||||
const rightButtonText = intl.formatMessage({
|
||||
id: isEdit ? 'basic_header.update' : isReply ? 'basic_header.reply' : 'basic_header.publish',
|
||||
@ -396,6 +397,7 @@ class EditorScreen extends Component {
|
||||
onTitleChanged={this._handleChangeTitle}
|
||||
getCommunity={this._getCommunity}
|
||||
autoFocusText={autoFocusText}
|
||||
sharedSnippetText={sharedSnippetText}
|
||||
/>
|
||||
</PostForm>
|
||||
</View>
|
||||
|
Loading…
Reference in New Issue
Block a user