Skip to content

Commit

Permalink
Merge branch 'chat-ui-revamp' into 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Viraj5903 committed Sep 2, 2024
2 parents f007233 + d8e35d9 commit 451533d
Show file tree
Hide file tree
Showing 51 changed files with 1,671 additions and 250 deletions.
8 changes: 4 additions & 4 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"projects": {
"default": "kai-ai-f63c8"
"default": "kai-ai-b8ac9"
},
"targets": {
"kai-ai-f63c8": {
"kai-ai-b8ac9": {
"hosting": {
"next": [
"kai-ai-f63c8"
"kai-ai-b8ac9"
]
}
}
},
"etags": {}
}
}
5 changes: 2 additions & 3 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2023, 6, 16);
match /chatSessions/{id} {
allow read, write: if request.auth != null && resource.data.user.id == request.auth.uid;
}
}
}
3 changes: 3 additions & 0 deletions frontend/assets/svg/ChatHistoryButtonIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions frontend/assets/svg/ChatIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions frontend/assets/svg/ChatIconFill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/assets/svg/DefaultPromptStar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/assets/svg/DiscoveryIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/assets/svg/HomeMenuIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/assets/svg/LogoutIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions frontend/assets/svg/PurpleStar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 27 additions & 1 deletion frontend/constants/bots.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const ACTION_TYPES = {
SUMMARIZE_CONTENT: {
actionType: 'Summarize Content',
description: 'Summarize key concepts and ideas for a given topic.',
},
GENERATE_QUIZ: {
actionType: 'Generate Quiz',
description: 'Create quiz on a given topic to test students understanding.',
},
ACTIVITY_RECOMMENDATIONS: {
actionType: 'Activity Recommendations',
description: 'Offer engaging activities based on the current subject.',
},
INTERACTIVE_TECHNIQUES: {
actionType: 'Interactive Techniques',
description:
'Suggest ideas for making lessons more interactive and engaging.',
},
};

const BOT_TYPE = {
MISSION: 'mission',
TEACH_ME: 'teach_me',
Expand All @@ -6,6 +26,12 @@ const BOT_TYPE = {
HACKATHON: 'hackathon',
};

const DEFAULT_PROMPTS = [
'Strategies to encourage student participation.',
'Design an engaging class activity.',
'Recommend resources for effective teaching.',
];

const MESSAGE_ROLE = {
SYSTEM: 'system',
HUMAN: 'human',
Expand All @@ -22,4 +48,4 @@ const MESSAGE_TYPES = {
QUICK_REPLY: 'quick_reply',
};

export { BOT_TYPE, MESSAGE_ROLE, MESSAGE_TYPES };
export { ACTION_TYPES, BOT_TYPE, DEFAULT_PROMPTS, MESSAGE_ROLE, MESSAGE_TYPES };
1 change: 1 addition & 0 deletions frontend/constants/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ROUTES = {
REDIRECT: '/redirect',
CHAT: '/chat',
HISTORY: '/history',
DISCOVERY: '/discovery',
};

export default ROUTES;
6 changes: 3 additions & 3 deletions frontend/layouts/AuthLayout/AuthLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ const AuthLayout = (props) => {
const renderArtifacts = () => {
return (
<>
<Box {...styles.reXProps}>
<Box {...styles.marvelProps}>
<Image
{...styles.reXImageProps}
{...styles.marvelImageProps}
src={ImageURLs.MarvelAuthImg}
alt="rexImage"
alt="Marvel Image"
/>
</Box>
<Box {...styles.greenBlobProps}>
Expand Down
4 changes: 2 additions & 2 deletions frontend/layouts/AuthLayout/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const styles = {
priority: true,
style: { zIndex: 0 },
},
reXImageProps: {
marvelImageProps: {
layout: 'fill',
objectFit: 'cover',
priority: true,
Expand Down Expand Up @@ -97,7 +97,7 @@ const styles = {
},
}),
},
reXProps: {
marvelProps: {
sx: (theme) => ({
position: 'absolute',
zIndex: 2,
Expand Down
4 changes: 2 additions & 2 deletions frontend/layouts/MainAppLayout/ MainAppLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useDispatch, useSelector } from 'react-redux';
import AppDisabled from '@/components/AppDisabled';
import Loader from '@/components/Loader';

import SideMenu from './SideMenu';
import NavBar from './NavBar';
import styles from './styles';

import { setLoading } from '@/redux/slices/authSlice';
Expand Down Expand Up @@ -52,7 +52,7 @@ const MainAppLayout = (props) => {
const renderApp = () => {
return (
<>
<SideMenu />
<NavBar />
<Grid {...styles.contentGridProps(extraContentProps, isToolPage)}>
{children}
</Grid>
Expand Down
171 changes: 171 additions & 0 deletions frontend/layouts/MainAppLayout/NavBar/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { Avatar, Button, Grid, Typography } from '@mui/material';
import { signOut } from 'firebase/auth';
import { useRouter } from 'next/router';

import { useSelector } from 'react-redux';

import ChatIcon from '@/assets/svg/ChatIcon.svg';
// import DiscoveryIcon from '@/assets/svg/DiscoveryIcon.svg';
import HomeIcon from '@/assets/svg/HomeMenuIcon.svg';
import LogoutIcon from '@/assets/svg/LogoutIcon.svg';

import ROUTES from '@/constants/routes';

import styles from './styles';

import { auth } from '@/redux/store';
import { chatRegex, discoveryRegex, homeRegex } from '@/regex/routes';

// TODO: Once Discovery Feature is ready, uncomment Discovery Page from below array.
const PAGES = [
{
name: 'Home',
link: ROUTES.HOME,
icon: <HomeIcon />,
id: 'home',
},
/* {
name: 'Discovery',
link: ROUTES.DISCOVERY,
icon: <DiscoveryIcon />,
id: 'discovery',
}, */
{
name: 'Chat',
link: ROUTES.CHAT,
icon: <ChatIcon />,
id: 'chat',
},
];

/**
* NavBar component renders the main navigation bar for the application.
* It includes the application logo, a navigation menu with dynamic active states,
* and a user profile section with the ability to sign out.
*
* @component
* @returns {JSX.Element} The navigation bar component.
*/
const NavBar = () => {
const router = useRouter();

const user = useSelector((state) => state.user.data);

/**
* Signs out the currently signed-in user from Firebase Authentication
* and redirects them to the sign-in page.
*
* @returns {void}
*/
const handleSignOutUser = () => {
signOut(auth);
};

/**
* Renders the logo of the application in the navbar.
* Clicking on the logo redirects the user to the home page.
*
* @returns {JSX.Element} The JSX element representing the logo section.
*/
const renderLogo = () => {
return (
<Grid {...styles.logoGridProps}>
<Grid onClick={() => router.push(ROUTES.HOME)} {...styles.logoImage}>
{/* TODO: Put Marvel AI logo here */}
<Typography {...styles.logoText}>Marvel AI</Typography>
</Grid>
<Typography {...styles.title}>AI Teaching Assistant</Typography>
</Grid>
);
};

/**
* Renders the profile section of the navbar, which includes the user's profile
* photo, name, and a logout button.
*
* @returns {JSX.Element} The profile section of the navbar.
*/
const renderProfile = () => {
return (
<Grid {...styles.profile}>
<Grid {...styles.userContainer}>
<Avatar src={user?.profilePhotoUrl} {...styles.userProfile}>
{user?.fullName[0]}
</Avatar>
<Typography {...styles.userName}>{user?.fullName}</Typography>
</Grid>
<Button startIcon={<LogoutIcon />} onClick={handleSignOutUser} />
</Grid>
);
};

/**
* Renders the navigation menu with dynamically set active states based on the current route.
*
* This function generates a grid-based navigation menu where each item reflects the current route's
* state. It highlights the active menu item and provides functionality to navigate to different routes
* when an item is clicked.
*
* @returns {JSX.Element} The navigation menu component with active states and clickable items.
*/
const renderNavMenu = () => {
const { pathname } = router;

/**
* Determines if a given menu item should be highlighted as active.
*
* @param {string} id - The identifier of the menu item to check.
* @returns {boolean} True if the menu item should be highlighted as active, otherwise false.
*/
const setActive = (id) => {
const isNotHomePage = [
chatRegex.test(pathname) || discoveryRegex.test(pathname),
].includes(true);

if (id === 'home')
return isNotHomePage ? false : homeRegex.test(pathname);

// TODO: Once Discovery Feature is ready, uncomment below statement.
// if (id === 'discovery') return discoveryRegex.test(pathname);

if (id === 'chat') return chatRegex.test(pathname);

return false;
};

/**
* Navigates to a specified route.
*
* @param {string} link - The route to navigate to.
* @returns {void}
*/
const handleRoute = (link) => {
router.push(link);
};

return (
<Grid {...styles.navMenu}>
{PAGES.map((page) => (
<Grid
key={page.id}
onClick={() => handleRoute(page.link, page.id)}
{...styles.navMenuItem(setActive(page.id))}
>
<Grid {...styles.navMenuIcon}>{page.icon}</Grid>
<Typography {...styles.navMenuText}>{page.name}</Typography>
</Grid>
))}
</Grid>
);
};

return (
<Grid {...styles.mainGrid}>
{renderLogo()}
{renderNavMenu()}
{renderProfile()}
</Grid>
);
};

export default NavBar;
1 change: 1 addition & 0 deletions frontend/layouts/MainAppLayout/NavBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Navbar';
Loading

0 comments on commit 451533d

Please sign in to comment.