Skip to content

Commit

Permalink
feat: support new markdown in notifs and update feed/spam fns
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashshah committed Dec 1, 2023
1 parent b154690 commit 1ed6752
Show file tree
Hide file tree
Showing 16 changed files with 837 additions and 2,813 deletions.
136 changes: 133 additions & 3 deletions src/components/labels/StylishLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,97 @@ export default class CalendarEvents extends Component {
Linking.openURL(matchingString);
}

newLineStyles() {
return '\n';
}

renderTextStyles(matchingString) {
const pattern =
/<span color=["']?(#[0-9A-Fa-f]{3,6}|[a-zA-Z]+)["']?>(.*?)<\/span>/i;
const match = matchingString.match(pattern);

if (match) {
const colorName = match[1].toLowerCase();
let color;
switch (colorName) {
case 'primary':
color = GLOBALS.COLORS.PRIMARY;
break;
case 'secondary':
color = GLOBALS.COLORS.GRADIENT_SECONDARY;
break;
case 'white':
color = GLOBALS.COLORS.WHITE;
break;
// can add more custom color names if needed, couldn't find the tertiary color
default:
color = colorName;
}
let textContent = match[2];
return <Text style={{color: color}}>{textContent}</Text>;
}

return matchingString;
}

renderLinkWithColor(matchingString) {
const pattern =
/<PUSHText color=["']?(#[0-9A-Fa-f]{3,6}|[a-zA-Z]+)["']?\s+link=["'](https?:\/\/[^"']+)["']>(.*?)<\/PUSHText>/i;
const linkPattern = /\[([^\]]+)]\((https?:\/\/[^)]+)/;
const match = matchingString.match(pattern);
const markdownLinkPattern = matchingString.match(linkPattern);

const tryLink = url => {
Linking.canOpenURL(url).then(supported => {
if (supported) Linking.openURL(url);
else console.log("Don't know how to open URI: " + url);
});
};

if (match) {
const colorName = match[1].toLowerCase();
let color;
// Map custom color names to specific values
switch (colorName) {
case 'primary':
color = GLOBALS.COLORS.PRIMARY;
break;
case 'secondary':
color = GLOBALS.COLORS.GRADIENT_SECONDARY;
break;
case 'tertiary':
color = GLOBALS.COLORS.GRADIENT_THIRD;
break;
case 'white':
color = GLOBALS.COLORS.WHITE;
break;
// Add more custom color names if needed
default:
color = colorName;
}

const link = match[2];
let textContent = match[3];
return (
<Text style={{color: color}} onPress={() => tryLink(link)}>
{textContent}
</Text>
);
} else if (markdownLinkPattern) {
const linkText = markdownLinkPattern[1];
const linkUrl = markdownLinkPattern[2];
return (
<Text
onPress={() => tryLink(linkUrl)}
style={{color: GLOBALS.COLORS.PINK, flex: 0}}>
{linkText}
</Text>
);
}

return matchingString;
}

// RENDER
render() {
const {style, title, fontSize, textStyle} = this.props;
Expand All @@ -94,6 +185,11 @@ export default class CalendarEvents extends Component {
style: [styles.link, styles.underline],
onPress: this.handleEmailPress,
},
{
pattern: /\[([^\]]+)]\((https?:\/\/[^)]+)\)/g,
style: {},
renderText: this.renderLinkWithColor,
},
{
pattern: /\[(u):([^\]]+)\]/i, // url
style: [styles.primary, styles.bold, styles.italics, styles.underline],
Expand Down Expand Up @@ -129,6 +225,12 @@ export default class CalendarEvents extends Component {
onPress: this.handleUrlPress,
renderText: this.renderThreeStyles,
},
{
pattern:
/<span color=["']?(#[0-9A-Fa-f]{3,6}|[a-zA-Z]+)["']?>(.*?)<\/span>/gi,
style: {}, // we can add aditional styles here if needed
renderText: this.renderTextStyles,
},
{
pattern: /\[(d):([^\]]+)\]/i, // default or primary gradient color
style: [styles.primary, styles.bold],
Expand All @@ -149,20 +251,43 @@ export default class CalendarEvents extends Component {
style: [styles.error, styles.bold],
renderText: this.renderStyles,
},
{
pattern: /\[(bi):([^\]]+)\]/i, // bolditalics
style: [styles.bold, styles.italics],
renderText: this.renderStyles,
},
{
pattern: /\*\*\*(.*?)\*\*\*/g, // bolditalics ***text***
style: {
...styles.bold,
...styles.italics,
},
renderText: matchingString =>
matchingString.replace(/\*\*\*(.*?)\*\*\*/g, '$1'),
},
{
pattern: /\[(b):([^\]]+)\]/i, // bold
style: styles.bold,
renderText: this.renderStyles,
},
{
pattern: /\*\*(.*?)\*\*/g, // bold **text**
style: styles.bold,
renderText: matchingString =>
matchingString.replace(/\*\*(.*?)\*\*/g, '$1'),
},
{
pattern: /\[(i):([^\]]+)\]/i, // italics
style: styles.italics,
renderText: this.renderStyles,
},
{
pattern: /\[(bi):([^\]]+)\]/i, // bolditalics
style: [styles.bold, styles.italics],
renderText: this.renderStyles,
pattern: /\*(.*?)\*/g, // italic *some text*
style: {
...styles.italics,
},
renderText: matchingString =>
matchingString.replace(/\*(.*?)\*/g, '$1'),
},
{
pattern: /\[(w):([^\]]+)\]/i, // white
Expand Down Expand Up @@ -194,6 +319,11 @@ export default class CalendarEvents extends Component {
style: [styles.link, styles.underline],
onPress: this.handelUrlPress,
},
{
pattern: /\\n/g,
style: {},
renderText: this.newLineStyles,
},
];

if (Platform.OS === 'ios') {
Expand Down
8 changes: 2 additions & 6 deletions src/components/loaders/EPNSActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import {ActivityIndicator, Platform, StyleSheet, View} from 'react-native';
import GLOBALS from 'src/Globals';

const EPNSActivity = ({style, size, color}) => {
const EPNSActivity = ({style, size, color = GLOBALS.COLORS.GRADIENT_THIRD}) => {
return (
<View
style={[
Expand All @@ -13,11 +13,7 @@ const EPNSActivity = ({style, size, color}) => {
size === 'small' ? styles.small : styles.big,
]}>
{Platform.OS == 'android' || color ? (
<ActivityIndicator
style={styles.activity}
size={size}
color={color ? color : GLOBALS.COLORS.GRADIENT_THIRD}
/>
<ActivityIndicator style={styles.activity} size={size} color={color} />
) : (
<MaskedView
style={styles.maskedView}
Expand Down
Loading

0 comments on commit 1ed6752

Please sign in to comment.