Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
639bb24
Update Prompt.ts
barnesrj Apr 12, 2025
c674354
Create get-tab-url.ts
barnesrj Apr 12, 2025
38a2e64
Create get-tab-url.ts
barnesrj Apr 12, 2025
b5f3e32
Update popup.tsx
barnesrj Apr 12, 2025
c5ff347
Update Prompt.ts
barnesrj Apr 12, 2025
5799a04
Update get-tab-url.ts
barnesrj Apr 14, 2025
3402373
Update popup.tsx
barnesrj Apr 14, 2025
f737dcb
Update popup.tsx
barnesrj Apr 14, 2025
e5653e4
Delete prompt-manager/utils/get-tab-url.ts
barnesrj Apr 14, 2025
d758af1
Delete prompt-manager/utils/prompt-manager/utils/get-tab-url.ts
barnesrj Apr 14, 2025
e837e15
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 14, 2025
bd64f51
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
panda Apr 18, 2025
d7100e9
Update usePrompts.test.ts
barnesrj Apr 18, 2025
94d3e71
Update PromptList.test.tsx
barnesrj Apr 18, 2025
75056cd
Update usePrompts.test.ts
barnesrj Apr 18, 2025
021f0ed
Update usePrompts.test.ts
barnesrj Apr 18, 2025
4aeb2d9
Update promptUtils.test.ts
barnesrj Apr 18, 2025
1cea80f
Update PromptList.test.tsx
barnesrj Apr 18, 2025
2563d4c
Update PromptListItem.test.tsx
barnesrj Apr 18, 2025
f62c975
Update Prompt.ts
barnesrj Apr 18, 2025
951de6d
Update Prompt.ts
barnesrj Apr 18, 2025
7ad7508
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 19, 2025
5f0642e
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 19, 2025
c4a3d91
Update promptUtils.ts
barnesrj Apr 19, 2025
8a9f399
Merge branch 'dev' into 32-store-timestamps-and-platform-usage-for-ea…
barnesrj Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions prompt-manager/interface/Prompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface Prompt {
title: string;
prompt: string;
tags: string[];
category?: string;
}
title: string;
prompt: string;
tags: string[];
category?: string;
createdAt: Date;
website: string;
}
35 changes: 24 additions & 11 deletions prompt-manager/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { usePrompts } from "~hooks/usePrompts"
import { ImportBtn } from "~components/ImportBtn";
import { ExportBtn } from "~components/ExportBtn";


function IndexPopup() {
const { prompts, setPrompts } = usePrompts();
const [userInput, setUserInput] = useState("")
Expand All @@ -25,19 +26,31 @@ function IndexPopup() {
}
}, [prompts])

const savePrompt = () => {
if (userInput.trim() !== "") {
const newPrompt: Prompt = {
title: "",
tags: [],
prompt: userInput,
category: currentCategory
}
const savePrompt = async () => {
if (userInput.trim() !== "") {
let website = ""

try {
website = await useCurrentTabUrl()
} catch (err) {
console.error("Could not get tab URL:", err)
website = "unknown"
}

setPrompts((existingPrompts) => [...existingPrompts, newPrompt])
setUserInput("")
const newPrompt: Prompt = {
title: "",
tags: [],
prompt: userInput,
category: currentCategory,
createdAt: new Date(),
website
}

setPrompts((existingPrompts) => [...existingPrompts, newPrompt])
setUserInput("")
}
}


const createNewCategory = () => {
if (newCategory.trim() !== "" && !categories.includes(newCategory)) {
Expand Down Expand Up @@ -171,4 +184,4 @@ function IndexPopup() {
)
}

export default IndexPopup
export default IndexPopup
12 changes: 9 additions & 3 deletions prompt-manager/tests/components/PromptList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ const mockPromptListData: Prompt[] = [
{
title: "Sample Prompt",
prompt: "This is a sample prompt description.",
tags: ["Test Tag"]
tags: ["Test Tag"],
createdAt: new Date(),
website: "https://chatgpt.com/"
},
{
title: "Another Prompt",
prompt: "This is another sample prompt description.",
tags: ["Another Tag"]
tags: ["Another Tag"],
createdAt: new Date(),
website: "https://chatgpt.com/"
},
{
title: "Searchable Prompt",
prompt: "This prompt is meant to be found.",
tags: ["Search Tag"]
tags: ["Search Tag"],
createdAt: new Date(),
website: "https://chatgpt.com/"
}
];

Expand Down
2 changes: 2 additions & 0 deletions prompt-manager/tests/components/PromptListItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const mockPrompt: Prompt = {
title: "Test Prompt",
prompt: "This is a test prompt description.",
tags: ["Tag1", "Tag2"],
createdAt: new Date(),
website: "https://chatgpt.com/"
};

describe("PromptListItem", () => {
Expand Down
9 changes: 7 additions & 2 deletions prompt-manager/tests/hooks/usePrompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jest.mock("@plasmohq/storage/hook", () => ({
useStorage: jest.fn()
}))

const newPrompt = { title: "Test Title", prompt: "Test Prompt", tags: [] }
const newPrompt = { title: "Test Title", prompt: "Test Prompt", tags: [], createdAt: new Date(),
website: "https://chatgpt.com/" }

describe("usePrompts", () => {
it("should return an empty array as the initial value for prompts", () => {
Expand All @@ -26,7 +27,11 @@ describe("usePrompts", () => {

it("should return the stored prompts from the list if they exist", () => {
const mockPrompts: Prompt[] = [
{ title: "Test Title", prompt: "Test Prompt", tags: [] }
{ title: "Test Title",
prompt: "Test Prompt",
tags: [],
createdAt: new Date(),
website: "https://chatgpt.com/" }
]
const mockUseStorage = jest.fn(() => [mockPrompts, jest.fn()])
;(useStorage as jest.Mock).mockImplementation(mockUseStorage)
Expand Down
8 changes: 5 additions & 3 deletions prompt-manager/tests/utils/promptUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { Prompt } from "~interface/Prompt";

describe("promptUtils", () => {
const mockPrompts: Prompt[] = [
{ title: "Test Prompt", prompt: "This is a test prompt.", tags: ["Tag1"] },
{ title: "Another Prompt", prompt: "This is another test prompt.", tags: ["Tag2"] },
{ title: "Test Prompt", prompt: "This is a test prompt.", tags: ["Tag1"], createdAt: new Date(),
website: "https://chatgpt.com/" },
{ title: "Another Prompt", prompt: "This is another test prompt.", tags: ["Tag2"], createdAt: new Date(),
website: "https://chatgpt.com/" },
];

beforeEach(() => {
Expand Down Expand Up @@ -52,4 +54,4 @@ describe("promptUtils", () => {
expect(mockClick).toHaveBeenCalledTimes(1);
expect(mockRevokeObjectURL).toHaveBeenCalledWith(mockCreateObjectURL.mock.results[0].value);
});
});
});
8 changes: 6 additions & 2 deletions prompt-manager/utils/promptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export function importPrompts(file: File): Promise<Prompt[]> {
reader.onload = (event) => {
try {
const result = event.target?.result as string;
const importedPrompts: Prompt[] = JSON.parse(result);
const rawPrompts = JSON.parse(result);
const importedPrompts: Prompt[] = rawPrompts.map((p: any) => ({
...p,
createdAt: new Date(p.createdAt)
}));
resolve(importedPrompts);
} catch (error) {
reject(new Error("Invalid JSON file"));
Expand All @@ -43,4 +47,4 @@ export function importPrompts(file: File): Promise<Prompt[]> {

reader.readAsText(file);
});
}
}