mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 12:51:42 +03:00
added show schedule and remove function as part 1
This commit is contained in:
parent
c4e250d10e
commit
15452c8c7c
@ -57,7 +57,7 @@ class CommentsView extends PureComponent {
|
||||
handleOnUserPress={handleOnUserPress}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isShowMoreButton={commentNumber === 1 && item.children > 0}
|
||||
voteCount={item.vote_count}
|
||||
voteCount={item.net_votes}
|
||||
isShowSubComments={isShowSubComments}
|
||||
key={item.permlink}
|
||||
marginLeft={marginLeft}
|
||||
|
@ -9,6 +9,7 @@ export default {
|
||||
'ko-KR': require('./ko-KR.json'),
|
||||
'lt-LT': require('./lt-LT.json'),
|
||||
'pt-PT': require('./pt-PT.json'),
|
||||
'fa-IR': require('./fa-IR.json'),
|
||||
};
|
||||
|
||||
export const locales = [
|
||||
@ -22,4 +23,5 @@ export const locales = [
|
||||
{ id: 'ko-KR', name: 'Korean' },
|
||||
{ id: 'lt-LT', name: 'Lithuanian' },
|
||||
{ id: 'pt-PT', name: 'Porteguese' },
|
||||
{ id: 'fa-IR', name: 'Persian' },
|
||||
];
|
||||
|
@ -8,6 +8,7 @@ export default [
|
||||
'Porteguese',
|
||||
'Russian',
|
||||
'Turkish',
|
||||
'Persian',
|
||||
];
|
||||
|
||||
export const VALUE = [
|
||||
@ -20,4 +21,5 @@ export const VALUE = [
|
||||
'pt-PT',
|
||||
'ru-RU',
|
||||
'tr-TR',
|
||||
'fa-IR',
|
||||
];
|
||||
|
@ -223,7 +223,7 @@ export const schedule = (
|
||||
upvote,
|
||||
scheduleDate,
|
||||
) => api
|
||||
.post('/api/schedules', {
|
||||
.post('/schedules', {
|
||||
username: user,
|
||||
category: tags[0],
|
||||
title,
|
||||
@ -238,18 +238,18 @@ export const schedule = (
|
||||
})
|
||||
.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
|
||||
// Images
|
||||
|
||||
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) => {
|
||||
const fData = new FormData();
|
||||
|
@ -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;
|
||||
|
||||
try {
|
||||
|
@ -1,7 +1,5 @@
|
||||
import React, { Component } from 'react';
|
||||
import {
|
||||
Platform, BackHandler, Alert, NetInfo,
|
||||
} from 'react-native';
|
||||
import { Platform, BackHandler, Alert, NetInfo } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { addLocaleData } from 'react-intl';
|
||||
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 lt from 'react-intl/locale-data/lt';
|
||||
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
|
||||
import AUTH_TYPE from '../../../constants/authType';
|
||||
@ -71,7 +71,7 @@ import {
|
||||
import ApplicationScreen from '../screen/applicationScreen';
|
||||
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 {
|
||||
constructor() {
|
||||
@ -87,7 +87,7 @@ class ApplicationContainer extends Component {
|
||||
const { isIos } = this.state;
|
||||
let isConnected;
|
||||
|
||||
await NetInfo.isConnected.fetch().then((_isConnected) => {
|
||||
await NetInfo.isConnected.fetch().then(_isConnected => {
|
||||
isConnected = _isConnected;
|
||||
});
|
||||
|
||||
@ -104,9 +104,7 @@ class ApplicationContainer extends Component {
|
||||
};
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const {
|
||||
isDarkTheme: _isDarkTheme, selectedLanguage, isLogingOut, isConnected,
|
||||
} = this.props;
|
||||
const { isDarkTheme: _isDarkTheme, selectedLanguage, isLogingOut, isConnected } = this.props;
|
||||
|
||||
if (_isDarkTheme !== nextProps.isDarkTheme || selectedLanguage !== nextProps.selectedLanguage) {
|
||||
this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true }));
|
||||
@ -136,7 +134,7 @@ class ApplicationContainer extends Component {
|
||||
await this._getUserData();
|
||||
};
|
||||
|
||||
_handleConntectionChange = (status) => {
|
||||
_handleConntectionChange = status => {
|
||||
const { dispatch, isConnected } = this.props;
|
||||
|
||||
if (isConnected !== status) {
|
||||
@ -170,19 +168,19 @@ class ApplicationContainer extends Component {
|
||||
let realmData = [];
|
||||
let currentUsername;
|
||||
|
||||
await getAuthStatus().then((res) => {
|
||||
await getAuthStatus().then(res => {
|
||||
({ currentUsername } = res);
|
||||
if (res) {
|
||||
getUserData().then(async (userData) => {
|
||||
getUserData().then(async userData => {
|
||||
if (userData.length > 0) {
|
||||
realmData = userData;
|
||||
userData.forEach((accountData, index) => {
|
||||
if (
|
||||
!accountData.accessToken
|
||||
&& !accountData.masterKey
|
||||
&& !accountData.postingKey
|
||||
&& !accountData.activeKey
|
||||
&& !accountData.memoKey
|
||||
!accountData.accessToken &&
|
||||
!accountData.masterKey &&
|
||||
!accountData.postingKey &&
|
||||
!accountData.activeKey &&
|
||||
!accountData.memoKey
|
||||
) {
|
||||
realmData.splice(index, 1);
|
||||
if (realmData.length === 0) {
|
||||
@ -213,7 +211,7 @@ class ApplicationContainer extends Component {
|
||||
await switchAccount(realmObject[0].username);
|
||||
}
|
||||
await getUser(realmObject[0].username)
|
||||
.then(async (accountData) => {
|
||||
.then(async accountData => {
|
||||
dispatch(login(true));
|
||||
|
||||
const isExistUser = await getExistUser();
|
||||
@ -227,7 +225,7 @@ class ApplicationContainer extends Component {
|
||||
}
|
||||
this._connectNotificationServer(accountData.name);
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
Alert.alert(err);
|
||||
});
|
||||
}
|
||||
@ -239,15 +237,18 @@ class ApplicationContainer extends Component {
|
||||
_getSettings = () => {
|
||||
const { dispatch } = this.props;
|
||||
|
||||
getSettings().then((response) => {
|
||||
getSettings().then(response => {
|
||||
if (response) {
|
||||
if (response.isDarkTheme !== '') dispatch(isDarkTheme(response.isDarkTheme));
|
||||
if (response.language !== '') dispatch(setLanguage(response.language));
|
||||
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.notification !== '') {
|
||||
dispatch(changeNotificationSettings({ type: 'notification', action: response.notification }));
|
||||
dispatch(
|
||||
changeNotificationSettings({ type: 'notification', action: response.notification }),
|
||||
);
|
||||
dispatch(changeAllNotificationSettings(response));
|
||||
|
||||
Push.setEnabled(response.notification);
|
||||
@ -261,7 +262,7 @@ class ApplicationContainer extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
_connectNotificationServer = (username) => {
|
||||
_connectNotificationServer = username => {
|
||||
const { dispatch, unreadActivityCount } = this.props;
|
||||
const ws = new WebSocket(`${Config.ACTIVITY_WEBSOCKET_URL}?user=${username}`);
|
||||
|
||||
@ -299,10 +300,10 @@ class ApplicationContainer extends Component {
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
_switchAccount = async (targetAccountUsername) => {
|
||||
_switchAccount = async targetAccountUsername => {
|
||||
const { dispatch } = this.props;
|
||||
|
||||
await switchAccount(targetAccountUsername).then((accountData) => {
|
||||
await switchAccount(targetAccountUsername).then(accountData => {
|
||||
const realmData = getUserDataWithUsername(targetAccountUsername);
|
||||
const _currentAccount = accountData;
|
||||
_currentAccount.username = accountData.name;
|
||||
|
@ -4,7 +4,9 @@ import { Alert } from 'react-native';
|
||||
import { injectIntl } from 'react-intl';
|
||||
|
||||
// Services and Actions
|
||||
import { getDrafts, removeDraft, getSchedules } from '../../../providers/esteem/esteem';
|
||||
import {
|
||||
getDrafts, removeDraft, getSchedules, removeSchedule,
|
||||
} from '../../../providers/esteem/esteem';
|
||||
|
||||
// Middleware
|
||||
|
||||
@ -35,6 +37,7 @@ class DraftsContainer extends Component {
|
||||
// Component Life Cycle Functions
|
||||
componentDidMount() {
|
||||
this._getDrafts();
|
||||
this._getSchedules();
|
||||
}
|
||||
|
||||
// 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) => {
|
||||
const { navigation } = this.props;
|
||||
const { drafts } = this.state;
|
||||
@ -115,6 +133,7 @@ class DraftsContainer extends Component {
|
||||
drafts={drafts}
|
||||
schedules={schedules}
|
||||
removeDraft={this._removeDraft}
|
||||
removeSchedule={this._removeSchedule}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -33,8 +33,10 @@ class DraftsScreen extends Component {
|
||||
|
||||
// Component Functions
|
||||
|
||||
_renderItem = (item) => {
|
||||
const { currentAccount, removeDraft, editDraft } = this.props;
|
||||
_renderItem = (item, type) => {
|
||||
const {
|
||||
currentAccount, removeDraft, editDraft, removeSchedule,
|
||||
} = this.props;
|
||||
const tags = item.tags ? item.tags.split(/[ ,]+/) : [];
|
||||
const tag = tags[0] || '';
|
||||
const image = catchDraftImage(item.body);
|
||||
@ -50,7 +52,7 @@ class DraftsScreen extends Component {
|
||||
username={currentAccount.name}
|
||||
reputation={currentAccount.reputation}
|
||||
handleOnPressItem={editDraft}
|
||||
handleOnRemoveItem={removeDraft}
|
||||
handleOnRemoveItem={type === 'schedules' ? removeSchedule : removeDraft}
|
||||
id={item._id}
|
||||
/>
|
||||
);
|
||||
@ -80,7 +82,7 @@ class DraftsScreen extends Component {
|
||||
data={data}
|
||||
keyExtractor={item => item._id}
|
||||
removeClippedSubviews={false}
|
||||
renderItem={({ item }) => this._renderItem(item)}
|
||||
renderItem={({ item }) => this._renderItem(item, type)}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
@ -76,7 +76,10 @@ class ProfileContainer extends Component {
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const {
|
||||
navigation, currentAccount, activeBottomTab, isLoggedIn,
|
||||
navigation,
|
||||
currentAccount,
|
||||
activeBottomTab,
|
||||
isLoggedIn,
|
||||
} = this.props;
|
||||
const currentUsername = currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name;
|
||||
|
||||
@ -115,34 +118,37 @@ class ProfileContainer extends Component {
|
||||
};
|
||||
|
||||
_handleFollowUnfollowUser = async (isFollowAction) => {
|
||||
const { username, isFollowing } = this.state;
|
||||
const { currentAccount, pinCode } = this.props;
|
||||
const { isFollowing } = this.state;
|
||||
|
||||
this.setState({
|
||||
isProfileLoading: true,
|
||||
});
|
||||
|
||||
if (isFollowAction && !isFollowing) {
|
||||
this._followUser(currentAccount, pinCode, currentAccount.name, username);
|
||||
this._followUser();
|
||||
} else {
|
||||
this._unfollowUser(currentAccount, pinCode, currentAccount.name, username);
|
||||
this._unfollowUser();
|
||||
}
|
||||
};
|
||||
|
||||
_handleMuteUnmuteUser = async (isMuteAction) => {
|
||||
const { username } = this.state;
|
||||
const { currentAccount, pinCode } = this.props;
|
||||
|
||||
_handleMuteUnmuteUser = (isMuteAction) => {
|
||||
this.setState({
|
||||
isProfileLoading: true,
|
||||
});
|
||||
|
||||
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, {
|
||||
follower,
|
||||
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, {
|
||||
follower,
|
||||
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, {
|
||||
follower,
|
||||
following,
|
||||
@ -184,32 +200,32 @@ class ProfileContainer extends Component {
|
||||
_profileActionDone = (error = null) => {
|
||||
const { username } = this.state;
|
||||
|
||||
this.setState({
|
||||
isProfileLoading: false,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
this.setState({
|
||||
error,
|
||||
});
|
||||
alert(error);
|
||||
}, () => alert(error));
|
||||
} 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) {
|
||||
const { isLoggedIn, currentAccount } = this.props;
|
||||
let isFollowing;
|
||||
let isMuted;
|
||||
let _isFollowing;
|
||||
let _isMuted;
|
||||
let isFavorite;
|
||||
let follows;
|
||||
|
||||
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) => {
|
||||
isFavorite = isFav;
|
||||
@ -222,13 +238,22 @@ class ProfileContainer extends Component {
|
||||
follows = null;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
follows,
|
||||
isFollowing,
|
||||
isMuted,
|
||||
isFavorite,
|
||||
isReady: true,
|
||||
});
|
||||
/**
|
||||
* This follow code totally a work arround
|
||||
* Ceated for server response delay.
|
||||
*/
|
||||
if (isProfileAction && (isFollowing === _isFollowing && isMuted === _isMuted)) {
|
||||
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 (
|
||||
<ProfileScreen
|
||||
about={user && user.about && user.about.profile}
|
||||
activePage={activePage}
|
||||
avatar={avatar}
|
||||
comments={comments}
|
||||
currency={currency}
|
||||
@ -359,7 +385,6 @@ class ProfileContainer extends Component {
|
||||
selectedQuickProfile={selectedQuickProfile}
|
||||
selectedUser={user}
|
||||
username={username}
|
||||
activePage={activePage}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ const imgTagRegex = /(<img[^>]*>)/g;
|
||||
const iframeRegex = /(?:<iframe[^>]*)(?:(?:\/>)|(?:>.*?<\/iframe>))/g;
|
||||
const hTagRegex = /(<h([1-6])>([^<]*)<\/h([1-6])>)/g;
|
||||
|
||||
export const markDown2Html = (input) => {
|
||||
export const markDown2Html = input => {
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
@ -95,177 +95,194 @@ export const markDown2Html = (input) => {
|
||||
return output;
|
||||
};
|
||||
|
||||
const replaceAuthorNames = input => input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => {
|
||||
const userLower = user.toLowerCase();
|
||||
const preceedings = (preceeding1 || '') + (preceeding2 || '');
|
||||
return `${preceedings}<a class="markdown-author-link" href="${userLower}" data-author="${userLower}"> @${user}</a>`;
|
||||
});
|
||||
const replaceAuthorNames = input =>
|
||||
input.replace(authorNameRegex, (match, preceeding1, preceeding2, user) => {
|
||||
const userLower = user.toLowerCase();
|
||||
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) => {
|
||||
if (/#[\d]+$/.test(tag)) return tag;
|
||||
const preceding = /^\s|>/.test(tag) ? tag[0] : '';
|
||||
tag = tag.replace('>', '');
|
||||
const tag2 = tag.trim().substring(1);
|
||||
const tagLower = tag2.toLowerCase();
|
||||
return `${preceding}<a class="markdown-tag-link" href="${tagLower}" data-tag="${tagLower}">${tag.trim()}</a>`;
|
||||
});
|
||||
const replaceTags = input =>
|
||||
input.replace(tagsRegex, tag => {
|
||||
if (/#[\d]+$/.test(tag)) return tag;
|
||||
const preceding = /^\s|>/.test(tag) ? tag[0] : '';
|
||||
tag = tag.replace('>', '');
|
||||
const tag2 = tag.trim().substring(1);
|
||||
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) => {
|
||||
if (dTubeRegex.test(link)) {
|
||||
const dTubeMatch = link.match(dTubeRegex)[0];
|
||||
const execLink = dTubeRegex.exec(dTubeMatch);
|
||||
const handleATag = input =>
|
||||
input.replace(aTagRegex, link => {
|
||||
if (dTubeRegex.test(link)) {
|
||||
const dTubeMatch = link.match(dTubeRegex)[0];
|
||||
const execLink = dTubeRegex.exec(dTubeMatch);
|
||||
|
||||
if (execLink[2] && execLink[3]) {
|
||||
const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`;
|
||||
if (execLink[2] && execLink[3]) {
|
||||
const embedLink = `https://emb.d.tube/#!/${execLink[2]}/${execLink[3]}`;
|
||||
|
||||
return iframeBody(embedLink);
|
||||
}
|
||||
if (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 iframeBody(embedLink);
|
||||
}
|
||||
if (dTubeMatch) {
|
||||
return iframeBody(dTubeMatch);
|
||||
}
|
||||
|
||||
return link;
|
||||
}
|
||||
if (link.trim().indexOf('ipfs.busy.org') > 0) {
|
||||
return imageBody(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 markdownMatch = link.match(markdownImageRegex);
|
||||
if (markdownMatch[0]) {
|
||||
const firstMarkdownMatch = markdownMatch[0];
|
||||
const _link = firstMarkdownMatch.match(urlRegex)[0];
|
||||
const handleHTag = input => input.replace(hTagRegex, tag => `<div>${tag}</div>`);
|
||||
|
||||
return _link;
|
||||
}
|
||||
return link;
|
||||
});
|
||||
const handleMarkdownLink = input =>
|
||||
input.replace(copiedPostRegex, link => {
|
||||
const postMatch = link.match(copiedPostRegex);
|
||||
|
||||
const centerStyling = input => input.replace(
|
||||
centerRegex,
|
||||
() => '<center style="text-align: center; align-items: center; justify-content: center;">',
|
||||
);
|
||||
if (postMatch) {
|
||||
let tag = postMatch[1];
|
||||
|
||||
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];
|
||||
if (tag === '/busy.org') {
|
||||
tag = 'busy';
|
||||
}
|
||||
|
||||
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) => {
|
||||
const _imgTag = imgTag.trim();
|
||||
const match = _imgTag.match(imgRegex);
|
||||
return `<a class="markdown-post-link" href="${_permlink}" data_tag={${tag.trim()}} data_author="${postMatch[2].replace(
|
||||
'@',
|
||||
'',
|
||||
)}">/${_permlink}</a>`;
|
||||
}
|
||||
});
|
||||
|
||||
if (match && match[0]) {
|
||||
return match[0];
|
||||
}
|
||||
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);
|
||||
|
||||
return imgTag;
|
||||
});
|
||||
if (imageMatch) {
|
||||
if (imageMatch[0].indexOf('.gif') > 0) {
|
||||
return gifBody(imageMatch[0]);
|
||||
}
|
||||
|
||||
const createYoutubeIframe = input => input.replace(youTubeRegex, (link) => {
|
||||
const execVideo = youTubeRegex.exec(link);
|
||||
const match = link.match(youTubeRegex);
|
||||
if (imageMatch[0]) {
|
||||
return imageBody(imageMatch[0]);
|
||||
}
|
||||
} else if (link.trim().indexOf('ipfs.busy.org') > 0) {
|
||||
return imageBody(link);
|
||||
}
|
||||
|
||||
if (execVideo[1] && match) {
|
||||
const videoLink = execVideo[1];
|
||||
const embedLink = `https://www.youtube.com/embed/${videoLink}`;
|
||||
return link;
|
||||
}
|
||||
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 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 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 handleImageLink = input => input.replace(imgRegex, link => imageBody(link));
|
||||
|
||||
// const handleCodeTag = input => input.replace(codeTagRegex, (tag) => {
|
||||
// const stringsRegex = /(?<=>)(.*)(?=<)/g;
|
||||
|
Loading…
Reference in New Issue
Block a user