Skip to content

Commit

Permalink
Merge pull request #7 from SchickliCop/feature/ms/bug-fixes
Browse files Browse the repository at this point in the history
Fix Application Crash
  • Loading branch information
saoc90 authored Dec 13, 2024
2 parents 0b45707 + 36e889d commit e17dcef
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/features/chat-home-page/chat-home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const ChatHome: FC<ChatPersonaProps> = (props) => {
persona={persona}
key={persona.id}
showContextMenu={false}
showActionMenu={false}
/>
);
})}
Expand Down
3 changes: 2 additions & 1 deletion src/features/chat-page/chat-header/extension-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const ExtensionDetail: FC<Props> = (props) => {
<Sheet>
<SheetTrigger asChild>
<Button variant={"outline"} className="gap-2" disabled={props.disabled} aria-label="Current Chat Extensions Menu">
<PocketKnife size={16} /> {installedCount} ({totalCount})
<PocketKnife size={16} />
{installedCount > 0 ? `Installed ${installedCount}` : `Add Extensions (Available: ${totalCount})`}
</Button>
</SheetTrigger>
<SheetContent className="min-w-[480px] sm:w-[540px] flex flex-col">
Expand Down
2 changes: 1 addition & 1 deletion src/features/extensions-page/extension-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ExtensionPage: FC<Props> = (props) => {
<ScrollArea className="flex-1">
<main className="flex flex-1 flex-col">
<ExtensionHero />
<div className="container max-w-4xl py-3">
<div className="container max-w-4xl py-8">
<div className="grid grid-cols-3 gap-3">
{props.extensions.map((extension) => {
return (
Expand Down
20 changes: 16 additions & 4 deletions src/features/main-menu/main-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,36 @@ export const MainMenu = async () => {
</MenuLink>
</MenuItem>
<MenuItem tooltip="Persona">
<MenuLink href="/persona" ariaLabel="Go to the Persona configuration page">
<MenuLink
href="/persona"
ariaLabel="Go to the Persona configuration page"
>
<VenetianMask {...menuIconProps} />
</MenuLink>
</MenuItem>
<MenuItem tooltip="extensions">
<MenuLink href="/extensions" ariaLabel="Go to the Extensions configuration page">
<MenuLink
href="/extensions"
ariaLabel="Go to the Extensions configuration page"
>
<PocketKnife {...menuIconProps} />
</MenuLink>
</MenuItem>
<MenuItem tooltip="prompts">
<MenuLink href="/prompt" ariaLabel="Go to the Prompt Library configuration page">
<MenuLink
href="/prompt"
ariaLabel="Go to the Prompt Library configuration page"
>
<Book {...menuIconProps} />
</MenuLink>
</MenuItem>
{user.isAdmin && (
<>
<MenuItem tooltip="reporting">
<MenuLink href="/reporting" ariaLabel="Go to the Admin reporting" >
<MenuLink
href="/reporting"
ariaLabel="Go to the Admin reporting"
>
<Sheet {...menuIconProps} />
</MenuLink>
</MenuItem>
Expand Down
1 change: 1 addition & 0 deletions src/features/main-menu/menu-tray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const MenuTray = React.forwardRef<
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => {
const { isMenuOpen } = useMenuState();

return (
<div
ref={ref}
Expand Down
11 changes: 4 additions & 7 deletions src/features/persona-page/add-new-persona.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import { useSession } from "next-auth/react";
import { FC } from "react";
import { useFormState, useFormStatus } from "react-dom";
import { FC, useActionState } from "react";
import { useFormStatus } from "react-dom";
import { ServerActionResponse } from "../common/server-action-response";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
Expand Down Expand Up @@ -35,9 +35,9 @@ export const AddNewPersona: FC<Props> = (props) => {

const { isOpened, persona } = usePersonaState();

const [formState, formAction] = useFormState(
const [formState, formAction] = useActionState(
addOrUpdatePersona,
initialState
initialState,
);

const { data } = useSession();
Expand All @@ -55,8 +55,6 @@ export const AddNewPersona: FC<Props> = (props) => {
}
};

const store = personaStore;

return (
<Sheet
open={isOpened}
Expand All @@ -67,7 +65,6 @@ export const AddNewPersona: FC<Props> = (props) => {
<SheetContent className="min-w-[480px] sm:w-[540px] flex flex-col">
<SheetHeader>
<SheetTitle>Persona</SheetTitle>

</SheetHeader>
<form action={formAction} className="flex-1 flex flex-col">
<ScrollArea
Expand Down
3 changes: 2 additions & 1 deletion src/features/persona-page/persona-card/persona-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CopyToClipboardButton } from "./copy-to-clipboard-button";
interface Props {
persona: PersonaModel;
showContextMenu: boolean;
showActionMenu: boolean;
}

export const PersonaCard: FC<Props> = (props) => {
Expand All @@ -25,7 +26,7 @@ export const PersonaCard: FC<Props> = (props) => {
<Card key={persona.id} className="flex flex-col">
<CardHeader className="flex flex-row">
<CardTitle className="flex-1">{persona.name}</CardTitle>
{props.showContextMenu && (
{props.showActionMenu && (
<div>
<PersonaCardContextMenu persona={persona} />
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/features/persona-page/persona-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { PersonaCard } from "./persona-card/persona-card";
import { PersonaHero } from "./persona-hero/persona-hero";
import { PersonaModel } from "./persona-services/models";
import { ExtensionModel } from "../extensions-page/extension-services/models";
import { useSession } from "next-auth/react";
import { userHashedId } from "../auth-page/helpers";

interface ChatPersonaProps {
personas: PersonaModel[];
Expand All @@ -16,14 +18,15 @@ export const ChatPersonaPage: FC<ChatPersonaProps> = (props) => {
<ScrollArea className="flex-1">
<main className="flex flex-1 flex-col">
<PersonaHero />
<div className="container max-w-4xl py-3">
<div className="container max-w-4xl py-8">
<div className="grid grid-cols-3 gap-3">
{props.personas.map((persona) => {
{props.personas.map(async (persona) => {
return (
<PersonaCard
persona={persona}
key={persona.id}
showContextMenu
showActionMenu={persona.userId === await userHashedId()}
/>
);
})}
Expand Down
21 changes: 12 additions & 9 deletions src/features/persona-page/persona-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class PersonaState {
isPublished: false,
type: "PERSONA",
userId: "",
extensionIds: []
extensionIds: [],
};

public isOpened: boolean = false;
public errors: string[] = [];
public persona: PersonaModel = { ...this.defaultModel };

public addExtension(id: string): void{
public addExtension(id: string): void {
if (!this.persona.extensionIds) {
this.persona.extensionIds = [];
}
Expand All @@ -34,8 +34,10 @@ class PersonaState {
if (!this.persona.extensionIds) {
return;
}
this.persona.extensionIds = this.persona.extensionIds.filter((e) => e !== id);
};
this.persona.extensionIds = this.persona.extensionIds.filter(
(e) => e !== id
);
}

public updateOpened(value: boolean) {
this.isOpened = value;
Expand Down Expand Up @@ -81,10 +83,12 @@ export const usePersonaState = () => {
};

export const addOrUpdatePersona = async (previous: any, formData: FormData) => {
personaStore.updateErrors([]);

const model = FormDataToPersonaModel(formData);
model.extensionIds = personaStore.persona.extensionIds.map((e) => e);

if (personaStore.persona.extensionIds) {
model.extensionIds = personaStore.persona.extensionIds.map((e) => e);
}

const response =
model.id && model.id !== ""
? await UpsertPersona(model)
Expand All @@ -95,9 +99,8 @@ export const addOrUpdatePersona = async (previous: any, formData: FormData) => {
RevalidateCache({
page: "persona",
});
} else {
personaStore.updateErrors(response.errors.map((e) => e.message));
}

return response;
};

Expand Down
6 changes: 3 additions & 3 deletions src/features/prompt-page/add-new-prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
SheetTitle,
} from "@/ui/sheet";
import { useSession } from "next-auth/react";
import { FC } from "react";
import { useFormState, useFormStatus } from "react-dom";
import { FC, useActionState } from "react";
import { useFormStatus } from "react-dom";
import { ServerActionResponse } from "../common/server-action-response";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
Expand All @@ -26,7 +26,7 @@ export const AddPromptSlider: FC<SliderProps> = (props) => {

const { isOpened, prompt } = usePromptState();

const [formState, formAction] = useFormState(addOrUpdatePrompt, initialState);
const [formState, formAction] = useActionState(addOrUpdatePrompt, initialState);

const { data } = useSession();

Expand Down
2 changes: 1 addition & 1 deletion src/features/prompt-page/prompt-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ChatSamplePromptPage: FC<ChatSamplePromptProps> = async (
<ScrollArea className="flex-1">
<main className="flex flex-1 flex-col">
<PromptHero />
<div className="container max-w-4xl py-3">
<div className="container max-w-4xl py-8">
<div className="grid grid-cols-3 gap-3">
{promptsResponse.response.map((prompt) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/features/reporting-page/reporting-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function ReportingContent(props: ChatReportingProps) {
const chatThreads = chatHistoryResponse.response;
const hasMoreResults = chatThreads.length === SEARCH_PAGE_SIZE;
return (
<div className="container max-w-4xl py-3">
<div className="container max-w-4xl py-8">
<Table>
<TableHeader>
<TableRow>
Expand Down
2 changes: 1 addition & 1 deletion src/features/ui/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface HeroProps extends PropsWithChildren {

export const Hero: FC<HeroProps> = (props) => {
return (
<div className="border-b w-full pt-8">
<div className="border-b w-full pt-8 pb-4">
<div className="container max-w-4xl h-full flex flex-col gap-4">
<div className="flex gap-6 flex-col items-start">
<h1 className="text-4xl font-bold flex gap-2 items-center">
Expand Down
5 changes: 2 additions & 3 deletions src/features/ui/markdown/citation-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
SheetTitle,
SheetTrigger,
} from "@/ui/sheet";
import { FC } from "react";
import { useFormState } from "react-dom";
import { FC, useActionState } from "react";
import { ScrollArea } from "../scroll-area";
import { useMarkdownContext } from "./markdown-context";

Expand All @@ -22,7 +21,7 @@ export const CitationSlider: FC<SliderProps> = (props) => {

if (!onCitationClick) throw new Error("onCitationClick is null");

const [node, formAction] = useFormState(onCitationClick, null);
const [node, formAction] = useActionState(onCitationClick, null);

return (
<form>
Expand Down

0 comments on commit e17dcef

Please sign in to comment.