Skip to content

Commit

Permalink
[AC-2704] feat: widget modularization - phase 1 (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 authored Sep 6, 2024
1 parent 7b9797b commit 3fc3551
Show file tree
Hide file tree
Showing 90 changed files with 2,921 additions and 1,461 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
"styled-components": "^5.3.11"
},
"devDependencies": {
"@linaria/atomic": "^6.2.0",
"@linaria/core": "^6.2.0",
"@linaria/react": "^6.2.1",
"@types/dompurify": "^3.0.5",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"@vitejs/plugin-react": "^4.2.1",
"@wyw-in-js/babel-preset": "^0.5.3",
"@wyw-in-js/vite": "^0.5.3",
"date-fns": "^3.6.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/self-service/scripts/generateIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function generateIndexFile(version) {
process.exit(1);
}

const content = `import(\`/${version}/output.js\`).then(() => console.log("AI chatbot module has been successfully loaded"));`;
const content = `import('./${version}/output.js').then(() => console.log("AI chatbot module has been successfully loaded"));`;

fs.writeFileSync('dist/index.js', content);
fs.cpSync('playground', 'dist/playground', { recursive: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/self-service/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineConfig({
output: {
manualChunks: undefined,
entryFileNames: `output.js`,
chunkFileNames: `[name].js`,
chunkFileNames: `[hash].js`,
assetFileNames: `[name].[ext]`,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/uikit
Submodule uikit updated 63 files
+38 −38 src/modules/GroupChannel/components/MessageInputWrapper/MessageInputWrapperView.tsx
+1 −9 src/svgs/icon-add.svg
+1 −9 src/svgs/icon-arrow-left.svg
+1 −9 src/svgs/icon-attach.svg
+1 −11 src/svgs/icon-audio-on-lined.svg
+1 −9 src/svgs/icon-ban.svg
+1 −9 src/svgs/icon-broadcast.svg
+1 −9 src/svgs/icon-camera.svg
+1 −9 src/svgs/icon-channels.svg
+1 −9 src/svgs/icon-chat-filled.svg
+1 −9 src/svgs/icon-chat.svg
+1 −9 src/svgs/icon-chevron-down.svg
+1 −9 src/svgs/icon-chevron-right.svg
+1 −9 src/svgs/icon-close.svg
+1 −9 src/svgs/icon-collapse.svg
+1 −9 src/svgs/icon-copy.svg
+1 −9 src/svgs/icon-create.svg
+1 −9 src/svgs/icon-delete.svg
+1 −9 src/svgs/icon-disconnected.svg
+1 −9 src/svgs/icon-document.svg
+1 −9 src/svgs/icon-done-all.svg
+1 −9 src/svgs/icon-done.svg
+1 −9 src/svgs/icon-download.svg
+1 −9 src/svgs/icon-edit.svg
+1 −9 src/svgs/icon-emoji-more.svg
+1 −9 src/svgs/icon-error.svg
+1 −9 src/svgs/icon-expand.svg
+1 −7 src/svgs/icon-feedback-dislike.svg
+1 −7 src/svgs/icon-feedback-like.svg
+1 −9 src/svgs/icon-file-audio.svg
+1 −9 src/svgs/icon-file-document.svg
+1 −9 src/svgs/icon-freeze.svg
+1 −9 src/svgs/icon-gif.svg
+1 −9 src/svgs/icon-info.svg
+1 −9 src/svgs/icon-leave.svg
+1 −9 src/svgs/icon-members.svg
+1 −9 src/svgs/icon-message.svg
+1 −9 src/svgs/icon-moderations.svg
+1 −9 src/svgs/icon-more.svg
+1 −9 src/svgs/icon-mute.svg
+1 −9 src/svgs/icon-notifications-off-filled.svg
+1 −9 src/svgs/icon-notifications.svg
+1 −9 src/svgs/icon-operator.svg
+1 −9 src/svgs/icon-photo.svg
+1 −9 src/svgs/icon-play.svg
+1 −9 src/svgs/icon-plus.svg
+1 −9 src/svgs/icon-question.svg
+1 −9 src/svgs/icon-refresh.svg
+1 −9 src/svgs/icon-remove.svg
+1 −15 src/svgs/icon-reply-filled.svg
+1 −9 src/svgs/icon-search.svg
+1 −9 src/svgs/icon-send.svg
+1 −9 src/svgs/icon-settings-filled.svg
+1 −3 src/svgs/icon-slide-left.svg
+1 −9 src/svgs/icon-spinner.svg
+1 −9 src/svgs/icon-supergroup.svg
+1 −4 src/svgs/icon-thread.svg
+1 −9 src/svgs/icon-thumbnail-none.svg
+1 −12 src/svgs/icon-toggleoff.svg
+1 −12 src/svgs/icon-toggleon.svg
+1 −9 src/svgs/icon-user.svg
+11 −10 src/ui/MessageInput/index.tsx
+1 −0 tsconfig.json
13 changes: 6 additions & 7 deletions src/components/BotMessageFeedback.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { Feedback, FeedbackRating } from '@sendbird/chat/message';
import { BaseMessage, Feedback, FeedbackRating } from '@sendbird/chat/message';
import { useReducer } from 'react';

import FeedbackIconButton from '@uikit/ui/FeedbackIconButton';
import Icon, { IconTypes } from '@uikit/ui/Icon';
import MessageFeedbackFailedModal from '@uikit/ui/MessageFeedbackFailedModal';
import MessageFeedbackModal from '@uikit/ui/MessageFeedbackModal';
import MobileFeedbackMenu from '@uikit/ui/MobileFeedbackMenu';
import { CoreMessageType } from '@uikit/utils';

import { elementIds } from '../const';
import { useConstantState } from '../context/ConstantContext';
import { Icon } from '../foundation/components/Icon';

type State = Partial<{
errorText: string;
modalVisible: boolean;
menuVisible: boolean;
}>;

function BotMessageFeedback({ message }: { message: CoreMessageType }) {
function BotMessageFeedback({ message }: { message: BaseMessage }) {
const { stringSet } = useConstantState();
const [state, setState] = useReducer((p: State, a: State) => ({ ...p, ...a }), {
errorText: '',
Expand Down Expand Up @@ -50,7 +49,7 @@ function BotMessageFeedback({ message }: { message: CoreMessageType }) {
}}
disabled={!!message.myFeedback && message.myFeedback.rating !== FeedbackRating.GOOD}
>
<Icon type={IconTypes.FEEDBACK_LIKE} width="24px" height="24px" />
<Icon type={'feedback-like'} size={24} />
</FeedbackIconButton>
<FeedbackIconButton
aria-label="Dislike the bot answer"
Expand All @@ -70,7 +69,7 @@ function BotMessageFeedback({ message }: { message: CoreMessageType }) {
}}
disabled={!!message.myFeedback && message.myFeedback.rating !== FeedbackRating.BAD}
>
<Icon type={IconTypes.FEEDBACK_DISLIKE} width="24px" height="24px" />
<Icon type={'feedback-dislike'} size={24} />
</FeedbackIconButton>
</div>
{
Expand Down Expand Up @@ -104,7 +103,7 @@ function BotMessageFeedback({ message }: { message: CoreMessageType }) {
isMobile
rootElementId={elementIds.widgetWindow}
selectedFeedback={message.myFeedback.rating}
message={message}
message={message as any}
onUpdate={async (selectedFeedback, comment) => {
if (message.myFeedback) {
try {
Expand Down
35 changes: 8 additions & 27 deletions src/components/BotMessageWithBodyInput.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { User } from '@sendbird/chat';
import { ReactNode } from 'react';
import styled from 'styled-components';

import Avatar from '@uikit/ui/Avatar';
import Label, { LabelColors, LabelTypography } from '@uikit/ui/Label';

import BotProfileImage from './BotProfileImage';
import { useChatContext } from './chat/context/ChatProvider';
import { DefaultSentTime, FullBodyContainer, WideSentTime } from './MessageComponent';
import { useConstantState } from '../context/ConstantContext';
import { Label } from '../foundation/components/Label';
import { formatCreatedAtToAMPM } from '../utils/messageTimestamp';

const Root = styled.span`
display: flex;
flex-direction: row;
align-items: flex-end;
margin-bottom: 6px;
gap: 8px;
position: relative;
`;
Expand All @@ -40,14 +37,11 @@ const EmptyImageContainer = styled.div`
`;

type Props = {
botUser?: User;
createdAt?: number;
messageData?: string;
bodyComponent: ReactNode;
chainTop?: boolean;
chainBottom?: boolean;
messageCount?: number;
zIndex?: number;
messageFeedback?: ReactNode;
wideContainer?: boolean;
};
Expand All @@ -59,46 +53,33 @@ const HEIGHTS = {
};

export default function BotMessageWithBodyInput(props: Props) {
const { botUser } = useChatContext();
const { botStudioEditProps, dateLocale } = useConstantState();

const {
botUser,
createdAt,
bodyComponent,
messageCount,
zIndex,
chainTop,
chainBottom,
messageFeedback,
wideContainer = false,
} = props;
const { createdAt, bodyComponent, chainTop, chainBottom, messageFeedback, wideContainer = false } = props;

const profilePaddingBottom = (messageFeedback ? HEIGHTS.FEEDBACK : 0) + (wideContainer ? HEIGHTS.TIMESTAMP : 0);

const nonChainedMessage = chainTop == null && chainBottom == null;
const displayProfileImage = nonChainedMessage || chainBottom;
const displaySender = nonChainedMessage || chainTop;
const displayProfileImage = nonChainedMessage || chainBottom;
const { profileUrl, nickname } = botStudioEditProps?.botInfo ?? {};
const botProfileUrl = profileUrl ?? botUser?.profileUrl;
const botNickname = nickname ?? botUser?.nickname;

return (
<Root style={{ zIndex: messageCount === 1 && zIndex ? zIndex : 0 }}>
<Root>
{displayProfileImage ? (
<div style={{ paddingBottom: profilePaddingBottom }}>
{botProfileUrl != null && botProfileUrl != '' ? (
<Avatar src={botProfileUrl} alt="botProfileImage" height="28px" width="28px" />
) : (
<BotProfileImage width={28} height={28} iconWidth={16} iconHeight={16} />
)}
<BotProfileImage size={28} profileUrl={botProfileUrl} />
</div>
) : (
<EmptyImageContainer />
)}
<FullBodyContainer>
{displaySender && (
<Sender>
<Label type={LabelTypography.CAPTION_2} color={LabelColors.ONBACKGROUND_2}>
<Label type={'caption2'} color={'onbackground2'}>
{botNickname}
</Label>
</Sender>
Expand Down
48 changes: 26 additions & 22 deletions src/components/BotProfileImage.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import styled from 'styled-components';
import { styled } from '@linaria/react';
import { useTheme } from 'styled-components';

import { getColorBasedOnSaturation } from '../colors';
import Icon from '../icons/bot-profile-image-small.svg';
import BotProfileIcon from '../icons/bot-profile-image-small.svg';

interface ImageProps {
width: number;
height: number;
iconWidth: number;
iconHeight: number;
}
const StyledBotImage = styled.span<ImageProps>`
width: ${({ width }) => `${width}px`};
height: ${({ height }) => `${height}px`};
background: ${({ theme }) => theme.accentColor};
const Container = styled.span<{ backgroundColor: string; size: number }>`
width: ${({ size }) => `${size}px`};
height: ${({ size }) => `${size}px`};
background: ${({ backgroundColor }) => backgroundColor};
box-sizing: border-box;
padding: 6px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}`;

const ChatBotIcon = styled(Icon)`
const Icon = styled(BotProfileIcon)<{ fill: string }>`
path {
fill: ${({ theme }) => getColorBasedOnSaturation(theme.accentColor)};
fill: ${({ fill }) => fill};
}
`;
const StyledBotIcon = styled(ChatBotIcon).attrs(({ width, height }) => ({
width,
height,
}))``;

function BotProfileImage(props: ImageProps) {
type Props = {
profileUrl?: string;
size: number;
};

function BotProfileImage({ size, profileUrl }: Props) {
const theme = useTheme();

if (profileUrl) {
return <img src={profileUrl} style={{ borderRadius: '50%', width: size, height: size }} alt={'bot profile'} />;
}

return (
<StyledBotImage {...props}>
<StyledBotIcon width={props.iconWidth} height={props.iconHeight} />
</StyledBotImage>
<Container size={size} backgroundColor={theme.accentColor}>
<Icon fill={getColorBasedOnSaturation(theme.accentColor)} />
</Container>
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/CurrentUserMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const Root = styled.div<{ enableEmojiFeedback: boolean }>`
display: flex;
justify-content: flex-end;
align-items: end;
margin-bottom: 6px;
gap: 4px;
margin-top: ${({ enableEmojiFeedback }) => (enableEmojiFeedback ? '16px' : '0')};
`;

type Props = {
Expand Down
Loading

0 comments on commit 3fc3551

Please sign in to comment.