1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
import sha256 from 'https://esm.sh/crypto-js/sha256';
import Hex from 'https://esm.sh/crypto-js/enc-hex';
const PASSWORD_HASH = "75699634e8d0a66d4c9e0c8f4a5a4e02c3a1d0a13b3a5e9c7b3a1d0a13b3a5e9c";
function App() {
const [view, setView] = useState("home");
const [bio, setBio] = useState("");
const [ratings, setRatings] = useState({
authenticity: 0,
humor: 0,
clarity: 0,
positivity: 0,
uniqueness: 0,
conciseness: 0,
grammar: 0,
sharedInterests: 0,
respectfulness: 0,
confidence: 0,
openness: 0,
conversationStarters: 0,
originality: 0,
emotionalIntelligence: 0,
callToAction: 0
});
const [leaderboard, setLeaderboard] = useState([]);
useEffect(() => {
fetchLeaderboard();
}, []);
const fetchLeaderboard = async () => {
const response = await fetch("/leaderboard");
if (response.ok) {
const data = await response.json();
setLeaderboard(data);
}
};
const handleSubmit = async (e) => {
e.preventDefault();
const response = await fetch("/submit", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ bio }),
});
if (response.ok) {
setBio("");
setView("rate");
}
};
const handleRate = async (category, value) => {
setRatings(prev => ({ ...prev, [category]: value }));
await fetch("/rate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ category, value }),
});
};
const fetchBioToRate = async () => {
const response = await fetch("/bio");
if (response.ok) {
const data = await response.json();
setBio(data.bio || "No more bios to rate!");
setRatings({
authenticity: 0,
humor: 0,
clarity: 0,
positivity: 0,
uniqueness: 0,
conciseness: 0,
grammar: 0,
sharedInterests: 0,
respectfulness: 0,
confidence: 0,
openness: 0,
conversationStarters: 0,
originality: 0,
emotionalIntelligence: 0,
callToAction: 0
});
}
};
const clearAllBios = async () => {
const password = prompt("Enter the password to clear all bios:");
if (password) {
const hashedPassword = Hex.stringify(sha256(password));
if (hashedPassword === PASSWORD_HASH) {
const response = await fetch("/clear-bios", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ password: hashedPassword })
});