ignore ctx is null early return
This commit is contained in:
@@ -28,7 +28,6 @@ interface ImageResponse {
|
|||||||
}
|
}
|
||||||
export function ImageGenDrawer({ disableFactor }: Props) {
|
export function ImageGenDrawer({ disableFactor }: Props) {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
|
|
||||||
const [showGenImage, setShowGenImage] = useState(false);
|
const [showGenImage, setShowGenImage] = useState(false);
|
||||||
const [imageGenPrompt, setImageGenPrompt] = useState("");
|
const [imageGenPrompt, setImageGenPrompt] = useState("");
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ interface Props {
|
|||||||
}
|
}
|
||||||
export function ImageUploadDrawer({ setImages, images, disableFactor }: Props) {
|
export function ImageUploadDrawer({ setImages, images, disableFactor }: Props) {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const [showAddImage, setShowAddImage] = useState(false);
|
const [showAddImage, setShowAddImage] = useState(false);
|
||||||
const [enableHighResolution, setEnableHighResolution] = useState(true);
|
const [enableHighResolution, setEnableHighResolution] = useState(true);
|
||||||
useState("b64_json");
|
useState("b64_json");
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ function APIsDropdownList({
|
|||||||
|
|
||||||
function ToolsDropdownList() {
|
function ToolsDropdownList() {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
|
|
||||||
@@ -189,7 +188,6 @@ function ToolsDropdownList() {
|
|||||||
|
|
||||||
function ChatTemplateDropdownList() {
|
function ChatTemplateDropdownList() {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
|
|
||||||
const { chatStore, setChatStore, templates } = ctx;
|
const { chatStore, setChatStore, templates } = ctx;
|
||||||
|
|
||||||
@@ -237,7 +235,6 @@ function ChatTemplateDropdownList() {
|
|||||||
|
|
||||||
const APIListMenu: React.FC = () => {
|
const APIListMenu: React.FC = () => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col m-2 gap-2 w-full">
|
<div className="flex flex-col m-2 gap-2 w-full">
|
||||||
{ctx.templateTools.length > 0 && <ToolsDropdownList />}
|
{ctx.templateTools.length > 0 && <ToolsDropdownList />}
|
||||||
|
|||||||
@@ -172,7 +172,6 @@ export function TTSPlay(props: TTSPlayProps) {
|
|||||||
function TTSButton(props: TTSProps) {
|
function TTSButton(props: TTSProps) {
|
||||||
const [generating, setGenerating] = useState(false);
|
const [generating, setGenerating] = useState(false);
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -237,7 +236,6 @@ function TTSButton(props: TTSProps) {
|
|||||||
|
|
||||||
export default function Message(props: { messageIndex: number }) {
|
export default function Message(props: { messageIndex: number }) {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const { messageIndex } = props;
|
const { messageIndex } = props;
|
||||||
const { chatStore, setChatStore } = ctx;
|
const { chatStore, setChatStore } = ctx;
|
||||||
|
|
||||||
@@ -303,7 +301,8 @@ export default function Message(props: { messageIndex: number }) {
|
|||||||
<Markdown>{getMessageText(chat)}</Markdown>
|
<Markdown>{getMessageText(chat)}</Markdown>
|
||||||
) : (
|
) : (
|
||||||
<div className="message-content">
|
<div className="message-content">
|
||||||
{chat.content &&
|
{ctx &&
|
||||||
|
chat.content &&
|
||||||
(chat.logprobs && renderColor
|
(chat.logprobs && renderColor
|
||||||
? chat.logprobs.content
|
? chat.logprobs.content
|
||||||
.filter((c) => c.token)
|
.filter((c) => c.token)
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ interface ChatStoreSearchResult {
|
|||||||
|
|
||||||
export default function Search() {
|
export default function Search() {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const { setSelectedChatIndex, db } = ctx;
|
const { setSelectedChatIndex, db } = ctx;
|
||||||
|
|
||||||
const [searchResult, setSearchResult] = useState<ChatStoreSearchResult[]>([]);
|
const [searchResult, setSearchResult] = useState<ChatStoreSearchResult[]>([]);
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ const Help = (props: { children: any; help: string; field: string }) => {
|
|||||||
|
|
||||||
const SelectModel = (props: { help: string }) => {
|
const SelectModel = (props: { help: string }) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
|
|
||||||
let shouldIUseCustomModel: boolean = true;
|
let shouldIUseCustomModel: boolean = true;
|
||||||
for (const model in models) {
|
for (const model in models) {
|
||||||
@@ -184,7 +183,6 @@ const LongInput = (props: {
|
|||||||
help: string;
|
help: string;
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="name" className="text-right">
|
<Label htmlFor="name" className="text-right">
|
||||||
@@ -233,7 +231,6 @@ const InputField = (props: {
|
|||||||
help: string;
|
help: string;
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const [hideInput, setHideInput] = useState(true);
|
const [hideInput, setHideInput] = useState(true);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -289,7 +286,6 @@ const Slicer = (props: {
|
|||||||
max: number;
|
max: number;
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const enable_filed_name: "temperature_enabled" | "top_p_enabled" =
|
const enable_filed_name: "temperature_enabled" | "top_p_enabled" =
|
||||||
`${props.field}_enabled` as any;
|
`${props.field}_enabled` as any;
|
||||||
|
|
||||||
@@ -380,7 +376,6 @@ const Number = (props: {
|
|||||||
help: string;
|
help: string;
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label className="flex items-center gap-2">
|
<Label className="flex items-center gap-2">
|
||||||
@@ -436,7 +431,6 @@ const Choice = (props: {
|
|||||||
help: string;
|
help: string;
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
@@ -627,7 +621,6 @@ const ToolsShowBlock = (props: {
|
|||||||
|
|
||||||
export default (props: {}) => {
|
export default (props: {}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
|
|
||||||
let link =
|
let link =
|
||||||
location.protocol +
|
location.protocol +
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { useContext } from "react";
|
|||||||
|
|
||||||
const Templates = () => {
|
const Templates = () => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const { templates, chatStore, setChatStore, setTemplates } = ctx;
|
const { templates, chatStore, setChatStore, setTemplates } = ctx;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { AppContext } from "@/pages/App";
|
|||||||
|
|
||||||
const VersionHint = () => {
|
const VersionHint = () => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
|
|
||||||
const { chatStore } = ctx;
|
const { chatStore } = ctx;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ const WhisperButton = (props: {
|
|||||||
setInputMsg: Dispatch<string>;
|
setInputMsg: Dispatch<string>;
|
||||||
}) => {
|
}) => {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
const { chatStore } = ctx;
|
const { chatStore } = ctx;
|
||||||
|
|
||||||
const { inputMsg, setInputMsg } = props;
|
const { inputMsg, setInputMsg } = props;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ interface EditMessageProps {
|
|||||||
}
|
}
|
||||||
export function EditMessage(props: EditMessageProps) {
|
export function EditMessage(props: EditMessageProps) {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
|
|
||||||
const { showEdit, setShowEdit, chat } = props;
|
const { showEdit, setShowEdit, chat } = props;
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ interface Props {
|
|||||||
}
|
}
|
||||||
export function EditMessageDetail({ chat, setShowEdit }: Props) {
|
export function EditMessageDetail({ chat, setShowEdit }: Props) {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
|
|
||||||
const { chatStore, setChatStore } = ctx;
|
const { chatStore, setChatStore } = ctx;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ interface Props {
|
|||||||
}
|
}
|
||||||
export function EditMessageString({ chat, setShowEdit }: Props) {
|
export function EditMessageString({ chat, setShowEdit }: Props) {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (!ctx) return <div>error</div>;
|
|
||||||
|
|
||||||
const { chatStore, setChatStore } = ctx;
|
const { chatStore, setChatStore } = ctx;
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ interface AppContextType {
|
|||||||
setTemplateTools: (t: TemplateTools[]) => void;
|
setTemplateTools: (t: TemplateTools[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AppContext = createContext<AppContextType | null>(null);
|
export const AppContext = createContext<AppContextType>(null as any);
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import { ImageGenDrawer } from "@/components/ImageGenDrawer";
|
|||||||
|
|
||||||
export default function ChatBOX() {
|
export default function ChatBOX() {
|
||||||
const ctx = useContext(AppContext);
|
const ctx = useContext(AppContext);
|
||||||
if (ctx === null) return <></>;
|
|
||||||
const {
|
const {
|
||||||
db,
|
db,
|
||||||
chatStore,
|
chatStore,
|
||||||
@@ -54,7 +53,6 @@ export default function ChatBOX() {
|
|||||||
setSelectedChatIndex,
|
setSelectedChatIndex,
|
||||||
} = ctx;
|
} = ctx;
|
||||||
// prevent error
|
// prevent error
|
||||||
if (chatStore === undefined) return <div></div>;
|
|
||||||
const [inputMsg, setInputMsg] = useState("");
|
const [inputMsg, setInputMsg] = useState("");
|
||||||
const [images, setImages] = useState<MessageDetail[]>([]);
|
const [images, setImages] = useState<MessageDetail[]>([]);
|
||||||
const [showAddImage, setShowAddImage] = useState(false);
|
const [showAddImage, setShowAddImage] = useState(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user