-
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.
- Loading branch information
Showing
10 changed files
with
225 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.icon-upvote { | ||
width: 55px; | ||
height: 36px; | ||
left: 238px; | ||
top: 195.24px; | ||
} | ||
.icon-upvote:hover { | ||
cursor: pointer; | ||
} | ||
.icon-downvote { | ||
position: absolute; | ||
width: 55px; | ||
height: 36px; | ||
|
||
transform: rotate(-180deg); | ||
} | ||
.icon-downvote:hover { | ||
cursor: pointer; | ||
} |
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,26 @@ | ||
import React from "react"; | ||
import upDownVote from "./upDownvote.png"; | ||
import "./DisplayLink.css"; | ||
const DisplayLink = (props) => { | ||
return ( | ||
<div className="container-display-link"> | ||
<img | ||
src={upDownVote} | ||
alt="iconForUpvoteDownvote" | ||
className="icon-upvote" | ||
></img> | ||
|
||
<img | ||
src={upDownVote} | ||
alt="iconForUpvoteDownvote" | ||
className="icon-downvote" | ||
></img> | ||
<p>{props.link}</p> | ||
<p>{props.linkName}</p> | ||
<p>{props.userName}</p> | ||
<hr /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DisplayLink; |
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,49 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import Upload from "./Upload"; | ||
import DisplayLink from "./DisplayLink"; | ||
|
||
const ShareMain = () => { | ||
const [uploadYes, setUploadYes] = useState(false); | ||
const [link, setLinks] = useState([]); | ||
|
||
const handleClick = () => { | ||
setUploadYes(true); | ||
}; | ||
|
||
const handleClickExit = () => { | ||
setUploadYes(false); | ||
}; | ||
|
||
useEffect(() => { | ||
const getResource = async () => { | ||
const result = await fetch("/getresource"); | ||
const links = await result.json(); | ||
console.log(links[0]); | ||
setLinks(links); | ||
}; | ||
|
||
getResource(); | ||
}, []); | ||
return ( | ||
<div> | ||
<h1>resourec main page</h1> | ||
<button onClick={handleClick}>Upload</button> | ||
{uploadYes ? <Upload exit={handleClickExit} /> : <div></div>} | ||
|
||
{link.length === 0 ? ( | ||
<div>Loading ...</div> | ||
) : ( | ||
link.map((e) => ( | ||
<DisplayLink | ||
link={e.link} | ||
linkName={e.linkName} | ||
userName={e.userName} | ||
key={e._id} | ||
/> | ||
)) | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ShareMain; |
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,53 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const Upload = (props) => { | ||
const [link, setLink] = useState(""); | ||
const [linkName, setLinkName] = useState(""); | ||
|
||
const handleClickUpload = () => { | ||
fetch("/resourceupload", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
link: link, | ||
linkName: linkName, | ||
userName: document.cookie | ||
.split("; ") | ||
.find((row) => row.startsWith("access-token")) | ||
.split("=")[1], | ||
}), | ||
}); | ||
|
||
setLink(""); | ||
setLinkName(""); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<dialog open> | ||
<label htmlFor="resourceName">Link Name</label> | ||
<input | ||
type="text" | ||
placeholder="Enter name to be displayed" | ||
name="resourceName" | ||
value={linkName} | ||
onChange={(e) => setLinkName(e.target.value)} | ||
></input> | ||
<label htmlFor="resourceLink">Link</label> | ||
<input | ||
type="text" | ||
placeholder="enter or paste a URL" | ||
name="resourceLink" | ||
value={link} | ||
onChange={(e) => setLink(e.target.value)} | ||
></input> | ||
<button onClick={props.exit}>Exit</button> | ||
<button onClick={handleClickUpload}>Upload</button> | ||
</dialog> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Upload; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
const { MongoClient } = require("mongodb"); | ||
|
||
module.exports = async function (emptyArray) { | ||
const uri = process.env.DB_CREDENTIALS; | ||
|
||
const client = new MongoClient(uri, { useUnifiedTopology: true }); | ||
let successOrFail = false; | ||
|
||
try { | ||
await client.connect(); | ||
|
||
const database = client.db("4learn"); | ||
const collection = database.collection("Resource"); | ||
|
||
// create js obj received by /login | ||
|
||
const result = await collection.find(); | ||
|
||
await result.forEach((result) => emptyArray.push(result)); | ||
} finally { | ||
await client.close(); | ||
return emptyArray; | ||
} | ||
}; |
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,26 @@ | ||
const { MongoClient } = require("mongodb"); | ||
|
||
module.exports = async function (userName, link, linkName) { | ||
const uri = process.env.DB_CREDENTIALS; | ||
|
||
const client = new MongoClient(uri); | ||
let successOrFail = false; | ||
try { | ||
await client.connect(); | ||
|
||
const database = client.db("4learn"); | ||
const collection = database.collection("Resource"); | ||
|
||
const doc = { userName: userName, link: link, linkName: linkName }; | ||
const result = await collection.insertOne(doc); | ||
|
||
console.log(`${result.insertedCount} documents were inserted into db`); | ||
console.log(result.insertedCount > 0); | ||
if (result.insertedCount > 0) { | ||
successOrFail = true; | ||
return true; | ||
} | ||
} finally { | ||
await client.close(); | ||
} | ||
}; |