Skip to content

Commit

Permalink
Activity,Comment and search screen small bug fixes (#701)
Browse files Browse the repository at this point in the history
* Resolves #686 - timestamp to date according to latest PR

* Resolve - #699 Resolve - #666 Resolve - #635 Resolve - #566 Resolve - #674 Resolve - #669 activitylog mention date, comment activity mentions and date format, search screen

* resolve conflict

* search bar useeffect typo mistake
  • Loading branch information
jhenterprise committed Jul 19, 2022
1 parent 7998456 commit 8fa9dfd
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 18 deletions.
12 changes: 3 additions & 9 deletions components/Card/ActivityLogCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ActivityLogCard = ({ preview, refreshing }) => {
const [accordionState, setAccordionState] = useState([]);
const navigation = useNavigation();
const { styles, globalStyles } = useStyles(localStyles);
const { i18n,moment, numberFormat } = useI18N();
const { i18n, numberFormat } = useI18N();

useEffect(() => {
if (groupedActivityLog) {
Expand All @@ -32,13 +32,6 @@ const ActivityLogCard = ({ preview, refreshing }) => {
}
}, [groupedActivityLog]);

const timestamptoDate = (match, timestamp) => {
if ( isNaN(timestamp) ){
return false
}
return moment(timestamp*1000).format('MMM D, YYYY');
}

const handleAccordionChange = (groupIndex) => {
const updatedAccordionState = accordionState.map((item, index) =>
index === groupIndex ? !item : item
Expand Down Expand Up @@ -76,7 +69,8 @@ const ActivityLogCard = ({ preview, refreshing }) => {
if (!groupedActivityLog[makeKey]) {
groupedActivityLog[makeKey] = [];
}
element.object_note = baptismDateRegex.test(element.object_note)?element.object_note.replace(baptismDateRegex, timestamptoDate):element.object_note;
//element.object_note = baptismDateRegex.test(element.object_note)?element.object_note.replace(baptismDateRegex, timestamptoDate):element.object_note;
//element.object_note = mentionName.test(element.object_note)?element.object_note.replace(mentionName, stringtoMention):element.object_note;
groupedActivityLog[makeKey].push({
...element,
});
Expand Down
2 changes: 1 addition & 1 deletion components/FilterList/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const SearchBar = ({
const debouncedSearch = useDebounce(_search, 1000);

useEffect(() => {
if (onSearch) onSearch(debouncedSearch);
if (onSearch) onSearch(debouncedSearch.trim().normalize("NFD").replace(/[\u0300-\u036f]/g, ""));
Keyboard.dismiss();
return;
}, [debouncedSearch]);
Expand Down
74 changes: 71 additions & 3 deletions components/RenderActivityLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { View, Text, Pressable } from "react-native";
import { useNavigation } from "@react-navigation/native";

import { ScreenConstants } from "constants";
import ParsedText from "react-native-parsed-text";
import useI18N from "hooks/use-i18n";

import PrefetchCacheRecord from "components/PrefetchCacheRecord";
import { ChevronDownIcon, ChevronUpIcon } from "components/Icon";
Expand All @@ -20,10 +22,30 @@ const RenderActivityLog = ({
}) => {
const { styles, globalStyles } = useStyles(localStyles);
const { getTabScreenFromType } = useType();
const { moment } = useI18N();
const navigation = useNavigation();

const MENTION_PATTERN = /@\[\w* \w* \(\w*\)\]\(\.?\w*\)*/g;
const MENTION_PATTERN_2 = /@\[\w*\]\(\.?\w*\)*/g;
const BAPTISM_DATE_PATTERN = /\{(\d+)\}+/;
if (!logs || logs.length === 0 || accordionState.length === 0) return null;

const renderMention = (matchingString, matches) => {
let mentionText = matchingString.substring(
matchingString.lastIndexOf("[") + 1,
matchingString.lastIndexOf("]")
);
return `@${mentionText}`;
};

const timestamptoDate = (match, timestamp) => {
match = match.replace('{','');
match = match.replace('}','');
if ( isNaN(match*1000) ){
return false;
}
return moment(match*1000).format('MMM D, YYYY');
}

return (
<>
<View
Expand All @@ -47,7 +69,8 @@ const RenderActivityLog = ({
}
}}
>
<Text style={styles.activityLink}>{logs?.[0] ?? " "}</Text>
<Text style={styles.activityLink}>
{logs?.[0] ?? " "}</Text>
</Pressable>
<Pressable
onPress={() => {
Expand All @@ -63,7 +86,30 @@ const RenderActivityLog = ({
<>
{/* Show all the entries. */}
<Text key={`${log.object_id}-${index}`} style={styles.activityText}>
<ParsedText
//selectable
style={styles.commentText(true)}
parse={[
{
pattern: MENTION_PATTERN,
style: styles.parseText,
renderText: renderMention,
},
{
pattern: MENTION_PATTERN_2,
style: styles.parseText,
renderText: renderMention,
},
{
pattern: BAPTISM_DATE_PATTERN,
style: styles.activityText,
renderText: timestamptoDate,
},
]}
>
{log?.object_note}
</ParsedText>
{/* {log?.object_note} */}
</Text>
{
// Prefetch any posts in the ActivityLog so that the records
Expand All @@ -77,7 +123,29 @@ const RenderActivityLog = ({
) : (
<>
{/* Show only one entry. */}
<Text style={styles.activityText}>{logs?.[1][0]?.object_note}</Text>
<Text style={styles.activityText}><ParsedText
//selectable
style={styles.commentText(true)}
parse={[
{
pattern: MENTION_PATTERN,
style: styles.parseText,
renderText: renderMention,
},
{
pattern: MENTION_PATTERN_2,
style: styles.parseText,
renderText: renderMention,
},
{
pattern: BAPTISM_DATE_PATTERN,
style: styles.activityText,
renderText: timestamptoDate,
},
]}
>
{logs?.[1][0]?.object_note}
</ParsedText></Text>
{
// Prefetch any posts in the ActivityLog so that the records
// are available if the user goes OFFLINE.
Expand Down
13 changes: 13 additions & 0 deletions components/RenderActivityLog.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ export const localStyles = ({ theme, isRTL, isIOS }) => ({
fontStyle: "italic",
paddingVertical: 2,
},
commentText: (isActivity) => ({
flexDirection: "row",
color: isActivity ? theme.text.secondary : theme.text.primary,
fontStyle: isActivity ? "italic" : null,
padding: 5,
}),
parseText: {
color:
ThemeConstants.DARK === theme.mode
? theme.highlight
: theme.brand.primary,
textDecorationLine: "underline",
}
});
21 changes: 18 additions & 3 deletions screens/Posts/CommentsActivityScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import { parseDateSafe, decodeHTMLEntities } from "utils";

import { localStyles } from "./CommentsActivityScreen.styles";

const MENTION_PATTERN = /@\[.+?\]\((.*)\)/g;

//const MENTION_PATTERN = /@\[.+?\]\((.*)\)/g;
const MENTION_PATTERN = /@\[\w* \w* \(\w*\)\]\(\.?\w*\)*/g
const BAPTISM_DATE_PATTERN = /\{(\d+)\}+/;
const OFFSET_Y = 125;

const CommentsActivityConstants = Object.freeze({
Expand Down Expand Up @@ -113,7 +114,7 @@ const CommentsActivityScreen = ({
const CommentsActivityItem = ({ item, loading }) => {
if (!item || loading) return <CommentsActivityItemLoadingSkeleton />;
let message = item?.comment_content || item?.object_note;
const datetime = moment(parseDate(item)).format("LLLL");
const datetime = moment(parseDate(item)).format("d MMMM YYYY,H:m");
const author = item?.comment_author || item?.name;
const authorId = Number(item?.user_id);
const userIsAuthor = authorId === userData?.ID;
Expand Down Expand Up @@ -261,6 +262,15 @@ const CommentsActivityScreen = ({
return `@${mentionText}`;
};

const timestamptoDate = (match, timestamp) => {
match = match.replace('{','');
match = match.replace('}','');
if ( isNaN(match*1000) ){
return false;
}
return moment(match*1000).format('MMM D, YYYY');
}

return (
<Pressable onLongPress={() => onLongPress()}>
<View style={styles.container}>
Expand Down Expand Up @@ -315,6 +325,11 @@ const CommentsActivityScreen = ({
style: styles.parseText,
renderText: renderMention,
},
{
pattern: BAPTISM_DATE_PATTERN,
style: styles.time,
renderText: timestamptoDate,
}
]}
>
{hasUrl ? messageArr : decodeHTMLEntities(message)}
Expand Down
4 changes: 2 additions & 2 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export const searchObj = (
searchStr,
{ caseInsensitive, include, exclude } = {}
) => {
if (caseInsensitive) searchStr = searchStr?.toLowerCase();
if (caseInsensitive) searchStr = searchStr?.toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
const result = [];
const recursiveSearch = (obj = {}) => {
if (!obj || typeof obj !== "object") return;
Object.keys(obj).forEach((key) => {
let value = String(obj[key]);
if (caseInsensitive) value = value?.toLowerCase();
if (caseInsensitive) value = value?.toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
// if key/prop is in include list, then check if value contains searchStr
if (include?.length > 0) {
include.forEach((prop) => {
Expand Down

0 comments on commit 8fa9dfd

Please sign in to comment.