From fa6472ce1541df5c038275e66efa885f5864e20c Mon Sep 17 00:00:00 2001 From: jay Date: Wed, 25 Oct 2023 16:49:13 +0530 Subject: [PATCH 1/7] work in progress Match page --- app/match/page.tsx | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/match/page.tsx diff --git a/app/match/page.tsx b/app/match/page.tsx new file mode 100644 index 0000000..45c7bb0 --- /dev/null +++ b/app/match/page.tsx @@ -0,0 +1,71 @@ +"use client" + +import { ReactNode, useEffect, useState } from "react" +import { useRouter } from "next/navigation" +import { useEncryptedStore } from "@/store/encrypted" +import { usePasswordStore } from "@/store/password" + +import RequireAuth from "@/components/helper/RequireAuth" + +const Match = () => { + const router = useRouter() + const [match, setMatch] = useState(null) + const [user1, setUser1] = useState(null) + const [user2, setUser2] = useState(null) + const [verificationURLs, setVerificationURLs] = useState(0) + const { address } = useEncryptedStore() + const { userId, token } = usePasswordStore() + + useEffect(() => { + ;(async () => { + try { + const { match } = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/getmatch/${userId}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + } + ).then((res) => res.json()) + console.log("match : ", match); + setUser1(match.user1) + setUser2(match.user2) + } catch (error) { + console.log(error) + } + })() + }, [address, userId, token, router]) + + + + return ( + +
+

My matches

+
+
+ +

your matches

+

{match}

+
+ +

your task

+

{user2 && user2.urls}

+
+
+
+
+ ) +} + +const Row = ({ children }: { children: ReactNode }) => { + return ( +
+ {children} +
+ ) +} + +export default Match From 640424502c477c2fa475184d9643388ad5db2600 Mon Sep 17 00:00:00 2001 From: hackertron Date: Thu, 26 Oct 2023 11:53:18 +0530 Subject: [PATCH 2/7] show match object on match page --- app/match/page.tsx | 56 +++++++++++++++++++++++++++++++++++++++------- types/index.ts | 18 +++++++++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/app/match/page.tsx b/app/match/page.tsx index 45c7bb0..7f817d8 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -4,15 +4,57 @@ import { ReactNode, useEffect, useState } from "react" import { useRouter } from "next/navigation" import { useEncryptedStore } from "@/store/encrypted" import { usePasswordStore } from "@/store/password" - +import { MatchDocument } from "@/types" import RequireAuth from "@/components/helper/RequireAuth" +const MatchDetails = ({ matchData }: {matchData: MatchDocument}) => { + const user1Urls = matchData.user1.urls.map((url, index) => ( +
  • + Title: {url.title} | URL: {url.url} +
  • + )); + + const user2Urls = matchData.user2.urls.map((url, index) => ( +
  • + Title: {url.title} | URL: {url.url} +
  • + )); + + return ( +
    +

    Match Details

    +
      +
    • + Status: {matchData.status} +
    • +
    • + Threshold: {matchData.threshold} +
    • +
    • + Created At:{" "} + {new Date(matchData.createdAt.$date).toLocaleString()} +
    • +
    • + Updated At:{" "} + {new Date(matchData.updatedAt.$date).toLocaleString()} +
    • +
    • + User 1 URLs: +
        {user1Urls}
      +
    • +
    • + User 2 URLs: +
        {user2Urls}
      +
    • +
    +
    + ); +}; + + const Match = () => { const router = useRouter() const [match, setMatch] = useState(null) - const [user1, setUser1] = useState(null) - const [user2, setUser2] = useState(null) - const [verificationURLs, setVerificationURLs] = useState(0) const { address } = useEncryptedStore() const { userId, token } = usePasswordStore() @@ -30,8 +72,7 @@ const Match = () => { } ).then((res) => res.json()) console.log("match : ", match); - setUser1(match.user1) - setUser2(match.user2) + setMatch(match) } catch (error) { console.log(error) } @@ -48,11 +89,10 @@ const Match = () => {

    your matches

    -

    {match}

    + {match && }

    your task

    -

    {user2 && user2.urls}

    diff --git a/types/index.ts b/types/index.ts index 0ff6d8b..c2654ff 100644 --- a/types/index.ts +++ b/types/index.ts @@ -23,3 +23,21 @@ export interface NavItem { disabled?: boolean external?: boolean } + +export interface MatchDocument { + _id: string, + user1: { + id: string, + urls: Array, + completed: boolean, +}, +user2: { + id: string, + urls: Array, + completed: boolean, +}, +status: string; +threshold: number; // threshold is max limit of urls allowed to be validated, depnds on key in MatchGroup +createdAt: Date; +updatedAt: Date; +} \ No newline at end of file From efab64e7802adcc193bf14f6b832c8b1a176d239 Mon Sep 17 00:00:00 2001 From: hackertron Date: Thu, 26 Oct 2023 13:05:19 +0530 Subject: [PATCH 3/7] added verification button --- app/match/page.tsx | 113 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 101 insertions(+), 12 deletions(-) diff --git a/app/match/page.tsx b/app/match/page.tsx index 7f817d8..b2d69f2 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -6,17 +6,85 @@ import { useEncryptedStore } from "@/store/encrypted" import { usePasswordStore } from "@/store/password" import { MatchDocument } from "@/types" import RequireAuth from "@/components/helper/RequireAuth" +import { Button } from "@/components/ui/button" -const MatchDetails = ({ matchData }: {matchData: MatchDocument}) => { + +const handleVerificationSubmit = async () => { + const verifiedURLs = JSON.parse(localStorage.getItem("verifiedURLs")) || []; + const invalidURLs = JSON.parse(localStorage.getItem("invalidURLs")) || []; + + try { + const response = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/updateMatch`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + userId, + verifiedURLs, + invalidURLs, + }), + } + ); + + if (response.ok) { + // Handle a successful response, e.g., show a success message + } else { + // Handle the error response, e.g., show an error message + } + } catch (error) { + console.error("Error submitting verification:", error); + } +}; + +const handleCheckboxChange = (event, urlId, storageKey) => { + const isChecked = event.target.checked; + + // Get the current state from local storage or initialize an empty array + let storedData = JSON.parse(localStorage.getItem(storageKey)) || []; + + // Check if the URL is in the other list (valid_urls or invalid_urls) and remove it + const otherStorageKey = storageKey === "valid_urls" ? "invalid_urls" : "valid_urls"; + storedData = storedData.filter((id) => !isInLocalStorage(id, otherStorageKey)); + + if (isChecked) { + // Add the URL ID to the array if checked + storedData.push(urlId); + } else { + // Remove the URL ID from the array if unchecked + const index = storedData.indexOf(urlId); + if (index !== -1) { + storedData.splice(index, 1); + } + } + + // Save the updated state to local storage + localStorage.setItem(storageKey, JSON.stringify(storedData)); +}; + +const isInLocalStorage = (urlId, storageKey) => { + const storedData = JSON.parse(localStorage.getItem(storageKey)) || []; + return storedData.includes(urlId); +}; + + +const MatchDetails = ({ matchData, onVerificationSubmit }: {matchData: MatchDocument, onVerificationSubmit: () => void }) => { const user1Urls = matchData.user1.urls.map((url, index) => (
  • + {/* handleCheckboxChange(e, url._id)} />*/} Title: {url.title} | URL: {url.url}
  • )); - const user2Urls = matchData.user2.urls.map((url, index) => (
  • - Title: {url.title} | URL: {url.url} + Title: {url.title} | URL: {url.url}
    + handleCheckboxChange(e, url._id, "valid_urls")} /> +
    + handleCheckboxChange(e, url._id, "invalid_urls")} /> +
  • )); @@ -32,21 +100,23 @@ const MatchDetails = ({ matchData }: {matchData: MatchDocument}) => {
  • Created At:{" "} - {new Date(matchData.createdAt.$date).toLocaleString()} + {new Date(matchData.createdAt).toLocaleString()}
  • Updated At:{" "} - {new Date(matchData.updatedAt.$date).toLocaleString()} + {new Date(matchData.updatedAt).toLocaleString()}
  • - User 1 URLs: + your URLs:
      {user1Urls}
  • - User 2 URLs: + URLs you have to validate :
      {user2Urls}
  • + ); }; @@ -55,6 +125,8 @@ const MatchDetails = ({ matchData }: {matchData: MatchDocument}) => { const Match = () => { const router = useRouter() const [match, setMatch] = useState(null) + const [user1, setUser1] = useState(null); + const [user2, setUser2] = useState(null); const { address } = useEncryptedStore() const { userId, token } = usePasswordStore() @@ -71,10 +143,18 @@ const Match = () => { }, } ).then((res) => res.json()) - console.log("match : ", match); - setMatch(match) + if (match) { + if (match.user1.id === userId) { + setUser1(match.user1); + setUser2(match.user2); + } else { + setUser1(match.user2); + setUser2(match.user1); + } + setMatch(match); // Set the match state + } } catch (error) { - console.log(error) + console.log(error); } })() }, [address, userId, token, router]) @@ -88,11 +168,20 @@ const Match = () => {
    -

    your matches

    - {match && } +

    your match

    + {match ? ( + + ) : ( + + )}

    your task

    +

    user2

    + {user2 && + +

    {user2.id}

    + }
    From bed9c9e9c342cc2c35a8fb66920f3772daca8cc2 Mon Sep 17 00:00:00 2001 From: hackertron Date: Sun, 29 Oct 2023 21:40:26 +0530 Subject: [PATCH 4/7] update sending data to updatematch --- app/match/page.tsx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/match/page.tsx b/app/match/page.tsx index b2d69f2..075afcd 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -9,13 +9,13 @@ import RequireAuth from "@/components/helper/RequireAuth" import { Button } from "@/components/ui/button" -const handleVerificationSubmit = async () => { - const verifiedURLs = JSON.parse(localStorage.getItem("verifiedURLs")) || []; - const invalidURLs = JSON.parse(localStorage.getItem("invalidURLs")) || []; +const handleVerificationSubmit = async (matchId, userId, token) => { + const verifiedURLs = JSON.parse(localStorage.getItem("valid_urls")) || []; + const invalidURLs = JSON.parse(localStorage.getItem("invalid_urls")) || []; try { const response = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/updateMatch`, + `${process.env.NEXT_PUBLIC_API_URL}/updatematch`, { method: "POST", headers: { @@ -23,9 +23,9 @@ const handleVerificationSubmit = async () => { Authorization: `Bearer ${token}`, }, body: JSON.stringify({ + matchId, userId, verifiedURLs, - invalidURLs, }), } ); @@ -40,7 +40,7 @@ const handleVerificationSubmit = async () => { } }; -const handleCheckboxChange = (event, urlId, storageKey) => { +const handleCheckboxChange = (event, url, storageKey) => { const isChecked = event.target.checked; // Get the current state from local storage or initialize an empty array @@ -52,10 +52,10 @@ const handleCheckboxChange = (event, urlId, storageKey) => { if (isChecked) { // Add the URL ID to the array if checked - storedData.push(urlId); + storedData.push(url); } else { // Remove the URL ID from the array if unchecked - const index = storedData.indexOf(urlId); + const index = storedData.indexOf(url); if (index !== -1) { storedData.splice(index, 1); } @@ -71,7 +71,7 @@ const isInLocalStorage = (urlId, storageKey) => { }; -const MatchDetails = ({ matchData, onVerificationSubmit }: {matchData: MatchDocument, onVerificationSubmit: () => void }) => { +const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {matchData: MatchDocument, userId : string | null, token: string | null, onVerificationSubmit: (matchId: string, userId : string | null , token: string | null) => void }) => { const user1Urls = matchData.user1.urls.map((url, index) => (
  • {/* handleCheckboxChange(e, url._id)} />*/} @@ -81,9 +81,9 @@ const MatchDetails = ({ matchData, onVerificationSubmit }: {matchData: MatchDocu const user2Urls = matchData.user2.urls.map((url, index) => (
  • Title: {url.title} | URL: {url.url}
    - handleCheckboxChange(e, url._id, "valid_urls")} /> + handleCheckboxChange(e, url.url, "valid_urls")} />
    - handleCheckboxChange(e, url._id, "invalid_urls")} /> + handleCheckboxChange(e, url.url, "invalid_urls")} />
  • )); @@ -116,7 +116,7 @@ const MatchDetails = ({ matchData, onVerificationSubmit }: {matchData: MatchDocu + onClick={() => onVerificationSubmit(matchData._id, userId, token)}>Submit Verification ); }; @@ -170,7 +170,7 @@ const Match = () => {

    your match

    {match ? ( - + ) : ( )} From 742cc06a4c2022495511126ec6c63b8553aed846 Mon Sep 17 00:00:00 2001 From: hackertron Date: Mon, 30 Oct 2023 15:26:17 +0100 Subject: [PATCH 5/7] mark complete and submit verification button added --- app/match/page.tsx | 109 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 26 deletions(-) diff --git a/app/match/page.tsx b/app/match/page.tsx index 075afcd..3f93fc5 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -9,6 +9,57 @@ import RequireAuth from "@/components/helper/RequireAuth" import { Button } from "@/components/ui/button" +const onMarkCompletionButton = async(userId: string | null) => { + // make post request to markcompletion + try { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/markcompletion`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userId, + }), + }); + + if (response.ok) { + // show alert and reload the page + window.alert("Success!"); + window.location.reload(); + } else { + // Handle error + window.alert("Error!"); + } + } catch (error) { + console.error("Error marking completion:", error); + } + }; + +const onCreateMatchButton = async(userId: string | null) => { + try { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/creatematch`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userId, + }), + }); + + if (response.ok) { + // reload the page + window.location.reload(); + } else { + // show alert no match found + window.alert("No match found"); + } + } catch (error) { + console.error("Error creating match:", error); + } + }; + + const handleVerificationSubmit = async (matchId, userId, token) => { const verifiedURLs = JSON.parse(localStorage.getItem("valid_urls")) || []; const invalidURLs = JSON.parse(localStorage.getItem("invalid_urls")) || []; @@ -72,21 +123,29 @@ const isInLocalStorage = (urlId, storageKey) => { const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {matchData: MatchDocument, userId : string | null, token: string | null, onVerificationSubmit: (matchId: string, userId : string | null , token: string | null) => void }) => { - const user1Urls = matchData.user1.urls.map((url, index) => ( -
  • - {/* handleCheckboxChange(e, url._id)} />*/} - Title: {url.title} | URL: {url.url} -
  • - )); - const user2Urls = matchData.user2.urls.map((url, index) => ( -
  • - Title: {url.title} | URL: {url.url}
    - handleCheckboxChange(e, url.url, "valid_urls")} /> -
    - handleCheckboxChange(e, url.url, "invalid_urls")} /> -
    -
  • - )); + let urlsToValidate = null; + if(userId != matchData.user1.id) { + urlsToValidate = matchData.user1.urls.map((url, index) => ( +
  • + Title: {url.title} | URL: {url.url}
    + handleCheckboxChange(e, url.url, "valid_urls")} /> +
    + handleCheckboxChange(e, url.url, "invalid_urls")} /> +
    +
  • + )) + } + else { + urlsToValidate = matchData.user2.urls.map((url, index) => ( +
  • + Title: {url.title} | URL: {url.url}
    + handleCheckboxChange(e, url.url, "valid_urls")} /> +
    + handleCheckboxChange(e, url.url, "invalid_urls")} /> +
    +
  • + )) + } return (
    @@ -106,13 +165,9 @@ const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {match Updated At:{" "} {new Date(matchData.updatedAt).toLocaleString()} -
  • - your URLs: -
      {user1Urls}
    -
  • URLs you have to validate : -
      {user2Urls}
    +
      {urlsToValidate}
  • + )} -

    your task

    -

    user2

    - {user2 && - -

    {user2.id}

    +

    are you done validating?

    +

    Mark as complete

    + {match && + }
    From acadcf7bd8692ff4e036400c9770a638586d5efa Mon Sep 17 00:00:00 2001 From: hackertron Date: Tue, 7 Nov 2023 09:41:39 +0100 Subject: [PATCH 6/7] match results component added --- app/match/page.tsx | 131 +++++++++++++++++++++++++++++++++++++-------- config/site.ts | 4 ++ 2 files changed, 112 insertions(+), 23 deletions(-) diff --git a/app/match/page.tsx b/app/match/page.tsx index 3f93fc5..8ceed13 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -48,7 +48,6 @@ const onCreateMatchButton = async(userId: string | null) => { }); if (response.ok) { - // reload the page window.location.reload(); } else { // show alert no match found @@ -121,30 +120,33 @@ const isInLocalStorage = (urlId, storageKey) => { return storedData.includes(urlId); }; +const populateUrls = (urls, includeInputValue) => { + return urls.map((url, index) => ( +
  • + Title: {url.title} | URL: {url.url}
    + {includeInputValue && ( +
    + handleCheckboxChange(e, url.url, "valid_urls")} /> +
    + handleCheckboxChange(e, url.url, "invalid_urls")} /> +
    +
    + )} +
  • + )); +}; + const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {matchData: MatchDocument, userId : string | null, token: string | null, onVerificationSubmit: (matchId: string, userId : string | null , token: string | null) => void }) => { let urlsToValidate = null; + let loggedInUserUrls = null; if(userId != matchData.user1.id) { - urlsToValidate = matchData.user1.urls.map((url, index) => ( -
  • - Title: {url.title} | URL: {url.url}
    - handleCheckboxChange(e, url.url, "valid_urls")} /> -
    - handleCheckboxChange(e, url.url, "invalid_urls")} /> -
    -
  • - )) + urlsToValidate = populateUrls(matchData.user1.urls, true); + loggedInUserUrls = populateUrls(matchData.user2.urls, false); } else { - urlsToValidate = matchData.user2.urls.map((url, index) => ( -
  • - Title: {url.title} | URL: {url.url}
    - handleCheckboxChange(e, url.url, "valid_urls")} /> -
    - handleCheckboxChange(e, url.url, "invalid_urls")} /> -
    -
  • - )) + urlsToValidate = populateUrls(matchData.user2.urls, true); + loggedInUserUrls = populateUrls(matchData.user1.urls, false); } return ( @@ -154,9 +156,6 @@ const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {match
  • Status: {matchData.status}
  • -
  • - Threshold: {matchData.threshold} -
  • Created At:{" "} {new Date(matchData.createdAt).toLocaleString()} @@ -166,7 +165,11 @@ const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {match {new Date(matchData.updatedAt).toLocaleString()}
  • - URLs you have to validate : + Your urls : +
      {loggedInUserUrls}
    +
  • +
  • + URLs you have to validate :
      {urlsToValidate}
  • @@ -176,6 +179,84 @@ const MatchDetails = ({ matchData, userId, token, onVerificationSubmit }: {match ); }; +const MatchResult = ({ matchData, onAgree, onClose }) => { + return ( +
    +

    Match Results

    +
      +
    • + User 1 ID: {matchData.user1.id} +
    • +
    • + User 1 Concur: {matchData.user1.concur} +
    • +
    • + User 1 Completed: {matchData.user1.completed ? 'Yes' : 'No'} +
    • +
    • + User 2 ID: {matchData.user2.id} +
    • +
    • + User 2 Concur: {matchData.user2.concur} +
    • +
    • + User 2 Completed: {matchData.user2.completed ? 'Yes' : 'No'} +
    • + {/* Render other properties as needed */} +
    +
    + + +
    +
    + ); +}; + +const handleAgree = async () => { + try { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/concur`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ agree: true }), + }); + + if (response.ok) { + // Handle success, e.g., show a success message + console.log('Agree successful'); + } else { + // Handle the error response, e.g., show an error message + console.error('Agree failed'); + } + } catch (error) { + console.error('Error agreeing:', error); + } +}; + +const handleClose = async () => { + try { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/concur`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ agree: false }), + }); + + if (response.ok) { + // Handle success, e.g., show a success message + console.log('Close successful'); + } else { + // Handle the error response, e.g., show an error message + console.error('Close failed'); + } + } catch (error) { + console.error('Error closing:', error); + } +}; + + const Match = () => { const router = useRouter() @@ -199,6 +280,7 @@ const Match = () => { } ).then((res) => res.json()) if (match) { + console.log("match : ", match); if (match.user1.id === userId) { console.log("inside match.user1.id : ", userId); setUser1(match.user1); @@ -240,6 +322,9 @@ const Match = () => { onClick={() => onMarkCompletionButton(userId)}>Completed }
    + + + diff --git a/config/site.ts b/config/site.ts index 5e80ac6..c913f7f 100644 --- a/config/site.ts +++ b/config/site.ts @@ -17,6 +17,10 @@ export const siteConfig = { title: "Add tag", href: "/submit-tag", }, + { + title: "Match", + href: "/match", + }, { title: "Me", href: "/me", From 90ad6667b48e9da1322869b1b96f4bf52f33bca5 Mon Sep 17 00:00:00 2001 From: hackertron Date: Tue, 7 Nov 2023 10:17:13 +0100 Subject: [PATCH 7/7] bug fix in matchresult. add conditional rendering --- app/match/page.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/match/page.tsx b/app/match/page.tsx index 8ceed13..42dac85 100644 --- a/app/match/page.tsx +++ b/app/match/page.tsx @@ -187,6 +187,16 @@ const MatchResult = ({ matchData, onAgree, onClose }) => {
  • User 1 ID: {matchData.user1.id}
  • +
  • +
      + {matchData.user1.urls.map((url, index) => ( +
    • + Title: {url.title} | URL:{" "} + {url.url} | Verified: {url.verified ? "Yes" : "No"} +
    • + ))} +
    +
  • User 1 Concur: {matchData.user1.concur}
  • @@ -196,6 +206,16 @@ const MatchResult = ({ matchData, onAgree, onClose }) => {
  • User 2 ID: {matchData.user2.id}
  • +
  • +
      + {matchData.user2.urls.map((url, index) => ( +
    • + Title: {url.title} | URL:{" "} + {url.url} | Verified: {url.verified ? "Yes" : "No"} +
    • + ))} +
    +
  • User 2 Concur: {matchData.user2.concur}
  • @@ -323,7 +343,7 @@ const Match = () => { } - + {match && }