feat: add pin/unpin functionality to chat history

Adds pin/unpin functionality to the chat history sidebar, allowing users to keep important conversations readily accessible. This improves user experience and helps organize past interactions.

This feature includes:
- Pin/unpin buttons in the chat history sidebar.
- Updated database schema to include `is_pinned` field for chat history items.
- Localized translations for pin/unpin actions.
- Updated UI to display pinned items at the top of the list.
This commit is contained in:
n4ze3m
2024-10-26 21:10:28 +05:30
parent f01f9d0482
commit d5df8b5c5f
29 changed files with 326 additions and 113 deletions

View File

@@ -8,6 +8,7 @@ type HistoryInfo = {
title: string
is_rag: boolean
message_source?: "copilot" | "web-ui"
is_pinned?: boolean
createdAt: number
}
@@ -232,7 +233,11 @@ export const generateID = () => {
})
}
export const saveHistory = async (title: string, is_rag?: boolean, message_source?: "copilot" | "web-ui") => {
export const saveHistory = async (
title: string,
is_rag?: boolean,
message_source?: "copilot" | "web-ui"
) => {
const id = generateID()
const createdAt = Date.now()
const history = { id, title, createdAt, is_rag, message_source }
@@ -317,6 +322,18 @@ export const updateHistory = async (id: string, title: string) => {
db.db.set({ chatHistories: newChatHistories })
}
export const pinHistory = async (id: string, is_pinned: boolean) => {
const db = new PageAssitDatabase()
const chatHistories = await db.getChatHistories()
const newChatHistories = chatHistories.map((history) => {
if (history.id === id) {
history.is_pinned = is_pinned
}
return history
})
db.db.set({ chatHistories: newChatHistories })
}
export const removeMessageUsingHistoryId = async (history_id: string) => {
const db = new PageAssitDatabase()
const chatHistory = await db.getChatHistory(history_id)
@@ -490,9 +507,8 @@ export const getRecentChatFromCopilot = async () => {
return { history, messages }
}
export const getTitleById = async (id: string) => {
const db = new PageAssitDatabase()
const title = await db.getChatHistoryTitleById(id)
return title
}
}