Untitled
unknown
plain_text
2 years ago
8.7 kB
3
Indexable
import React, { useMemo } from 'react';
import { Card, Text, View } from 'react-native-ui-lib';
type Props = {
report: any;
company?: any;
};
const SocialComparison = ({ report, company }: Props) => {
const memoized: any = useMemo(() => {
const data = report && report?.data;
let competitions: any = [];
let myScore = [];
let isError = false;
let isScorerError = false;
let isCompetitionError = false;
let isSocialError = false;
let errorMessageType;
if (!data) {
isError = true;
errorMessageType = 'errorMessage';
}
if (!isError) {
const { score } = report?.data?.score; // score verilerini almamıza yarıyor:
const { competition } = report?.data?.competition; // competitionsları almamıza yarıyor:
if (!competition || competition.length === 0) {
isCompetitionError = true;
errorMessageType = 'competitorNotExist';
}
if (!isCompetitionError && !isError) {
competition.forEach((singleCompetition: any) =>
competitions.push(parseCompanyData(singleCompetition)),
);
}
// console.log(competitions, "62")
// console.log(report?.data?.competition[0], "yuyuy")
console.log(score,"2893")
if (score) {
const { social } = score;
if (!social || social.length === 0) {
isSocialError = true;
errorMessageType = 'companySocialNotExist';
}
if (isSocialError && isCompetitionError) {
errorMessageType = 'CompetitorAndSocialNotExist';
}
} else {
isScorerError = true;
errorMessageType = 'errorMessage';
}
if (!isSocialError && !isScorerError) {
myScore = score;
}
}
if (!data) {
return null;
}
const parseCompanyData = (bahar: any) => {
const parseCompany: any = [];
if (!isSocialError && !isError) {
bahar.social.forEach((socialItem: any) => {
if (socialItem.type != 'linkedin') {
let numberOfPosts;
let numberOfPostsChange;
let averageLikesPerPost;
let averageLikesPerPostPrevious;
let averageLikesPerPostChange;
let averageSharesPerPost;
let averageSharesPerPostPrevious;
let averageSharesPerPostChange;
let averageCommentsPerPost;
let averageCommentsPerPostPrevious;
let averageCommentsPerPostChange;
if (report.data.type === 'MONTHLY') {
if (socialItem.type === 'facebook') {
numberOfPosts = socialItem.numberOfPostsLastMonth; // Total posts or posts monthly?
numberOfPostsChange =
socialItem.numberOfPostsLastMonth -
socialItem.numberOfPostsPastMonth;
averageLikesPerPost = socialItem.averageReactions;
averageLikesPerPostPrevious =
socialItem.reactionsPastMonth /
socialItem.numberOfPostsPastMonth;
averageLikesPerPostChange =
averageLikesPerPost - averageLikesPerPostPrevious;
averageSharesPerPost = socialItem.averageShares;
averageSharesPerPostPrevious =
socialItem.sharesPastMonth / socialItem.numberOfPostsPastMonth;
averageSharesPerPostChange =
averageSharesPerPost - averageSharesPerPostPrevious;
averageCommentsPerPost = socialItem.averageComments;
averageCommentsPerPostPrevious =
socialItem.commentPastMonth / socialItem.numberOfPostsPastMonth;
averageCommentsPerPostChange =
averageCommentsPerPost - averageCommentsPerPostPrevious;
} else {
numberOfPosts = socialItem.numberOfPostsLastMonth; // Total posts or posts monthly?
numberOfPostsChange =
socialItem.numberOfPostsLastMonth -
socialItem.numberOfPostsPastMonth;
averageLikesPerPost = socialItem.averageLikes;
averageLikesPerPostPrevious =
socialItem.likesPastMonth / socialItem.numberOfPostsPastMonth;
averageLikesPerPostChange =
averageLikesPerPost - averageLikesPerPostPrevious;
averageSharesPerPost = socialItem.averageShares;
averageSharesPerPostPrevious =
socialItem.sharesPastMonth / socialItem.numberOfPostsPastMonth;
averageSharesPerPostChange =
averageSharesPerPost - averageSharesPerPostPrevious;
averageCommentsPerPost = socialItem.averageComments;
averageCommentsPerPostPrevious =
socialItem.commentPastMonth / socialItem.numberOfPostsPastMonth;
averageCommentsPerPostChange =
averageCommentsPerPost - averageCommentsPerPostPrevious;
}
} else if (socialItem.type === 'facebook') {
numberOfPosts = socialItem.numberOfPostsLastWeek; // Total posts or posts Weekly?
numberOfPostsChange =
socialItem.numberOfPostsLastWeek -
socialItem.numberOfPostsPastWeek;
averageLikesPerPost = socialItem.averageReactions;
averageLikesPerPostPrevious =
socialItem.reactionsPastWeek / socialItem.numberOfPostsPastWeek;
averageLikesPerPostChange =
averageLikesPerPost - averageLikesPerPostPrevious;
averageSharesPerPost = socialItem.averageShares;
averageSharesPerPostPrevious =
socialItem.sharesPastWeek / socialItem.numberOfPostsPastWeek;
averageSharesPerPostChange =
averageSharesPerPost - averageSharesPerPostPrevious;
averageCommentsPerPost = socialItem.averageComments;
averageCommentsPerPostPrevious =
socialItem.commentPastWeek / socialItem.numberOfPostsPastWeek;
averageCommentsPerPostChange =
averageCommentsPerPost - averageCommentsPerPostPrevious;
} else {
numberOfPosts = socialItem.numberOfPostsLastWeek; // Total posts or posts Weekly?
numberOfPostsChange =
socialItem.numberOfPostsLastWeek -
socialItem.numberOfPostsPastWeek;
averageLikesPerPost = socialItem.averageLikes;
averageLikesPerPostPrevious =
socialItem.likesPastWeek / socialItem.numberOfPostsPastWeek;
averageLikesPerPostChange =
averageLikesPerPost - averageLikesPerPostPrevious;
averageSharesPerPost = socialItem.averageShares;
averageSharesPerPostPrevious =
socialItem.sharesPastWeek / socialItem.numberOfPostsPastWeek;
averageSharesPerPostChange =
averageSharesPerPost - averageSharesPerPostPrevious;
averageCommentsPerPost = socialItem.averageComments;
averageCommentsPerPostPrevious =
socialItem.commentPastWeek / socialItem.numberOfPostsPastWeek;
averageCommentsPerPostChange =
averageCommentsPerPost - averageCommentsPerPostPrevious;
}
parseCompany.push({
icon: socialItem.type,
name: bahar.name,
status: socialItem.status,
values: [
{
// Post
value: numberOfPosts,
exchangeValue: numberOfPostsChange,
},
{
// Avg. likes
value: averageLikesPerPost,
exchangeValue: averageLikesPerPostChange,
warnIndex: 2,
},
{
// Avg. Shares
value: averageSharesPerPost,
exchangeValue: averageSharesPerPostChange,
},
{
// Avg. Comment
value: averageCommentsPerPost,
exchangeValue: averageCommentsPerPostChange,
},
],
});
}
});
}
console.log(parseCompany.name,"123")
};
// return parseCompany;
// console.log(memoized?.parseCompany,"hasanbahar")
return { competitions,parseCompany }
}, [report])
// console.log(memoized?.parseCompany)
// memoized?.competitions?.values?.map((index) => {
// console.log(index)
// })
return (
<>
</>
);
};
export default SocialComparison;
Editor is loading...