-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added share option and routes for it
- Loading branch information
Showing
8 changed files
with
229 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { CloseIcon } from "../icons/close" | ||
import { Button } from "./Button" | ||
import axios from "axios"; | ||
import { backendURL, brainShareLink, brainShareURL, userContentURL } from "../../config"; | ||
import { ClipboarIcon } from "../icons/clipboard"; | ||
import { useRef, useState } from "react"; | ||
|
||
interface AddModalProps { | ||
open:boolean, | ||
onClose?:() => void, | ||
} | ||
|
||
export function ShareModal({open, onClose }:AddModalProps) { | ||
|
||
let urlReference= useRef<string>(backendURL+brainShareURL); | ||
const [stateURL, setStateURL] = useState(urlReference.current) | ||
|
||
|
||
const jwt = localStorage.getItem("token"); | ||
async function sharePage() { | ||
try { | ||
var responseValue = await axios.post(backendURL + brainShareURL, { | ||
share:true | ||
}, { | ||
headers: { | ||
"Authorization": jwt | ||
} | ||
}) | ||
let url = responseValue.data.URL.replace("3000", "5173") | ||
urlReference = url | ||
setStateURL(url) | ||
|
||
}catch (err) { | ||
console.log(err) | ||
} | ||
|
||
} | ||
|
||
|
||
return <div> | ||
{ open && <div className="h-screen w-screen bg-opacity-50 bg-slate-800 fixed -top-0 -left-0 z-10 overscroll-contain flex justify-center items-center outside" onClick={function (eObj) { | ||
//@ts-ignore | ||
if (eObj.target.className.includes("outside")){ | ||
onClose?.() | ||
} | ||
}}> | ||
<div className="min-h-96 max-h-[60%] w-[30%] bg-white rounded px-6 select-none py-8 modal" > | ||
<div className="flex justify-end select-none cursor-pointer" onClick={onClose}> | ||
<CloseIcon> | ||
</CloseIcon> | ||
</div> | ||
<div className="shareValue font-mono bg-purple-200 text-center p-2 mt-6 text-nowrap overflow-x-scroll" > | ||
URL : {stateURL} | ||
</div> | ||
<div className="flex justify-center gap-4 mt-10"> | ||
<Button variant="primary" text="Share" size="lg" handlerClick={function() { | ||
sharePage() | ||
}}></Button> | ||
<Button variant="primary" startIcon={<ClipboarIcon/>} size="lg" text="Copy" handlerClick={function() { | ||
navigator.clipboard.writeText(stateURL).then(m=> { | ||
alert("copied!!") | ||
}) | ||
}}></Button> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
|
||
} |
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,24 @@ | ||
import axios from "axios"; | ||
import { useEffect, useState } from "react"; | ||
import { Location } from "react-router-dom"; | ||
import { backendURL } from "../config"; | ||
|
||
export function useShareContent(hashValue:Location) { | ||
const [elements, setElements] = useState([]) | ||
|
||
const pathName = hashValue.pathname; | ||
|
||
const URL = backendURL+ "/user"+pathName; | ||
console.log(URL) | ||
|
||
useEffect(function() { | ||
|
||
axios.get(URL).then(m => { | ||
setElements(m.data.value.content) | ||
console.log(m.data.value.content) | ||
}) | ||
|
||
},[]) | ||
|
||
return elements; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import '../App.css' | ||
import { Card, cardProps } from '../components/ui/card' | ||
import brainImage from "../assets/brain.png" | ||
import { backendURL, userContentURL } from '../config' | ||
import axios from 'axios' | ||
import { useShareContent } from '../hooks/shareContent' | ||
import { useLocation } from 'react-router-dom' | ||
|
||
function ShareDashboard() { | ||
|
||
const url = useLocation() | ||
|
||
|
||
const content = useShareContent(url); | ||
|
||
return <div className="flex mx-auto"> | ||
|
||
<div className='px-10 flex-1 py-8 max-h-screen space-y-3.5 scroll-smooth overscroll-contain overflow-scroll'> | ||
<div className='flex justify-start gap-2 hover:shadow-xl p-4'> | ||
<div className='flex space-x-3 items-center'> | ||
<img src={brainImage} alt="logo" className='size-10'/> | ||
<span className='text-3xl font-semibold tracking-tighter font-sans'> Brainly</span> | ||
</div> | ||
</div> | ||
<div className='flex gap-8 flex-wrap justify-center m-auto '> | ||
{content.map(function (item:{type:string, tag:{title:string}[], title:string, link:string, _id:string}, index:number) { | ||
console.log(item) | ||
switch (item.type) { | ||
case "video": | ||
item.type = "yt" | ||
break; | ||
case "audio": | ||
item.type = "yt" | ||
break; | ||
case "article": | ||
item.type = "docs" | ||
break; | ||
case "tweet": | ||
item.type = "tw" | ||
break; | ||
case "unknown": | ||
item.type = "unknown" | ||
break; | ||
default: | ||
break; | ||
} | ||
const contentId = (item._id); | ||
return <Card deleteHandler={ async function () { | ||
|
||
try { | ||
let deleteResponse = await axios.delete(backendURL+userContentURL, { | ||
data : { | ||
contentId | ||
}, | ||
headers :{ | ||
"Authorization": localStorage.getItem("token") | ||
} | ||
}) | ||
console.log(deleteResponse) | ||
window.location.reload() | ||
|
||
}catch (err) { | ||
console.log(err) | ||
} | ||
|
||
}} contentId={item._id} tag={item.tag} key={index} type={item.type as cardProps["type"]} title={item.title} link={item.link} /> | ||
})} | ||
{content.length ==0 ? <div className='h-96 w-full flex justify-center items-end relative'> | ||
No content | ||
</div> :"" } | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
} | ||
|
||
export default ShareDashboard |