forked from weblab-class/Gumdrops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-code.js
148 lines (142 loc) · 5.73 KB
/
test-code.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//An old copy of the get("/projects") route:
/*
User.findById(req.query.userid).then( async (user)=>
{
try{
let arrayLength = user.projectIds.length;
let outProjects = [];
for (var i = 0; i < arrayLength; i++) {
console.log("User is in "+user.projectIds[i]+'\n');
let project = await Project.findById(user.projectIds[i]);
outProjects.push(project);
console.log("Found project "+project.name+"\n");
}
res.send({projects:outProjects});
} catch(e) {
res.status(400).json({message:e.message});
}
}); */
//An old copy of the submit project functions in CreateProject.js's handleSubmit function
//Now replaced with async/await capabilities
/* post("/api/project",projectObj).then(projectid=>{
console.log(projectid);
post("/api/user_add_project",{ //adds projectId to user's projectIds array
userId: this.props.userId,
projectId: projectid,
}).then(event=>{ //wait for both project operations to finish
if(!this.state.thumbnail){ //thumbnail empty
this.setState({ //resets the fields
projectName: "",
collaborators: "",
teamId: "",
tags: "",
thumbnail: null,
});
window.location.replace("/project/"+projectid); //redirect to new project page
} else {
//otherwise, proceeds to try add thumbnail to database
console.log("Tries to add thumbnail to database");
let thumbnailObj = {
projectId : projectid,
image: this.state.thumbnail,
}
//proceeds to upload thumbnail
post("/api/thumbnail",thumbnailObj).then((res)=>{
this.setState({ //resets the fields
projectName: "",
collaborators: "",
teamId: "",
tags: "",
thumbnail: null,
});
window.location.replace("/project/"+projectid); //redirect to new project page
});
}
});
});*/
//The following was run in Profile.js componentDidMount() as tests/placeholders
//The below command was used to trigger LinkPreview API
//It is temporary placeholder.
//let linkArray = ["https://gumdrops.herokuapp.com/","https://www.youtube.com/watch?v=fn3KWM1kuAw"];
//post('/api/link',{links:linkArray}).then((data)=>console.log(data));
//let myStyle = {color:"red",backgroundColor:"lightyellow",fontWeight:"bold",fontSize:"5em"};
//let newRole = { roleName: "dragonator",styling: myStyle};
//post("/api/role",newRole);
//The following is a copy of the render() function in Profile.js that was used as a test for message parsing for usernames
/*
render() {
if(this.state.user) {
if(this.state.editing) {
return(
<>
<h2 className="u-textCenter">Welcome, {!this.state.user ? "Anonymous" : this.state.user.name}</h2>
<hr></hr>
<ProfileImage userId={this.props.userId} editing={this.state.editing}/>
<ProfileBio userId={this.props.userId} editing={this.state.editing}/>
<button
type = "submit"
className = "Profile-edit u-pointer"
value = "Submit"
onClick={this.clickedEditing}
>Done
</button>
</>
);
}
let myStyle = {color:"red",backgroundColor:"lightyellow",fontWeight:"bold",fontSize:"5em"};
let text2 = "this is a normal text @daniel and I see the light @harry";
let text = "me, @daniel, and @david all went to the quarry together."
let nameArray = ["@daniel","@harry"];
let outputArray = [];
while(text!=="") {
let nextAt = text.indexOf("@");
if(nextAt === -1) {
outputArray.push(text);
break;
} else {
outputArray.push(text.substring(0,nextAt));
text = text.substring(nextAt);
let userFound = false;
for(var i=0; i<nameArray.length;i++){
if(text.startsWith(nameArray[i])) {
console.log("I found username "+nameArray[i]);
outputArray.push(nameArray[i]);
text = text.substring(nameArray[i].length);
userFound = true;
break;
}
}
if(!userFound) { //did not find anything
outputArray.push("@");
text = text.substring(1);
}
}
}
console.log(outputArray);
console.log("It stopped");
return(
<>
<h2 className="u-textCenter">Welcome, {!this.state.user ? "Anonymous" : this.state.user.name}</h2>
{outputArray.map((value)=>{
if(nameArray.includes(value)){
return <span style={{color:"red"}}>{value}</span>;
} else {
return <span>{value}</span>;
}
})}
<hr></hr>
<ProfileImage userId={this.props.userId} editing={this.state.editing}/>
<ProfileBio userId={this.props.userId} editing={this.state.editing}/>
<button
type = "submit"
className = "Profile-edit u-pointer"
value = "Submit"
onClick={this.clickedEditing}
>Edit
</button>
</>
);
}
return <h1>Loading!</h1>
}
*/