-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add prompt category selection (#1)
- Loading branch information
Showing
28 changed files
with
504 additions
and
132 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/chrome-extension/src/components/EnabledPrompts/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/// <reference types="chrome" /> | ||
import { Select, Space, Tag } from 'antd'; | ||
import type { CustomTagProps } from 'rc-select/lib/BaseSelect'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
const { Option } = Select; | ||
|
||
interface PromptCategory { | ||
name: string; | ||
emoji: string; | ||
} | ||
|
||
interface SelectPromptCategoriesProps { | ||
promptCategories: PromptCategory[]; | ||
} | ||
|
||
const colorOptions: Record<string, string> = { | ||
General: 'gold', | ||
Code: 'cyan', | ||
}; | ||
|
||
function SelectPromptCategories({ | ||
promptCategories, | ||
}: SelectPromptCategoriesProps) { | ||
const localStorageKey = 'enabledPromptCategories'; | ||
|
||
const [enabledPromptCategories, setEnabledPromptCategories] = useState< | ||
string[] | ||
>([]); | ||
|
||
useEffect(() => { | ||
chrome.storage.local.get( | ||
[localStorageKey], | ||
(result: { [x: string]: string }) => { | ||
if (result[localStorageKey]) { | ||
setEnabledPromptCategories(result[localStorageKey].split(',')); | ||
} | ||
} | ||
); | ||
}, []); | ||
|
||
const handleChange = async (values: string[]) => { | ||
setEnabledPromptCategories(values); | ||
await chrome.storage.local.set({ [localStorageKey]: values.join(',') }); | ||
}; | ||
|
||
const tagRender = (props: CustomTagProps) => { | ||
const { label, value, closable, onClose } = props; | ||
|
||
console.log(props); | ||
|
||
const onPreventMouseDown = (event: React.MouseEvent<HTMLSpanElement>) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}; | ||
return ( | ||
<Tag | ||
color={colorOptions[value]} | ||
onMouseDown={onPreventMouseDown} | ||
closable={closable} | ||
onClose={onClose} | ||
style={{ marginRight: 3 }} | ||
> | ||
{label} | ||
</Tag> | ||
); | ||
}; | ||
|
||
return ( | ||
<Select | ||
title="Select prompt types to enable" | ||
mode="multiple" | ||
style={{ width: '100%' }} | ||
placeholder="select prompt types to enable" | ||
value={enabledPromptCategories} | ||
onChange={handleChange} | ||
optionLabelProp="label" | ||
tagRender={tagRender} | ||
> | ||
{promptCategories | ||
.filter((o) => !enabledPromptCategories.includes(o.name)) | ||
.map((promptCategory) => ( | ||
<Option value={promptCategory.name} label={promptCategory.name}> | ||
<Space> | ||
<span role="img" aria-label={promptCategory.name}> | ||
{promptCategory.emoji} | ||
</span> | ||
{promptCategory.name} | ||
</Space> | ||
</Option> | ||
))} | ||
</Select> | ||
); | ||
} | ||
|
||
export default SelectPromptCategories; |
Oops, something went wrong.