added show schedule and remove function as part 1

This commit is contained in:
u-e 2019-04-09 21:38:23 +03:00
parent ca875a3dc1
commit d56469919d
10 changed files with 283 additions and 215 deletions

View File

@ -57,7 +57,7 @@ class CommentsView extends PureComponent {
handleOnUserPress={handleOnUserPress} handleOnUserPress={handleOnUserPress}
isLoggedIn={isLoggedIn} isLoggedIn={isLoggedIn}
isShowMoreButton={commentNumber === 1 && item.children > 0} isShowMoreButton={commentNumber === 1 && item.children > 0}
voteCount={item.vote_count} voteCount={item.net_votes}
isShowSubComments={isShowSubComments} isShowSubComments={isShowSubComments}
key={item.permlink} key={item.permlink}
marginLeft={marginLeft} marginLeft={marginLeft}

View File

@ -9,6 +9,7 @@ export default {
'ko-KR': require('./ko-KR.json'), 'ko-KR': require('./ko-KR.json'),
'lt-LT': require('./lt-LT.json'), 'lt-LT': require('./lt-LT.json'),
'pt-PT': require('./pt-PT.json'), 'pt-PT': require('./pt-PT.json'),
'fa-IR': require('./fa-IR.json'),
}; };
export const locales = [ export const locales = [
@ -22,4 +23,5 @@ export const locales = [
{ id: 'ko-KR', name: 'Korean' }, { id: 'ko-KR', name: 'Korean' },
{ id: 'lt-LT', name: 'Lithuanian' }, { id: 'lt-LT', name: 'Lithuanian' },
{ id: 'pt-PT', name: 'Porteguese' }, { id: 'pt-PT', name: 'Porteguese' },
{ id: 'fa-IR', name: 'Persian' },
]; ];

View File

@ -8,6 +8,7 @@ export default [
'Porteguese', 'Porteguese',
'Russian', 'Russian',
'Turkish', 'Turkish',
'Persian',
]; ];
export const VALUE = [ export const VALUE = [
@ -20,4 +21,5 @@ export const VALUE = [
'pt-PT', 'pt-PT',
'ru-RU', 'ru-RU',
'tr-TR', 'tr-TR',
'fa-IR',
]; ];

View File

@ -223,7 +223,7 @@ export const schedule = (
upvote, upvote,
scheduleDate, scheduleDate,
) => api ) => api
.post('/api/schedules', { .post('/schedules', {
username: user, username: user,
category: tags[0], category: tags[0],
title, title,
@ -238,18 +238,18 @@ export const schedule = (
}) })
.then(resp => resp.data); .then(resp => resp.data);
export const getSchedules = user => api.get(`/api/schedules/${user}`).then(resp => resp.data); export const getSchedules = user => api.get(`/schedules/${user}`).then(resp => resp.data);
export const removeSchedule = (id, user) => api.delete(`/api/schedules/${user}/${id}`); export const removeSchedule = (user, id) => api.delete(`/schedules/${user}/${id}`);
export const moveSchedule = (id, user) => api.put(`/api/schedules/${user}/${id}`); export const moveSchedule = (id, user) => api.put(`/schedules/${user}/${id}`);
// Old image service // Old image service
// Images // Images
export const getImages = user => api.get(`api/images/${user}`).then(resp => resp.data); export const getImages = user => api.get(`api/images/${user}`).then(resp => resp.data);
export const addMyImage = (user, url) => api.post('/api/image', { username: user, image_url: url }); export const addMyImage = (user, url) => api.post('/image', { username: user, image_url: url });
export const uploadImage = (file) => { export const uploadImage = (file) => {
const fData = new FormData(); const fData = new FormData();

View File

@ -192,7 +192,7 @@ export const getFollowSearch = (user, targetUser) => new Promise((resolve, rejec
}); });
}); });
export const getIsMuted = async (username, targetUsername) => { export const getIsMuted = async (targetUsername, username) => {
let resp; let resp;
try { try {

View File

@ -1,7 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { import { Platform, BackHandler, Alert, NetInfo } from 'react-native';
Platform, BackHandler, Alert, NetInfo,
} from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { addLocaleData } from 'react-intl'; import { addLocaleData } from 'react-intl';
import Config from 'react-native-config'; import Config from 'react-native-config';
@ -20,6 +18,8 @@ import tr from 'react-intl/locale-data/tr';
import ko from 'react-intl/locale-data/ko'; import ko from 'react-intl/locale-data/ko';
import lt from 'react-intl/locale-data/lt'; import lt from 'react-intl/locale-data/lt';
import pt from 'react-intl/locale-data/pt'; import pt from 'react-intl/locale-data/pt';
import fa from 'react-intl/locale-data/fa';
import he from 'react-intl/locale-data/he';
// Constants // Constants
import AUTH_TYPE from '../../../constants/authType'; import AUTH_TYPE from '../../../constants/authType';
@ -71,7 +71,7 @@ import {
import ApplicationScreen from '../screen/applicationScreen'; import ApplicationScreen from '../screen/applicationScreen';
import { Launch } from '../..'; import { Launch } from '../..';
addLocaleData([...en, ...ru, ...de, ...id, ...it, ...hu, ...tr, ...ko, ...pt, ...lt]); addLocaleData([...en, ...ru, ...de, ...id, ...it, ...hu, ...tr, ...ko, ...pt, ...lt, ...fa]);
class ApplicationContainer extends Component { class ApplicationContainer extends Component {
constructor() { constructor() {
@ -87,7 +87,7 @@ class ApplicationContainer extends Component {
const { isIos } = this.state; const { isIos } = this.state;
let isConnected; let isConnected;
await NetInfo.isConnected.fetch().then((_isConnected) => { await NetInfo.isConnected.fetch().then(_isConnected => {
isConnected = _isConnected; isConnected = _isConnected;
}); });
@ -104,9 +104,7 @@ class ApplicationContainer extends Component {
}; };
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { const { isDarkTheme: _isDarkTheme, selectedLanguage, isLogingOut, isConnected } = this.props;
isDarkTheme: _isDarkTheme, selectedLanguage, isLogingOut, isConnected,
} = this.props;
if (_isDarkTheme !== nextProps.isDarkTheme || selectedLanguage !== nextProps.selectedLanguage) { if (_isDarkTheme !== nextProps.isDarkTheme || selectedLanguage !== nextProps.selectedLanguage) {
this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true })); this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true }));
@ -136,7 +134,7 @@ class ApplicationContainer extends Component {
await this._getUserData(); await this._getUserData();
}; };
_handleConntectionChange = (status) => { _handleConntectionChange = status => {
const { dispatch, isConnected } = this.props; const { dispatch, isConnected } = this.props;
if (isConnected !== status) { if (isConnected !== status) {
@ -170,19 +168,19 @@ class ApplicationContainer extends Component {
let realmData = []; let realmData = [];
let currentUsername; let currentUsername;
await getAuthStatus().then((res) => { await getAuthStatus().then(res => {
({ currentUsername } = res); ({ currentUsername } = res);
if (res) { if (res) {
getUserData().then(async (userData) => { getUserData().then(async userData => {
if (userData.length > 0) { if (userData.length > 0) {
realmData = userData; realmData = userData;
userData.forEach((accountData, index) => { userData.forEach((accountData, index) => {
if ( if (
!accountData.accessToken !accountData.accessToken &&
&& !accountData.masterKey !accountData.masterKey &&
&& !accountData.postingKey !accountData.postingKey &&
&& !accountData.activeKey !accountData.activeKey &&
&& !accountData.memoKey !accountData.memoKey
) { ) {
realmData.splice(index, 1); realmData.splice(index, 1);
if (realmData.length === 0) { if (realmData.length === 0) {
@ -213,7 +211,7 @@ class ApplicationContainer extends Component {
await switchAccount(realmObject[0].username); await switchAccount(realmObject[0].username);
} }
await getUser(realmObject[0].username) await getUser(realmObject[0].username)
.then(async (accountData) => { .then(async accountData => {
dispatch(login(true)); dispatch(login(true));
const isExistUser = await getExistUser(); const isExistUser = await getExistUser();
@ -227,7 +225,7 @@ class ApplicationContainer extends Component {
} }
this._connectNotificationServer(accountData.name); this._connectNotificationServer(accountData.name);
}) })
.catch((err) => { .catch(err => {
Alert.alert(err); Alert.alert(err);
}); });
} }
@ -239,15 +237,18 @@ class ApplicationContainer extends Component {
_getSettings = () => { _getSettings = () => {
const { dispatch } = this.props; const { dispatch } = this.props;
getSettings().then((response) => { getSettings().then(response => {
if (response) { if (response) {
if (response.isDarkTheme !== '') dispatch(isDarkTheme(response.isDarkTheme)); if (response.isDarkTheme !== '') dispatch(isDarkTheme(response.isDarkTheme));
if (response.language !== '') dispatch(setLanguage(response.language)); if (response.language !== '') dispatch(setLanguage(response.language));
if (response.server !== '') dispatch(setApi(response.server)); if (response.server !== '') dispatch(setApi(response.server));
if (response.upvotePercent !== '') dispatch(setUpvotePercent(Number(response.upvotePercent))); if (response.upvotePercent !== '')
dispatch(setUpvotePercent(Number(response.upvotePercent)));
if (response.isDefaultFooter !== '') dispatch(isDefaultFooter(response.isDefaultFooter)); if (response.isDefaultFooter !== '') dispatch(isDefaultFooter(response.isDefaultFooter));
if (response.notification !== '') { if (response.notification !== '') {
dispatch(changeNotificationSettings({ type: 'notification', action: response.notification })); dispatch(
changeNotificationSettings({ type: 'notification', action: response.notification }),
);
dispatch(changeAllNotificationSettings(response)); dispatch(changeAllNotificationSettings(response));
Push.setEnabled(response.notification); Push.setEnabled(response.notification);
@ -261,7 +262,7 @@ class ApplicationContainer extends Component {
}); });
}; };
_connectNotificationServer = (username) => { _connectNotificationServer = username => {
const { dispatch, unreadActivityCount } = this.props; const { dispatch, unreadActivityCount } = this.props;
const ws = new WebSocket(`${Config.ACTIVITY_WEBSOCKET_URL}?user=${username}`); const ws = new WebSocket(`${Config.ACTIVITY_WEBSOCKET_URL}?user=${username}`);
@ -299,10 +300,10 @@ class ApplicationContainer extends Component {
.catch(() => {}); .catch(() => {});
}; };
_switchAccount = async (targetAccountUsername) => { _switchAccount = async targetAccountUsername => {
const { dispatch } = this.props; const { dispatch } = this.props;
await switchAccount(targetAccountUsername).then((accountData) => { await switchAccount(targetAccountUsername).then(accountData => {
const realmData = getUserDataWithUsername(targetAccountUsername); const realmData = getUserDataWithUsername(targetAccountUsername);
const _currentAccount = accountData; const _currentAccount = accountData;
_currentAccount.username = accountData.name; _currentAccount.username = accountData.name;

View File

@ -4,7 +4,9 @@ import { Alert } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
// Services and Actions // Services and Actions
import { getDrafts, removeDraft, getSchedules } from '../../../providers/esteem/esteem'; import {
getDrafts, removeDraft, getSchedules, removeSchedule,
} from '../../../providers/esteem/esteem';
// Middleware // Middleware
@ -35,6 +37,7 @@ class DraftsContainer extends Component {
// Component Life Cycle Functions // Component Life Cycle Functions
componentDidMount() { componentDidMount() {
this._getDrafts(); this._getDrafts();
this._getSchedules();
} }
// Component Functions // Component Functions
@ -82,6 +85,21 @@ class DraftsContainer extends Component {
}); });
}; };
_removeSchedule = (id) => {
const { currentAccount, intl } = this.props;
removeSchedule({ username: currentAccount.name, draftId: id })
.then(() => {
const { schedules } = this.state;
const newSchedules = [...schedules].filter(schedule => schedule._id !== id);
this.setState({ schedules: this._sortData(newSchedules) });
})
.catch(() => {
Alert.alert(intl.formatMessage({ id: 'alert.fail' }));
});
};
_editDraft = (id) => { _editDraft = (id) => {
const { navigation } = this.props; const { navigation } = this.props;
const { drafts } = this.state; const { drafts } = this.state;
@ -115,6 +133,7 @@ class DraftsContainer extends Component {
drafts={drafts} drafts={drafts}
schedules={schedules} schedules={schedules}
removeDraft={this._removeDraft} removeDraft={this._removeDraft}
removeSchedule={this._removeSchedule}
/> />
); );
} }

View File

@ -33,8 +33,10 @@ class DraftsScreen extends Component {
// Component Functions // Component Functions
_renderItem = (item) => { _renderItem = (item, type) => {
const { currentAccount, removeDraft, editDraft } = this.props; const {
currentAccount, removeDraft, editDraft, removeSchedule,
} = this.props;
const tags = item.tags ? item.tags.split(/[ ,]+/) : []; const tags = item.tags ? item.tags.split(/[ ,]+/) : [];
const tag = tags[0] || ''; const tag = tags[0] || '';
const image = catchDraftImage(item.body); const image = catchDraftImage(item.body);
@ -50,7 +52,7 @@ class DraftsScreen extends Component {
username={currentAccount.name} username={currentAccount.name}
reputation={currentAccount.reputation} reputation={currentAccount.reputation}
handleOnPressItem={editDraft} handleOnPressItem={editDraft}
handleOnRemoveItem={removeDraft} handleOnRemoveItem={type === 'schedules' ? removeSchedule : removeDraft}
id={item._id} id={item._id}
/> />
); );
@ -80,7 +82,7 @@ class DraftsScreen extends Component {
data={data} data={data}
keyExtractor={item => item._id} keyExtractor={item => item._id}
removeClippedSubviews={false} removeClippedSubviews={false}
renderItem={({ item }) => this._renderItem(item)} renderItem={({ item }) => this._renderItem(item, type)}
/> />
) )
)} )}

View File

@ -76,7 +76,10 @@ class ProfileContainer extends Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { const {
navigation, currentAccount, activeBottomTab, isLoggedIn, navigation,
currentAccount,
activeBottomTab,
isLoggedIn,
} = this.props; } = this.props;
const currentUsername = currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name; const currentUsername = currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name;
@ -115,34 +118,37 @@ class ProfileContainer extends Component {
}; };
_handleFollowUnfollowUser = async (isFollowAction) => { _handleFollowUnfollowUser = async (isFollowAction) => {
const { username, isFollowing } = this.state; const { isFollowing } = this.state;
const { currentAccount, pinCode } = this.props;
this.setState({ this.setState({
isProfileLoading: true, isProfileLoading: true,
}); });
if (isFollowAction && !isFollowing) { if (isFollowAction && !isFollowing) {
this._followUser(currentAccount, pinCode, currentAccount.name, username); this._followUser();
} else { } else {
this._unfollowUser(currentAccount, pinCode, currentAccount.name, username); this._unfollowUser();
} }
}; };
_handleMuteUnmuteUser = async (isMuteAction) => { _handleMuteUnmuteUser = (isMuteAction) => {
const { username } = this.state;
const { currentAccount, pinCode } = this.props;
this.setState({ this.setState({
isProfileLoading: true, isProfileLoading: true,
}); });
if (isMuteAction) { if (isMuteAction) {
this._muteUser(currentAccount, pinCode, currentAccount.name, username); this._muteUser();
} else {
this._unfollowUser();
} }
}; };
_unfollowUser = (currentAccount, pinCode, follower, following) => { _unfollowUser = () => {
const { username } = this.state;
const { currentAccount, pinCode } = this.props;
const follower = currentAccount.name;
const following = username;
unfollowUser(currentAccount, pinCode, { unfollowUser(currentAccount, pinCode, {
follower, follower,
following, following,
@ -155,7 +161,12 @@ class ProfileContainer extends Component {
}); });
}; };
_followUser = (currentAccount, pinCode, follower, following) => { _followUser = () => {
const { username } = this.state;
const { currentAccount, pinCode } = this.props;
const follower = currentAccount.name;
const following = username;
followUser(currentAccount, pinCode, { followUser(currentAccount, pinCode, {
follower, follower,
following, following,
@ -168,7 +179,12 @@ class ProfileContainer extends Component {
}); });
}; };
_muteUser = async (currentAccount, pinCode, follower, following) => { _muteUser = () => {
const { username } = this.state;
const { currentAccount, pinCode } = this.props;
const follower = currentAccount.name;
const following = username;
ignoreUser(currentAccount, pinCode, { ignoreUser(currentAccount, pinCode, {
follower, follower,
following, following,
@ -184,32 +200,32 @@ class ProfileContainer extends Component {
_profileActionDone = (error = null) => { _profileActionDone = (error = null) => {
const { username } = this.state; const { username } = this.state;
this.setState({
isProfileLoading: false,
});
if (error) { if (error) {
this.setState({ this.setState({
error, error,
}); }, () => alert(error));
alert(error);
} else { } else {
this._fetchProfile(username); this._fetchProfile(username, true);
} }
}; };
_fetchProfile = async (username = null) => {
_fetchProfile = async (username = null, isProfileAction = false) => {
const {
username: _username, isFollowing, isMuted,
} = this.state;
if (username) { if (username) {
const { isLoggedIn, currentAccount } = this.props; const { isLoggedIn, currentAccount } = this.props;
let isFollowing; let _isFollowing;
let isMuted; let _isMuted;
let isFavorite; let isFavorite;
let follows; let follows;
if (isLoggedIn && currentAccount.name !== username) { if (isLoggedIn && currentAccount.name !== username) {
isFollowing = await getIsFollowing(username, currentAccount.name); _isFollowing = await getIsFollowing(username, currentAccount.name);
isMuted = isFollowing ? false : await getIsMuted(username, currentAccount.name); _isMuted = _isFollowing ? false : await getIsMuted(username, currentAccount.name);
getIsFavorite(username, currentAccount.name).then((isFav) => { getIsFavorite(username, currentAccount.name).then((isFav) => {
isFavorite = isFav; isFavorite = isFav;
@ -222,13 +238,22 @@ class ProfileContainer extends Component {
follows = null; follows = null;
} }
this.setState({ /**
follows, * This follow code totally a work arround
isFollowing, * Ceated for server response delay.
isMuted, */
isFavorite, if (isProfileAction && (isFollowing === _isFollowing && isMuted === _isMuted)) {
isReady: true, this._fetchProfile(_username, true);
}); } else {
this.setState({
follows,
isFollowing: _isFollowing,
isMuted: _isMuted,
isFavorite,
isReady: true,
isProfileLoading: false,
});
}
} }
}; };
@ -337,6 +362,7 @@ class ProfileContainer extends Component {
return ( return (
<ProfileScreen <ProfileScreen
about={user && user.about && user.about.profile} about={user && user.about && user.about.profile}
activePage={activePage}
avatar={avatar} avatar={avatar}
comments={comments} comments={comments}
currency={currency} currency={currency}
@ -359,7 +385,6 @@ class ProfileContainer extends Component {
selectedQuickProfile={selectedQuickProfile} selectedQuickProfile={selectedQuickProfile}
selectedUser={user} selectedUser={user}
username={username} username={username}
activePage={activePage}
/> />
); );
} }

View File

@ -24,7 +24,7 @@ const imgTagRegex = /(<img[^>]*>)/g;
const iframeRegex = /(?:<iframe[^>]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/g; const iframeRegex = /(?:<iframe[^>]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/g;
const hTagRegex = /(<h([1-6])>([^<]*)<\/h([1-6])>)/g; const hTagRegex = /(<h([1-6])>([^<]*)<\/h([1-6])>)/g;
export const markDown2Html = (input) => { export const markDown2Html = input => {
if (!input) { if (!input) {
return ''; return '';
} }
@ -95,177 +95,194 @@ export const markDown2Html = (input) => {
return output; return output;
}; };
const replaceAuthorNames = input => input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => { const replaceAuthorNames = input =>
const userLower = user.toLowerCase(); input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => {
const preceedings = (preceeding1 || '') + (preceeding2 || ''); const userLower = user.toLowerCase();
return `${preceedings}<a class="markdown-author-link" href="${userLower}" data-author="${userLower}"> @${user}</a>`; const preceedings = (preceeding1 || '') + (preceeding2 || '');
}); return `${preceedings}<a class="markdown-author-link" href="${userLower}" data-author="${userLower}"> @${user}</a>`;
});
const replaceTags = input => input.replace(tagsRegex, (tag) => { const replaceTags = input =>
if (/#[\d]+$/.test(tag)) return tag; input.replace(tagsRegex, tag => {
const preceding = /^\s|>/.test(tag) ? tag[0] : ''; if (/#[\d]+$/.test(tag)) return tag;
tag = tag.replace('>', ''); const preceding = /^\s|>/.test(tag) ? tag[0] : '';
const tag2 = tag.trim().substring(1); tag = tag.replace('>', '');
const tagLower = tag2.toLowerCase(); const tag2 = tag.trim().substring(1);
return `${preceding}<a class="markdown-tag-link" href="${tagLower}" data-tag="${tagLower}">${tag.trim()}</a>`; const tagLower = tag2.toLowerCase();
}); return `${preceding}<a class="markdown-tag-link" href="${tagLower}" data-tag="${tagLower}">${tag.trim()}</a>`;
});
const handleATag = input => input.replace(aTagRegex, (link) => { const handleATag = input =>
if (dTubeRegex.test(link)) { input.replace(aTagRegex, link => {
const dTubeMatch = link.match(dTubeRegex)[0]; if (dTubeRegex.test(link)) {
const execLink = dTubeRegex.exec(dTubeMatch); const dTubeMatch = link.match(dTubeRegex)[0];
const execLink = dTubeRegex.exec(dTubeMatch);
if (execLink[2] && execLink[3]) { if (execLink[2] && execLink[3]) {
const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`; const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`;
return iframeBody(embedLink); return iframeBody(embedLink);
} }
if (dTubeMatch) { if (dTubeMatch) {
return iframeBody(dTubeMatch); return iframeBody(dTubeMatch);
}
return link;
}
if (imgRegex.test(link)) {
const imgMatch = link.match(imgRegex)[0];
if (imgMatch) return `<a src="${imgMatch}">Image</a>`;
}
return link;
});
const handleHTag = input => input.replace(hTagRegex, tag => `<div>${tag}</div>`);
const handleMarkdownLink = input => input.replace(copiedPostRegex, (link) => {
const postMatch = link.match(copiedPostRegex);
if (postMatch) {
let tag = postMatch[1];
if (tag === '/busy.org') {
tag = 'busy';
}
const _permlink = postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3];
return `<a class="markdown-post-link" href="${_permlink}" data_tag={${tag.trim()}} data_author="${postMatch[2].replace(
'@',
'',
)}">/${_permlink}</a>`;
}
});
const handleLinks = input => input.replace(linkRegex, (link) => {
if (link) {
if (
link
.toLowerCase()
.trim()
.indexOf('https://steemitimages.com/0x0/') === 0
|| imgRegex.test(link)
) {
const imageMatch = link.match(imgRegex);
if (imageMatch) {
if (imageMatch[0].indexOf('.gif') > 0) {
return gifBody(imageMatch[0]);
}
if (imageMatch[0]) {
return imageBody(imageMatch[0]);
}
} else if (link.trim().indexOf('ipfs.busy.org') > 0) {
return imageBody(link);
} }
return link; return link;
} }
if (link.trim().indexOf('ipfs.busy.org') > 0) {
return imageBody(link);
}
if (imgRegex.test(link)) { if (imgRegex.test(link)) {
return imageBody(link); const imgMatch = link.match(imgRegex)[0];
if (imgMatch) return `<a src="${imgMatch}">Image</a>`;
} }
}
return link; return link;
}); });
const changeMarkdownImage = input => input.replace(markdownImageRegex, (link) => { const handleHTag = input => input.replace(hTagRegex, tag => `<div>${tag}</div>`);
const markdownMatch = link.match(markdownImageRegex);
if (markdownMatch[0]) {
const firstMarkdownMatch = markdownMatch[0];
const _link = firstMarkdownMatch.match(urlRegex)[0];
return _link; const handleMarkdownLink = input =>
} input.replace(copiedPostRegex, link => {
return link; const postMatch = link.match(copiedPostRegex);
});
const centerStyling = input => input.replace( if (postMatch) {
centerRegex, let tag = postMatch[1];
() => '<center style="text-align: center; align-items: center; justify-content: center;">',
);
const steemitUrlHandle = input => input.replace(postRegex, (link) => { if (tag === '/busy.org') {
const postMatch = link.match(postRegex); tag = 'busy';
const tag = postMatch[2]; }
const author = postMatch[3].replace('@', '');
const permlink = postMatch[4];
return `<a class="markdown-post-link" href="${permlink}" data_tag={${tag}} data_author="${author}">/${permlink}</a>`; const _permlink =
}); postMatch[3].indexOf(')') > 0 ? postMatch[3].replace(')', '') : postMatch[3];
const handleImageTag = input => input.replace(imgTagRegex, (imgTag) => { return `<a class="markdown-post-link" href="${_permlink}" data_tag={${tag.trim()}} data_author="${postMatch[2].replace(
const _imgTag = imgTag.trim(); '@',
const match = _imgTag.match(imgRegex); '',
)}">/${_permlink}</a>`;
}
});
if (match && match[0]) { const handleLinks = input =>
return match[0]; input.replace(linkRegex, link => {
} if (link) {
if (
link
.toLowerCase()
.trim()
.indexOf('https://steemitimages.com/0x0/') === 0 ||
imgRegex.test(link)
) {
const imageMatch = link.match(imgRegex);
return imgTag; if (imageMatch) {
}); if (imageMatch[0].indexOf('.gif') > 0) {
return gifBody(imageMatch[0]);
}
const createYoutubeIframe = input => input.replace(youTubeRegex, (link) => { if (imageMatch[0]) {
const execVideo = youTubeRegex.exec(link); return imageBody(imageMatch[0]);
const match = link.match(youTubeRegex); }
} else if (link.trim().indexOf('ipfs.busy.org') > 0) {
return imageBody(link);
}
if (execVideo[1] && match) { return link;
const videoLink = execVideo[1]; }
const embedLink = `https://www.youtube.com/embed/${videoLink}`; if (link.trim().indexOf('ipfs.busy.org') > 0) {
return imageBody(link);
}
if (imgRegex.test(link)) {
return imageBody(link);
}
}
return link;
});
const changeMarkdownImage = input =>
input.replace(markdownImageRegex, link => {
const markdownMatch = link.match(markdownImageRegex);
if (markdownMatch[0]) {
const firstMarkdownMatch = markdownMatch[0];
const _link = firstMarkdownMatch.match(urlRegex)[0];
return _link;
}
return link;
});
const centerStyling = input =>
input.replace(
centerRegex,
() => '<center style="text-align: center; align-items: center; justify-content: center;">',
);
const steemitUrlHandle = input =>
input.replace(postRegex, link => {
const postMatch = link.match(postRegex);
const tag = postMatch[2];
const author = postMatch[3].replace('@', '');
const permlink = postMatch[4];
return `<a class="markdown-post-link" href="${permlink}" data_tag={${tag}} data_author="${author}">/${permlink}</a>`;
});
const handleImageTag = input =>
input.replace(imgTagRegex, imgTag => {
const _imgTag = imgTag.trim();
const match = _imgTag.match(imgRegex);
if (match && match[0]) {
return match[0];
}
return imgTag;
});
const createYoutubeIframe = input =>
input.replace(youTubeRegex, link => {
if (link.indexOf(')') || link.indexOf('(')) {
return link;
}
const execVideo = youTubeRegex.exec(link);
const match = link.match(youTubeRegex);
if (execVideo[1] && match) {
const videoLink = execVideo[1];
const embedLink = `https://www.youtube.com/embed/${videoLink}`;
return iframeBody(embedLink);
}
return link;
});
const handleIframe = input =>
input.replace(iframeRegex, link => {
const match = link.match(linkRegex);
if (match && match[0]) {
return iframeBody(match[0]);
}
return link;
});
const createVimeoIframe = input =>
input.replace(vimeoRegex, link => {
const execLink = vimeoRegex.exec(link);
const embedLink = `https://player.vimeo.com/video/${execLink[3]}`;
return iframeBody(embedLink); return iframeBody(embedLink);
} });
return link;
});
const handleIframe = input => input.replace(iframeRegex, (link) => {
const match = link.match(linkRegex);
if (match && match[0]) {
return iframeBody(match[0]);
}
return link;
});
const createVimeoIframe = input => input.replace(vimeoRegex, (link) => {
const execLink = vimeoRegex.exec(link);
const embedLink = `https://player.vimeo.com/video/${execLink[3]}`;
return iframeBody(embedLink);
});
const handleImageLink = input => input.replace(imgRegex, link => imageBody(link));
const iframeBody = link => `<iframe frameborder='0' allowfullscreen src='${link}'></iframe>`; const iframeBody = link => `<iframe frameborder='0' allowfullscreen src='${link}'></iframe>`;
const imageBody = link => `<center style="text-align: center; align-items: center; justify-content: center;"><img src="${`https://steemitimages.com/600x0/${link}`}" /></center>`; const imageBody = link =>
`<center style="text-align: center; align-items: center; justify-content: center;"><img src="${`https://steemitimages.com/600x0/${link}`}" /></center>`;
const gifBody = link => `<img src="${`https://steemitimages.com/0x0/${link}`}" />`; const gifBody = link => `<img src="${`https://steemitimages.com/0x0/${link}`}" />`;
const handleImageLink = input => input.replace(imgRegex, link => imageBody(link));
// const handleCodeTag = input => input.replace(codeTagRegex, (tag) => { // const handleCodeTag = input => input.replace(codeTagRegex, (tag) => {
// const stringsRegex = /(?<=>)(.*)(?=<)/g; // const stringsRegex = /(?<=>)(.*)(?=<)/g;