fix: agent info not updating when switching routes
This commit is contained in:
@@ -3,7 +3,8 @@ const route = useRoute();
|
|||||||
const { agents, getAgent } = useAgents();
|
const { agents, getAgent } = useAgents();
|
||||||
const { openDropdown, dropdownState, closeDropdown } = useDropdown();
|
const { openDropdown, dropdownState, closeDropdown } = useDropdown();
|
||||||
|
|
||||||
const activeAgent = getAgent(route.params.id as string);
|
const agentId = computed(() => route.params.id as string);
|
||||||
|
const activeAgent = getAgent(agentId);
|
||||||
|
|
||||||
const { isHovered } = useSidenavContext();
|
const { isHovered } = useSidenavContext();
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ const { getAgent } = useAgents();
|
|||||||
const triplit = useTriplitClient();
|
const triplit = useTriplitClient();
|
||||||
|
|
||||||
const navRef = ref<HTMLElement | null>(null);
|
const navRef = ref<HTMLElement | null>(null);
|
||||||
const activeAgent = getAgent(route.params.id as string);
|
const agentId = computed(() => route.params.id as string);
|
||||||
watch(() => route.params.id, () => {
|
|
||||||
|
console.log(agentId.value);
|
||||||
|
const activeAgent = getAgent(agentId);
|
||||||
|
watch(agentId, () => {
|
||||||
if (navRef.value) {
|
if (navRef.value) {
|
||||||
navRef.value.scrollTo({ top: 0, behavior: 'instant' });
|
navRef.value.scrollTo({ top: 0, behavior: 'instant' });
|
||||||
}
|
}
|
||||||
@@ -25,7 +28,7 @@ let activeAutoRenames = reactive(new Map<string, string>());
|
|||||||
|
|
||||||
const autoRenameTopic = async (topicId: string) => {
|
const autoRenameTopic = async (topicId: string) => {
|
||||||
const { setPage } = useSettings();
|
const { setPage } = useSettings();
|
||||||
const { autoRename, AutoRenameError } = useChat(route.params.id as string);
|
const { autoRename, AutoRenameError } = useChat(agentId.value);
|
||||||
|
|
||||||
const firstMessage = await triplit.fetchOne(triplit.query('messages').Where('topicId', '=', topicId).Order('createdAt', 'ASC').Limit(1));
|
const firstMessage = await triplit.fetchOne(triplit.query('messages').Where('topicId', '=', topicId).Order('createdAt', 'ASC').Limit(1));
|
||||||
if (!firstMessage) return;
|
if (!firstMessage) return;
|
||||||
@@ -106,8 +109,8 @@ const cancelRename = () => {
|
|||||||
|
|
||||||
const deleteTopic = async (topicId: string) => {
|
const deleteTopic = async (topicId: string) => {
|
||||||
if (route.params.topicId === topicId) {
|
if (route.params.topicId === topicId) {
|
||||||
if (route.params.id) {
|
if (agentId.value) {
|
||||||
await navigateTo(`/agent/${route.params.id}`);
|
await navigateTo(`/agent/${agentId.value}`);
|
||||||
} else {
|
} else {
|
||||||
await navigateTo('/');
|
await navigateTo('/');
|
||||||
}
|
}
|
||||||
@@ -129,7 +132,7 @@ const handleNavClick = (e: MouseEvent) => {
|
|||||||
case 'navigate':
|
case 'navigate':
|
||||||
if (e.metaKey || e.ctrlKey || e.shiftKey) return;
|
if (e.metaKey || e.ctrlKey || e.shiftKey) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return navigateTo(`/agent/${route.params.id}/topic/${topicId}`);
|
return navigateTo(`/agent/${agentId.value}/topic/${topicId}`);
|
||||||
|
|
||||||
case 'toggle-dropdown':
|
case 'toggle-dropdown':
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -157,7 +160,7 @@ const handleNavClick = (e: MouseEvent) => {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// simply preload the topic page
|
// simply preload the topic page
|
||||||
preloadRouteComponents(`/agent/${route.params.id}/topic/42`);
|
preloadRouteComponents(`/agent/${agentId.value}/topic/42`);
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -167,7 +170,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
<!-- Agent Info Link -->
|
<!-- Agent Info Link -->
|
||||||
<div class="mt-2 flex flex-col">
|
<div class="mt-2 flex flex-col">
|
||||||
<SidenavItem :to="`/agent/${route.params.id}/profile`" name="Agent Info" icon="mynaui:info-square"
|
<SidenavItem :to="`/agent/${agentId}/profile`" name="Agent Info" icon="mynaui:info-square"
|
||||||
:active="route.path.endsWith('/profile')" />
|
:active="route.path.endsWith('/profile')" />
|
||||||
|
|
||||||
<!-- Topics Section -->
|
<!-- Topics Section -->
|
||||||
@@ -183,7 +186,7 @@ onMounted(() => {
|
|||||||
:item-size="40" :overscan="20">
|
:item-size="40" :overscan="20">
|
||||||
<template v-slot="{ item: topic }">
|
<template v-slot="{ item: topic }">
|
||||||
<a :key="topic.id" data-action="navigate" :data-topic-id="topic.id"
|
<a :key="topic.id" data-action="navigate" :data-topic-id="topic.id"
|
||||||
:href="`/agent/${route.params.id}/topic/${topic.id}`" :aria-label="topic.name"
|
:href="`/agent/${agentId}/topic/${topic.id}`" :aria-label="topic.name"
|
||||||
class="mt-1 group px-2 decoration-none flex justify-between items-center shrink-0 rounded-lg transition-colors cursor-pointer h-9 text-[var(--text-secondary)] hover:bg-[var(--color-hover)] focus-visible:bg-[var(--color-hover)] focus:text-[var(--text-primary)]"
|
class="mt-1 group px-2 decoration-none flex justify-between items-center shrink-0 rounded-lg transition-colors cursor-pointer h-9 text-[var(--text-secondary)] hover:bg-[var(--color-hover)] focus-visible:bg-[var(--color-hover)] focus:text-[var(--text-primary)]"
|
||||||
:class="{ 'bg-[var(--color-hover)]': route.params.topicId === topic.id }">
|
:class="{ 'bg-[var(--color-hover)]': route.params.topicId === topic.id }">
|
||||||
<input v-if="renameTopicId === topic.id && !topic.renaming" id="topic-rename-input"
|
<input v-if="renameTopicId === topic.id && !topic.renaming" id="topic-rename-input"
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export const useAgents = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getAgent = (id: MaybeRef<string>) => {
|
const getAgent = (id: MaybeRef<string>) => {
|
||||||
return computed(() => state.list.value.find((agent) => agent.id === id) || null);
|
return computed(() => state.list.value.find((agent) => agent.id === toRef(id).value) || null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createAgent = async () => {
|
const createAgent = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user