|
|
@ -54,7 +54,7 @@ class StoryList {
|
|
|
|
// instance method?
|
|
|
|
// instance method?
|
|
|
|
|
|
|
|
|
|
|
|
// query the /stories endpoint (no auth required)
|
|
|
|
// query the /stories endpoint (no auth required)
|
|
|
|
const response = await axios({
|
|
|
|
const response = axios({
|
|
|
|
url: `${BASE_URL}/stories`,
|
|
|
|
url: `${BASE_URL}/stories`,
|
|
|
|
method: "GET",
|
|
|
|
method: "GET",
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -63,7 +63,7 @@ class StoryList {
|
|
|
|
const stories = response.data.stories.map(story => new Story(story));
|
|
|
|
const stories = response.data.stories.map(story => new Story(story));
|
|
|
|
console.log("stories instances here: ", stories);
|
|
|
|
console.log("stories instances here: ", stories);
|
|
|
|
// build an instance of our own class using the new array of stories
|
|
|
|
// build an instance of our own class using the new array of stories
|
|
|
|
return new StoryList(stories);
|
|
|
|
return new StoryList(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Adds story data to API, makes a Story instance, adds it to story list.
|
|
|
|
/** Adds story data to API, makes a Story instance, adds it to story list.
|
|
|
@ -74,18 +74,13 @@ class StoryList {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
async addStory(user, newStory) {
|
|
|
|
async addStory(user, newStory) {
|
|
|
|
|
|
|
|
|
|
|
|
//console.debug("addStory called");
|
|
|
|
|
|
|
|
//console.log("user.loginToken = ", user.loginToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await axios.post(
|
|
|
|
const response = await axios.post(
|
|
|
|
`${BASE_URL}/stories`,
|
|
|
|
`${BASE_URL}/stories`,
|
|
|
|
{ token: user.loginToken, story: newStory }
|
|
|
|
{ token: user.logintoken, story: newStory }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const story = new Story(response.data.story);
|
|
|
|
const story = new Story(response.data.story);
|
|
|
|
this.stories.unshift(story);
|
|
|
|
stories.unshift(story);
|
|
|
|
console.log("this is what a single story looks like... ", story);
|
|
|
|
|
|
|
|
return story;
|
|
|
|
return story;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -105,7 +100,7 @@ class User {
|
|
|
|
username,
|
|
|
|
username,
|
|
|
|
name,
|
|
|
|
name,
|
|
|
|
createdAt,
|
|
|
|
createdAt,
|
|
|
|
favorites = [],
|
|
|
|
favorites,
|
|
|
|
ownStories = []
|
|
|
|
ownStories = []
|
|
|
|
},
|
|
|
|
},
|
|
|
|
token) {
|
|
|
|
token) {
|
|
|
@ -180,7 +175,6 @@ class User {
|
|
|
|
* of favorites for a partiuclar user
|
|
|
|
* of favorites for a partiuclar user
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async insertStoryIntoFavorites(story) {
|
|
|
|
async insertStoryIntoFavorites(story) {
|
|
|
|
|
|
|
|
|
|
|
|
const response = await axios({
|
|
|
|
const response = await axios({
|
|
|
@ -194,7 +188,6 @@ class User {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** second method - take a story instance and remove it from our array of
|
|
|
|
/** second method - take a story instance and remove it from our array of
|
|
|
|
* favorited articles
|
|
|
|
* favorited articles
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -207,14 +200,22 @@ class User {
|
|
|
|
data: { token: `${currentUser.loginToken}` }
|
|
|
|
data: { token: `${currentUser.loginToken}` }
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return currentUser.favorites;
|
|
|
|
currentUser.favorites = response.data.user.favorites;
|
|
|
|
|
|
|
|
console.log("response.data.user.favorites = ", response.data.user.favorites);
|
|
|
|
}
|
|
|
|
console.log("CU Faves ", currentUser.favorites);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return currentUser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Stopping point of sprint. instertStoryIntoFavorites and removedStoryFromFavorites
|
|
|
|
|
|
|
|
* are working functions.
|
|
|
|
|
|
|
|
* Building out UI for these fucntions is next step.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****/
|
|
|
|
|
|
|
|
|
|
|
|
/** When we already have credentials (token & username) for a user,
|
|
|
|
/** When we already have credentials (token & username) for a user,
|
|
|
|
* we can log them in automatically. This function does that.
|
|
|
|
* we can log them in automatically. This function does that.
|
|
|
|