diff --git a/components/badge/index.tsx b/components/badge/index.tsx new file mode 100644 index 0000000..375a034 --- /dev/null +++ b/components/badge/index.tsx @@ -0,0 +1,13 @@ +import React from 'react' +import { IBadgeProps } from '@/types'; + +const Badge = (props: IBadgeProps) => { + const { text, tooltip } = props; + return ( + + {text} + + ) +} + +export default Badge \ No newline at end of file diff --git a/components/cards/button/index.tsx b/components/cards/button/index.tsx deleted file mode 100644 index 7d264b4..0000000 --- a/components/cards/button/index.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { IButtonCardProps } from "@/types"; -import React from "react"; - -const ButtonCard = (props: IButtonCardProps) => { - if (props) { - const { cardStyle, cardHeaderTitle, cardTooltip, cardOnClick } = props; - return ( - - ); - } else return null; -}; - -export default ButtonCard; diff --git a/components/cards/summary/index.tsx b/components/cards/summary/index.tsx index 9e3be3f..b2c68c9 100644 --- a/components/cards/summary/index.tsx +++ b/components/cards/summary/index.tsx @@ -1,58 +1,75 @@ import React from "react"; -import { ISummaryCardProps } from "@/types"; +import { ISummaryCardContentProps, ISummaryCardProps } from "@/types"; import { cardBodyTypes } from "@/utils/enums"; import { formatCompactNumber } from "@/utils/helpers"; +import SummaryCardLayout from "./layout"; const SummaryCard = (props: ISummaryCardProps) => { if (props) { const { cardStyle, + cardType, cardHeaderTitle, cardHeaderContent, cardBodyType, cardBodyContent, + cardBodyLongContent, + cardFooterContent, + cardClickEvent, + cardTooltip, } = props; + return ( -
-
-

{cardHeaderTitle}

-

{cardHeaderContent}

-
+ + {cardHeaderTitle && ( +
+

{cardHeaderTitle}

+

{cardHeaderContent}

+
+ )}
+ {cardFooterContent && +
+ {cardFooterContent} +
}
-
+ ); } else return null; }; -const SummaryContent = ({ - cardBodyType, - cardBodyContent, -}: { - cardBodyType: number; - cardBodyContent: any; -}) => { +const SummaryContent = (props: ISummaryCardContentProps) => { + const { + cardBodyType, + cardBodyContent, + cardBodyLongContent, + } = props; if (cardBodyType === cardBodyTypes.NUMBER) { return ( -

- {formatCompactNumber(cardBodyContent)} +

+ {formatCompactNumber(cardBodyContent.toString())}

); } else if (cardBodyType === cardBodyTypes.STRING) { return (

{cardBodyContent}

); - } else if (cardBodyType === cardBodyTypes.ELEMENT) { - return cardBodyContent; + } else if (cardBodyType === cardBodyTypes.ELEMENT && typeof cardBodyContent === "object") { + return ( +
+ {cardBodyContent} +
+ ); } else return null; }; diff --git a/components/cards/summary/layout.tsx b/components/cards/summary/layout.tsx new file mode 100644 index 0000000..e336a9b --- /dev/null +++ b/components/cards/summary/layout.tsx @@ -0,0 +1,22 @@ +import { ISummaryCardLayoutProps } from '@/types' +import { elementType } from '@/utils/enums'; +import React from 'react' + +const SummaryCardLayout = (props: ISummaryCardLayoutProps) => { + const { type, style, typeData, tooltip, children } = props; + if (type === elementType.button) { + return ( + + ); + } else { + return ( +
+ {children} +
+ ) + } +} + +export default SummaryCardLayout \ No newline at end of file diff --git a/components/sections/dashboard/index.tsx b/components/sections/dashboard/index.tsx index 86db54c..4ac2a48 100644 --- a/components/sections/dashboard/index.tsx +++ b/components/sections/dashboard/index.tsx @@ -1,10 +1,11 @@ import React, { useEffect, useState } from "react"; import SectionLayout from "../layout"; import SummaryCard from "@/components/cards/summary"; -import { cardBodyTypes } from "@/utils/enums"; +import { cardBodyTypes, elementType } from "@/utils/enums"; import Avatar from "@/components/avatar"; import { IDashboardProps, IGroupProps, ILatestMessageProps } from "@/types"; import { getBriefContent, isImage } from "@/utils/helpers"; +import Badge from "@/components/badge"; const Dashboard = (props: IDashboardProps) => { const [groups] = useState(props.groups); @@ -33,8 +34,8 @@ const Dashboard = (props: IDashboardProps) => { const message = props?.groups ?.map((g) => g.lastMessage) .sort((mA, mB) => Date.parse(mB?.createdOn) - Date.parse(mA?.createdOn)) - .at(0); - const group = props?.groups?.find((g) => g.id === message?.groupId); + .at(0), + group = props?.groups?.find((g) => g.id === message?.groupId && g.unreadCount > 0); return group && message ? Object.assign(message, { displayImage: group?.displayImage!, groupName: group?.name! @@ -43,6 +44,8 @@ const Dashboard = (props: IDashboardProps) => { }, [props]); if (props) { + const name = user?.firstName ?? user?.username, gridCols = online || unread ? 3 : 2; + return (
@@ -50,16 +53,15 @@ const Dashboard = (props: IDashboardProps) => {

Hello{" "} - {user?.firstName ?? user?.username} + {name}

-
+
{groups && ( { )} {friends && ( { )} {online && ( { )} {latest && ( { isStatus={false} /> } - cardBodyType={cardBodyTypes.STRING} + cardBodyType={cardBodyTypes.ELEMENT} cardBodyContent={ - isImage(latest.content) - ? "Image" - : getBriefContent(latest.content) +

+ {isImage(latest.content) ? "Image" : getBriefContent(latest.content)} +

} + cardBodyLongContent={latest.content} + cardFooterContent={ + + } + cardClickEvent={() => props.onSelectGroupHandler(latest.groupId)} /> )} {unread && ( { } else if (section === sections.home) { return (
- +
); } else if (section === sections.addFriend) { diff --git a/components/sections/introduction/index.tsx b/components/sections/introduction/index.tsx index c5455b2..5ae9dc4 100644 --- a/components/sections/introduction/index.tsx +++ b/components/sections/introduction/index.tsx @@ -1,9 +1,8 @@ import React from "react"; import SectionLayout from "../layout"; import SummaryCard from "@/components/cards/summary"; -import { cardBodyTypes, sections } from "@/utils/enums"; +import { cardBodyTypes, elementType, sections } from "@/utils/enums"; import { IIntroductionProps } from "@/types"; -import ButtonCard from "@/components/cards/button"; import Avatar from "@/components/avatar"; import { getBriefContent, writeContentToClipboard } from "@/utils/helpers"; @@ -23,37 +22,32 @@ const Introduction = (props: IIntroductionProps) => {
- setSection(sections.addFriend)} - cardTooltip={"Add Friend to Chat"} + Add Friend} + cardClickEvent={() => setSection(sections.addFriend)} + cardType={elementType.button} + cardTooltip="Add Friend" /> writeContentToClipboard(user?.emailAddresses?.at(0)?.emailAddress)} - className="text-stone-100 rounded-full p-2 bg-gradient-to-b from-green-400 to-green-500 shadow-sm text-ellipsis overflow-hidden"> -

- {getBriefContent(user?.emailAddresses?.at(0)?.emailAddress)} -

- + cardBodyContent={ } - cardHeaderContent={ - - } /> + cardHeaderContent={} + cardType={elementType.div} />
diff --git a/pages/index.tsx b/pages/index.tsx index 5f1fdff..3fbaa0a 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -45,7 +45,6 @@ import { saveFile, updateUnread, } from "@/utils/http"; -import Head from "next/head"; let socket: Socket; diff --git a/types/index.tsx b/types/index.tsx index 64ba5b0..7518da7 100644 --- a/types/index.tsx +++ b/types/index.tsx @@ -1,10 +1,11 @@ -import { groupTypes, messageTypes, sections } from "@/utils/enums"; +import { elementType, groupTypes, messageTypes, sections } from "@/utils/enums"; import { ChangeEventHandler, KeyboardEventHandler, LegacyRef, MouseEventHandler, + ReactElement, ReactNode, } from "react"; @@ -12,7 +13,9 @@ import { User } from "@clerk/nextjs/dist/types/server"; export type NameType = string | null | undefined; -export type NotifType = string | boolean | null; +export type NotificationType = string | boolean | null; + +export type CardContentType = string | number | ReactElement; export type PersistedSocket = { id: string; @@ -113,7 +116,7 @@ export interface IMessageListProps { messages: IMessageProps[] | undefined; group: IGroupProps | null | undefined; active: IActiveProps; - notifs: NotifType; + notifs: NotificationType; lastMessageRef: LegacyRef; onDeleteHandler: Function; onCopyHandler: Function; @@ -172,19 +175,35 @@ export interface IMessageCardProps { loading: boolean; } +export interface ICardTypeData { + clickEvent: MouseEventHandler | undefined; +} + +export interface ISummaryCardLayoutProps { + style: string; + type?: elementType; + typeData: ICardTypeData; + tooltip?: string; + children: ReactNode; +} + export interface ISummaryCardProps { cardStyle: string; - cardHeaderTitle: string; - cardHeaderContent?: any; + cardType: elementType; + cardHeaderTitle?: string; + cardHeaderContent?: CardContentType; cardBodyType: number; - cardBodyContent: any; + cardBodyContent: CardContentType; + cardBodyLongContent?: string; + cardFooterContent?: CardContentType; + cardClickEvent?: MouseEventHandler; + cardTooltip?: string; } -export interface IButtonCardProps { - cardStyle: string; - cardHeaderTitle: string; - cardTooltip: string; - cardOnClick: MouseEventHandler; +export interface ISummaryCardContentProps { + cardBodyType: number; + cardBodyContent: CardContentType; + cardBodyLongContent?: string; } export interface IAvatarProps { @@ -241,7 +260,8 @@ export interface ISectionLayoutProps { export interface IDashboardProps { groups: IGroupProps[]; user: any; - notifs: NotifType; + notifs: NotificationType; + onSelectGroupHandler: Function; } export interface IIntroductionProps { @@ -254,7 +274,7 @@ export interface ISecitonSwitchProps { setSection: Function; user: any; active: any; - notifs: NotifType; + notifs: NotificationType; input: string; loading: boolean; group: IGroupProps; @@ -278,7 +298,7 @@ export interface ISecitonSwitchProps { export interface IGroupSectionProps { group: IGroupProps; active: any; - notifs: NotifType; + notifs: NotificationType; input: string; loading: boolean; messages: IMessageProps[] | undefined; @@ -311,3 +331,8 @@ export interface IAddFriendProps { onSelectGroupHandler: Function; groups: IGroupProps[] | null | undefined; } + +export interface IBadgeProps { + text: string; + tooltip: string; +} diff --git a/utils/enums.ts b/utils/enums.ts index 7916945..b7bc77b 100644 --- a/utils/enums.ts +++ b/utils/enums.ts @@ -67,3 +67,8 @@ export enum sections { export enum strings { someone = "Someone", } + +export enum elementType { + button = "button", + div = "div", +} diff --git a/utils/helpers.ts b/utils/helpers.ts index 45f00d1..454f535 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -1,4 +1,4 @@ -import { NameType } from "@/types"; +import { CardContentType, NameType } from "@/types"; import { mediaTypes, messageTypes } from "./enums"; const getTimeConverted = (tempDate: Date = new Date()) => {