Skip to content

Commit

Permalink
Create chat history with the title of the current active tab's URL ho…
Browse files Browse the repository at this point in the history
…stname if the current chat ID is the initial chat ID
  • Loading branch information
Royal-lobster committed Sep 24, 2023
1 parent 7ca8ba7 commit 9aac19a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/components/Sidebar/chat/ChatHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ const ChatHistory = () => {
useChatHistory();

const currentChat = getChatHistory(currentChatId);
console.log(currentChatId);
console.log(currentChat, history);

return (
<div>
<Select.Root>
<Select.Trigger className="cdx-border cdx-p-2 cdx-rounded-sm">
<Select.Trigger className="cdx-border cdx-border-neutral-500/20 cdx-flex cdx-gap-2 cdx-items-center cdx-py-2 cdx-px-3 cdx-text-sm cdx-text-neutral-700 dark:cdx-text-neutral-300 cdx-rounded-md">
<RiTimeLine /> {currentChat?.name}
</Select.Trigger>
<Select.Content>
Expand Down
44 changes: 22 additions & 22 deletions src/components/Sidebar/layout/header.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import { useEffect, useState } from 'react'
import { BsRobot } from 'react-icons/bs'
import { HiOutlineCog, HiX } from 'react-icons/hi'
import { useEffect, useState } from "react";
import { BsRobot } from "react-icons/bs";
import { HiOutlineCog, HiX } from "react-icons/hi";

const Header = () => {
const [shortcut, setShortcut] = useState<string | null>(null)
const [shortcut, setShortcut] = useState<string | null>(null);
const onToggle = () => {
chrome.runtime.sendMessage({ action: 'close-sidebar' })
}
chrome.runtime.sendMessage({ action: "close-sidebar" });
};

const settingsPage = chrome.runtime.getURL('/src/pages/settings/index.html')
const settingsPage = chrome.runtime.getURL("/src/pages/settings/index.html");

const handleModifyShortcut = () => {
chrome.tabs.update({ url: 'chrome://extensions/shortcuts' })
}
chrome.tabs.update({ url: "chrome://extensions/shortcuts" });
};

useEffect(() => {
chrome.commands.getAll((commands) => {
const command = commands.find(
(command) => command.name === 'open-sidebar',
)
if (command) setShortcut(command.shortcut || null)
})
}, [])
(command) => command.name === "open-sidebar"
);
if (command) setShortcut(command.shortcut || null);
});
}, []);

return (
<div className="cdx-flex cdx-justify-between cdx-p-3.5 cdx-border-b dark:cdx-border-neutral-700/50 cdx-border-neutral-200">
<div className="cdx-flex cdx-justify-between cdx-p-3.5 cdx-border-b dark:cdx-border-neutral-700/50 cdx-border-neutral-300">
<h1 className="cdx-text-2xl cdx-flex cdx-items-center cdx-gap-2 cdx-m-0 cdx-p-0">
<BsRobot className='cdx-text-blue-400' />
<BsRobot className="cdx-text-blue-400" />
Syncia
</h1>

<div className='cdx-flex cdx-text-neutral-500 cdx-gap-2 cdx-items-center'>
<div className="cdx-flex cdx-text-neutral-500 cdx-gap-2 cdx-items-center">
<button
onClick={handleModifyShortcut}
className="cdx-flex cdx-items-center cdx-gap-2"
>
<span className="cdx-text-xs cdx-text-neutral-500 dark:cdx-bg-black/20 cdx-bg-black/10 cdx-border cdx-rounded-full cdx-border-neutral-400/30 dark:cdx-border-neutral-500/50 cdx-px-2 cdx-py-0.5">
{shortcut ? `Shortcut: ${shortcut}` : 'No shortcut'}
{shortcut ? `Shortcut: ${shortcut}` : "No shortcut"}
</span>
</button>
<a
target='_blank'
target="_blank"
rel="noreferrer"
className="cdx-text-xl"
href={settingsPage}
Expand All @@ -52,7 +52,7 @@ const Header = () => {
</button>
</div>
</div>
)
}
);
};

export default Header
export default Header;
16 changes: 15 additions & 1 deletion src/hooks/useChatHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,23 @@ export const useChatHistory = () => {

return newId;
};
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const tab = tabs[0];
if (tab) {
console.log(tab);
}
});

if (currentChatId === initialChatId) {
createChatHistory("Default Chat");
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const tab = tabs[0] as any;
if (tab) {
const data = JSON.parse(tab.vivExtData);
const url = data.urlForThumbnail;
const title = new URL(url).hostname;
createChatHistory(title);
}
});
}

const deleteChatHistory = (id: string) => {
Expand Down

0 comments on commit 9aac19a

Please sign in to comment.