Skip to content

Commit

Permalink
keyword generation and ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
auraticabhi committed Apr 2, 2024
1 parent dccc742 commit 289b613
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/[postTitle]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const PostPage = ({ params: { postTitle } }: Props) => {
const [imageUrl, setImageUrl] = useState<string | null>(null);
const [progress , setProgress] = useState<number | null>(0);
const [ansLoading, setAnsLoading] = useState(false);
const [isFocused, setIsFocused] = useState(false);

//need the actual postId of the question to send to the PostVoteClient
const [postId , setPostId] = useState<string>("");
Expand Down Expand Up @@ -383,13 +384,18 @@ const PostPage = ({ params: { postTitle } }: Props) => {
render={({ field }) => (
<FormItem>
{/* <FormLabel>Write an answer...</FormLabel> */}
<FormLabel>Description</FormLabel>
<div className={`${isFocused?"border-black border-[2.3px]": "border-[2px] border-[#d3d7dd]"} rounded-lg`} onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
>
<FormControl>
<Controller
control={form.control}
name="description"
render={({ field }) => <Tiptap {...field} setImageUpload={setImageUpload} uploadImage={uploadImage} progress={progress}/>}
/>
</FormControl>
</div>
<FormMessage />
</FormItem>
)}
Expand Down
7 changes: 5 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default function Home() {
const [previewImg, setPreviewImg] = useState<any>(null);
const [selectC, setSelectC] = useState<any>([]);
const [onFirstVisit, setOnFirstVisit] = useState(false);
const [isFocused, setIsFocused] = useState(false);

const [selectedCategory, setSelectedCategory] = useState<string | undefined>('');

Expand Down Expand Up @@ -338,7 +339,7 @@ export default function Home() {
try {
console.log("keyword Gen.....")
const docRef = await addDoc(collection(db, 'keywords'), {
prompt: `Generate some keywords and hashtags on topic ${data.title} and give it to me in array format without any formatting marks`,
prompt: `Generate some keywords and hashtags on topic ${data.title} and give it to me in "**Keywords:**["Keyword1", "Keyword2",...] **Hashtags:**["Hashtag1", "Hashtag2",...]" this format`,
});
console.log('Keyword Document written with ID: ', docRef.id);

Expand Down Expand Up @@ -541,7 +542,9 @@ export default function Home() {
render = {({field}) => (
<FormItem>
<FormLabel>Description</FormLabel>
<div className="border-2 border-black">
<div className={`${isFocused?"border-black border-[2.1px]": "border-[1.2px]"} rounded-lg`} onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
>
<FormControl>
<Controller
control={form.control}
Expand Down
21 changes: 18 additions & 3 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const Navbar = ({}: Props) => {
const [limitCount, setLimitCount] = useState(6); // Number of notifications to fetch at a time
const [lastVisible, setLastVisible] = useState<any>(null);
const [showLoadMoreButton , setShowLoadMoreButton] = useState(true);
const [isFocused, setIsFocused] = useState(false);

//for algolia search
const dispatch = useDispatch();
Expand Down Expand Up @@ -248,7 +249,7 @@ const Navbar = ({}: Props) => {
try {
console.log("keyword Gen.....")
const docRef = await addDoc(collection(db, 'keywords'), {
prompt: `Generate some keywords and hashtags on topic ${data.title}`,
prompt: `Generate some keywords and hashtags on topic ${data.title} and give it to me in "**Keywords:**["Keyword1", "Keyword2",...] **Hashtags:**["Hashtag1", "Hashtag2",...]" this format`,
});
console.log('Keyword Document written with ID: ', docRef.id);

Expand All @@ -257,11 +258,21 @@ const Navbar = ({}: Props) => {
const data = snap.data();
if (data && data.response) {
console.log('RESPONSE: ' + data.response);
const keywordsString = `${data.response}`;
const keywordsStr = `${data.response}`;

const cleanedString = keywordsStr.replace(/\*|\`/g, '');

const splitString = cleanedString.split("Keywords:");
const keywordsString = splitString[1].split("Hashtags:")[0].trim();
const hashtagsString = splitString[1].split("Hashtags:")[1].trim();

const keywordsArray = JSON.parse(keywordsString);
const hashtagsArray = JSON.parse(hashtagsString);

const questionDocRef = doc(db, 'questions', quesId);
await updateDoc(questionDocRef, {
keywords: keywordsString, // Add your keywords here
keywords: keywordsArray,
hashtags: hashtagsArray
});
}
});
Expand Down Expand Up @@ -549,6 +560,9 @@ const clearNotifications = async () => {
render = {({field}) => (
<FormItem>
<FormLabel>Description</FormLabel>
<div className={`${isFocused?"border-black border-[2.1px]": "border-[1.2px]"} rounded-lg`} onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
>
<FormControl>
<Controller
control={form.control}
Expand All @@ -558,6 +572,7 @@ const clearNotifications = async () => {
)}
/>
</FormControl>
</div>
<div className="text-sm opacity-70">This is the description, give more details about your question here.</div>
<FormMessage/>
</FormItem>
Expand Down

0 comments on commit 289b613

Please sign in to comment.