Skip to content

Commit

Permalink
fix: handle null ai user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
pnd280 committed Sep 29, 2024
1 parent 191d84f commit a51978a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"typescript.tsdk": "node_modules\\typescript\\lib",
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"workbench.editor.customLabels.patterns": {
"**/src/**/*.test.ts": "Test - ${dirname}: ${filename}",
"**/src/**": "${dirname}: ${filename}",
"**/src/**": "${dirname}: ${filename}"
},
"workbench.editor.labelFormat": "medium",
"search.exclude": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "complexity",
"displayName": "Complexity - Perplexity.ai supercharged",
"version": "0.0.3.8",
"version": "0.0.3.9",
"author": "pnd280",
"description": "⚡ Supercharge your Perplexity.ai",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ function UserProfileActions({
</div>
);

if (userAiProfile != null && !userAiProfile.has_profile) return;

return (
<div className="tw-absolute tw-right-0 tw-flex tw-h-full tw-w-full tw-items-center tw-justify-end tw-gap-1 tw-px-2 group-hover:tw-bg-gradient-to-r group-hover:tw-from-transparent group-hover:tw-to-secondary">
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function UserProfileEditDialog({
useEffect(() => {
if (userAiProfile) {
reset({
bio: userAiProfile.bio || "",
bio: userAiProfile.has_profile ? userAiProfile.bio : "",
});
}
}, [open, userAiProfile, reset]);
Expand Down
4 changes: 2 additions & 2 deletions src/types/pplx-api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as z from "zod";

import { LanguageModel } from "@/content-script/components/QueryBox";
import { Collection } from "@/types/collection.types";
import { UserAiProfile } from "@/types/user-ai-profile";
import { HasUserAiProfile, UserAiProfile } from "@/types/user-ai-profile";

export type SubscriptionStatus = "active" | "trialing" | "none";

Expand Down Expand Up @@ -51,4 +51,4 @@ export type ThreadMessageApiResponse = {

export type UserAiProfileApiResponse = UserAiProfile;

export type UpdateUserAiProfileApiRequest = Partial<UserAiProfileApiResponse>;
export type UpdateUserAiProfileApiRequest = Partial<HasUserAiProfile>;
17 changes: 15 additions & 2 deletions src/types/user-ai-profile.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import * as z from "zod";

export const UserAiProfileSchema = z.object({
has_profile: z.boolean(),
const HasUserAiProfileSchema = z.object({
has_profile: z.literal(true),
disabled: z.boolean(),
bio: z.string(),
});

export type HasUserAiProfile = z.infer<typeof HasUserAiProfileSchema>;

const NoUserAiProfileSchema = z.object({
has_profile: z.literal(false),
});

export type NoUserAiProfile = z.infer<typeof NoUserAiProfileSchema>;

export const UserAiProfileSchema = z.union([
HasUserAiProfileSchema,
NoUserAiProfileSchema,
]);

export type UserAiProfile = z.infer<typeof UserAiProfileSchema>;

0 comments on commit a51978a

Please sign in to comment.