- Notifications
You must be signed in to change notification settings - Fork0
[I2 27] Olliebot#64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
TR-04 wants to merge2 commits intomasterChoose a base branch fromI2-27/olliebot
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
156 changes: 156 additions & 0 deletionsfrontend/src/components/Olliebot.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import React, { useState } from 'react'; | ||
| import { MessageCircle, X, ChevronDown, ChevronUp, HelpCircle } from 'lucide-react'; | ||
| const Olliebot = () => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [showFaqs, setShowFaqs] = useState(true); | ||
| const toggleChat = () => { | ||
| setIsOpen(!isOpen); | ||
| }; | ||
| const toggleFaqs = () => { | ||
| setShowFaqs(!showFaqs); | ||
| }; | ||
| interface Message { | ||
| id: string; | ||
| text: string; | ||
| isUser: boolean; | ||
| } | ||
| interface FaqItem { | ||
| id: string; | ||
| question: string; | ||
| answer: string; | ||
| } | ||
| // All new messages are added here | ||
| const [messages, setMessages] = useState<Message[]>([ | ||
| { id: '1', text: "Hi! What can I help you with today?", isUser: false } | ||
| ]); | ||
| // Mapping? Similar to how freerooms was done for search | ||
| const FaqItems: FaqItem[] = [ | ||
| { | ||
| id: "1", | ||
| question: "What is CSESoc?", | ||
| answer: "We're one of the largest computing societies in the southern hemisphere! Whether you're looking to improve your tech skills, network with like-minded peers, or explore career opportunities, CSESoc offers valuable resources and experiences for computer science and engineering students.", | ||
| }, | ||
| { | ||
| id: "2", | ||
| question: "How can I join CSESoc?", | ||
| answer: "Check our discord and website for updates! Spots open up every year :)", | ||
| }, | ||
| { | ||
| id: "3", | ||
| question: "What events do CSESoc run?", | ||
| answer: "We run events that range from fun social meetups to hackathons and training workshops. You can check out our full event listing at our facebook page and on discord announcements!", | ||
| }, | ||
| { | ||
| id: "4", | ||
| question: "Who's Ollie?", | ||
| answer: "That would be me! Wait, I'm actually a bot. Anyways, Ollie is CSESoc's ottersome little mascot!", | ||
| }, | ||
| ]; | ||
| const addMessage = (text: string, isUser: boolean) => { | ||
| const newMessage: Message = { | ||
| id: Date.now().toString(), | ||
| text, | ||
| isUser, | ||
| }; | ||
| {/*Update array, append new message atop previous*/} | ||
| setMessages(prevMessages => [...prevMessages, newMessage]); | ||
| }; | ||
| const handleFaqSelect = (faq: FaqItem) => { | ||
| addMessage(faq.question, true); | ||
| setTimeout(() => { | ||
| addMessage(faq.answer, false); | ||
| }, 500); | ||
| }; | ||
| return ( | ||
| <div className="fixed bottom-6 right-6 z-50"> | ||
| <div | ||
| className={`transition-all duration-300 ease-in-out flex flex-col shadow-2xl ${ | ||
| !isOpen | ||
| ? 'w-16 h-16 rounded-lg cursor-pointer bg-[#3977F8] hover:bg-blue-700' | ||
| : 'w-[420px] h-[520px] bg-white rounded-lg' | ||
| }`} | ||
| onClick={!isOpen ? toggleChat : undefined} | ||
| > | ||
| {!isOpen ? ( | ||
| <div className="flex items-center justify-center w-full h-full text-white"> | ||
| <MessageCircle size={24} /> | ||
| </div> | ||
| ) : ( | ||
| <> | ||
| <div className="bg-[#3977F8] text-white p-4 rounded-t-lg flex items-center justify-between"> | ||
| <div className="flex items-center gap-2"> | ||
| <MessageCircle size={20} /> | ||
| <span className="font-semibold">Olliebot</span> | ||
| </div> | ||
| <button className="text-white hover:text-gray-200" | ||
| onClick={toggleChat} | ||
| > | ||
| <X size={20} /> | ||
| </button> | ||
| </div> | ||
| {/* Messages */} | ||
| <div className="flex-1 p-4 overflow-y-auto space-y-3"> | ||
| {messages.map((message) => ( | ||
| <div | ||
| key={message.id} | ||
| className={`flex ${message.isUser ? 'justify-end' : 'justify-start'}`} | ||
| > | ||
| <div | ||
| className={`max-w-xs px-3 py-2 rounded-lg text-sm ${ | ||
| message.isUser | ||
| ? 'bg-[#3977F8] text-white rounded-br-none' | ||
| : 'bg-gray-100 text-gray-800 rounded-bl-none' | ||
| }`} | ||
| > | ||
| {message.text} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| {/* FAQs */} | ||
| <div className="border-t border-gray-200"> | ||
| <button | ||
| className="w-full p-3 flex items-center justify-between text-left bg-gray-50 hover:bg-gray-100 transition-colors" | ||
| onClick={toggleFaqs} | ||
| > | ||
| <div className="flex items-center gap-2"> | ||
| <HelpCircle size={16} className="text-[#3977F8]" /> | ||
| <span className="font-medium text-gray-700 text-sm">FAQs</span> | ||
| </div> | ||
| {showFaqs ? <ChevronUp size={16} className='text-gray-700'/> : <ChevronDown size={16} className='text-gray-700'/>} | ||
| </button> | ||
| {showFaqs && ( | ||
| <div className="p-3 space-y-2 max-h-[160px] overflow-y-auto bg-gray-50"> | ||
| {FaqItems.map((faq) => ( | ||
| <button | ||
| key={faq.id} | ||
| className="w-full text-left p-2 bg-white hover:bg-blue-50 hover:border-blue-200 rounded border border-gray-200 transition-colors" | ||
| onClick={() => handleFaqSelect(faq)} | ||
| > | ||
| <span className="text-sm text-gray-800">{faq.question}</span> | ||
| </button> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default Olliebot; |
3 changes: 3 additions & 0 deletionsfrontend/src/pages/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.