diff --git a/app/EventDetailsPage/[eventTitle]/page.tsx b/app/EventDetailsPage/[eventTitle]/page.tsx index c3479ea..893243f 100644 --- a/app/EventDetailsPage/[eventTitle]/page.tsx +++ b/app/EventDetailsPage/[eventTitle]/page.tsx @@ -66,6 +66,7 @@ type EventDetailsType = { durationOfEvent: number registrationLink: string uid: string + hashtags: Array createdAt: string name: string profilePic: string @@ -373,51 +374,14 @@ const EventDetailsPage = ({ params: { eventTitle } }: Props) => {
- - - - - - - - - - - - - - - + {eventObject.hashtags?( + eventObject.hashtags.map((hashtag, index)=>{ + return + }) + ):
No Tags Found...
+ }
diff --git a/app/homepage2/page.tsx b/app/homepage2/page.tsx index fa07d2c..dab6aeb 100644 --- a/app/homepage2/page.tsx +++ b/app/homepage2/page.tsx @@ -27,7 +27,9 @@ import Loader from "../../components/ui/Loader" import { db , storage} from "@/utils/firebase"; import { addDoc, + arrayUnion, collection, + getDoc, getDocs, limit, onSnapshot, @@ -35,6 +37,7 @@ import { query, serverTimestamp, startAfter, + updateDoc, where, } from "firebase/firestore"; import { ref , uploadBytes, uploadBytesResumable , getDownloadURL} from "firebase/storage"; @@ -43,7 +46,7 @@ import imageCompression from 'browser-image-compression'; import styled, { createGlobalStyle } from "styled-components"; - +import { LuXCircle } from "react-icons/lu"; import { Dialog, @@ -157,13 +160,18 @@ export default function MusicPage() { const [isFocused, setIsFocused] = useState(false); - + type SelectedCategoriesType = Record; //image uploading const [imageUpload , setImageUpload] = useState(null); const [imageUrl, setImageUrl] = useState(null); const [selectC, setSelectC] = useState([]); + const [selectedCategories, setSelectedCategories] = useState({}); + const [selectedMainCategory, setSelectedMainCategory] = useState(''); + const [selectedSubcategory, setSelectedSubcategory] = useState(''); const [progress , setProgress] = useState(0); const [previewImg, setPreviewImg] = useState(null); + const [subCategoryy, setSubCategoryy] = useState(["SubCategory1", "SubCategory2", "SubCategory3"]); + const [tempSubCategory, setTempSubCategory] = useState([]); //old homepage stuff @@ -305,9 +313,68 @@ export default function MusicPage() { } }; + //category stuff + + const handleMainCategoryChange = (newValue: string) => { + setTempSubCategory([]); + if(!selectC.includes(newValue)){ + setSelectC((prev:any)=>{ + return [...prev, newValue] + }) + } + setSelectedMainCategory(newValue); + handleCategorySelectChange(newValue, undefined); + }; + + const handleSubcategoryChange = (newValue: string) => { + if(!tempSubCategory.includes(newValue)){ + setTempSubCategory((prev:any)=>{ + return [...prev, newValue] + }) + } + handleCategorySelectChange(selectedMainCategory, newValue); + setSelectedSubcategory(newValue); + }; + + const handleCategorySelectChange = (category: string, subcategory: string | undefined) => { + setSelectedCategories((prev: any) => { + const updatedCategories = { ...prev }; + if (!updatedCategories[category]) { + updatedCategories[category] = []; + } + if (subcategory && !updatedCategories[category].includes(subcategory)) { + updatedCategories[category].push(subcategory); + } + return updatedCategories; + }); + //console.log(selectedCategories); + }; + + const delCategories = (category:string)=>{ + let newCategory=selectC.filter((cat:any)=>{ + console.log(cat, " ", category); + return cat!=category; + }) + setSelectC(newCategory); + delete selectedCategories[category] + //console.log(selectedCategories); + } + + const delSubCategories = (category:string)=>{ + let newSubCategory=tempSubCategory.filter((cat:any)=>{ + return cat!=category; + }) + setTempSubCategory(newSubCategory); + selectedCategories[selectedMainCategory]=selectedCategories[selectedMainCategory].filter((subcat)=>( + subcat!=category + )) + //console.log(selectedCategories); + } + //create event + async function createEventPost(data:Input) { - const docRef = addDoc(collection(db, 'events'), { + const docRef = await addDoc(collection(db, 'events'), { title: data.title, description: data.description, eventImageURL: imageUrl, @@ -321,10 +388,72 @@ export default function MusicPage() { profilePic: user?.photoURL, }); + console.log("Event ID: ", docRef.id); + const event_id = docRef.id + + try { + for (const [mainCategory, subcategories] of Object.entries(selectedCategories)) { + // Update Firestore for main category + await updateDoc(doc(db, 'meta-data', 'v1', 'event-categories', mainCategory), { + Events: arrayUnion(docRef.id), + }); + + // Update Firestore for each subcategory + for (const subcategory of subcategories) { + await updateDoc(doc(db, 'meta-data', 'v1', 'event-categories', mainCategory), { + [subcategory]: arrayUnion(docRef.id), + }); + } + } + + // Clear selected categories after submission + setSelectedCategories({}); + } catch (error) { + console.error('Error updating Firestore:', error); + } + toast({ title: "Event Created", description: "Your event has been created successfully.", }) + + 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 "**Keywords:**["Keyword1", "Keyword2",...] **Hashtags:**["Hashtag1", "Hashtag2",...]" this format`, + }); + console.log('Keyword Document written with ID: ', docRef.id); + + // Listen for changes to the document + const unsubscribe = onSnapshot(doc(db, 'keywords', docRef.id), async(snap) => { + const data = snap.data(); + if (data && data.response) { + console.log('RESPONSE: ' + 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, 'events', event_id); + await updateDoc(questionDocRef, { + keywords: keywordsArray, + hashtags: hashtagsArray // Add your keywords here + }); + } + }); + + // Stop listening after some time (for demonstration purposes) + setTimeout(() => unsubscribe(), 60000); + } catch (error) { + console.error('Error adding document: ', error); + } + } function onSubmit(data: Input) { @@ -351,7 +480,13 @@ export default function MusicPage() { setLastDoc(loadMore); }; - + useEffect(()=>{ + const getCat=async()=>{ + //fetch all categories + } + getCat(); + }, []) + //useEffect for automting lazyload functionality useEffect(() => { if(morePosts){ @@ -409,7 +544,7 @@ export default function MusicPage() { } - + Create your Event @@ -499,7 +634,64 @@ export default function MusicPage() { } - + {/*Category thing*/} +
+ +
Category
+ +
+ { + selectC.map((category:string, index:number)=>{ + return {category.split("|").join("/")} {delCategories(category)}} className="mt-[0.27rem] ml-1 cursor-pointer text-slate-800 hover:text-slate-900"> + }) + } +
+ {/* Ls */} +
+ {selectedMainCategory && ( + + )} +
+ { + tempSubCategory.map((subcategory:string, index:number)=>{ + return {subcategory} {delSubCategories(subcategory)}} className="mt-[0.27rem] ml-1 cursor-pointer text-slate-800 hover:text-slate-900"> + }) + } +
+
+ {/* */} +
This is the category, you can choose multiple categories for your Question.
+
{/* DateOfEvent */}