-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Articles can be "completed" #1
base: master
Are you sure you want to change the base?
Conversation
animation shows up on single words now - match left counter added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice changes, in particular also thanks for updating for the changes in MaterialUI!
I added some feedback on the stylistic/idiomatic level. I also believe the project was originally formatted using an automatic pretty-printer but I could be wrong. If not, it may make sense to configure prettier.js for the project and run it on the whole codebase once, this may be easier than hunting for small whitespace differences (some of which I had made comments for, so you can ignore these :))
(Note that I didn't get around to running the code yet)
src/ArticleList.js
Outdated
const [open, setOpen] = React.useState(false); | ||
const [content, setContent] = React.useState(''); | ||
const [notification, setNotification] = React.useState(''); | ||
const [articles, setArticles] = React.useState(fetch_articles()); | ||
const [level, setLevel] = React.useState(fetch_user_level()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the original code was not consistent either but maybe you could make it consistent in one swoop and remove the React.
prefix for the original two lines as well, so that it's the same as useParams
and useHistory
below?
src/ArticleList.js
Outdated
useEffect(() => { | ||
// TODO: check from state if all articles are completed -> level up! | ||
// use: | ||
if (articles.filter((article) => !article.completed).length == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using articles.every
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks! there is still a bit of rust on JS to take off :D
src/ArticleList.js
Outdated
const markAsComplete = (article_id) => { | ||
let updated_articles = articles.map( | ||
(article) => { | ||
return((article.id == article_id && !article.completed) ? {...article, 'completed': true}: article |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor style comments, I would have probably formulated it as:
articles.map((article) => article.id === articleId ? {...article, completed: true} : article)
Note camelCase instead of snake_case, the triple ===l, and changed whitespace
src/ArticleList.js
Outdated
) | ||
} | ||
) | ||
setArticles(updated_articles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, take the line from above and then insert it here:
setArticles((articles) => articles.map(...))
if you update a value in React, the recommended pattern is to use these update functions instead of reading the value first. This prevents using an out-of-date articles value if multiple "set"s happened before the next rebuild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right.
I initially made the all-articles-completed check on this function; as setState methods won't reflect state changes immediately I was using the tmp variable as a workaround. I figured there's the useEffect function for this purpose but forgot to edit the line :)
Also, react-dom inherently treats URL params as strings; will force casting on the next commit to add the strict equality here.
src/ArticleList.js
Outdated
|
||
} | ||
|
||
function get_article(article_id){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider changing to camelCase as well :)
src/articles/Article.js
Outdated
Setmatch_left(match_left - 1) | ||
} | ||
|
||
const reactStringReplace = require('react-string-replace'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wow this worked? I didn't know you could that tbh :D
I believe the more idiomatic approach (correct me if I'm wrong for this library) would be to move it to the very top of the file and use esmodule-style imports, along the lines of import { reactStringReplace } from 'react-string-replace;
or similar.
src/ArticleList.js
Outdated
'id': 0, | ||
'completed': false, | ||
'title': 'Apple Pie', | ||
'content': 'German Apple Cake is a traditional German dessert that is so easy to make even if you aren’t totally kitchen confident! With a simple batter that rises up and bakes around the apples this easy apple coffee cake is the perfect everyday dessert that tastes best with a dollop of whipped cream on top.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you replaced the content with the preview? At least when I open an article, I also only see this short text, rather than the steps and methods, as in ApplePie.js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup. can fix it easily but I am actually craving for a model and a migration with all articles to be run on init so we can clean up this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in the long run that would definitely be more convenient.
src/ArticleList.js
Outdated
'id': 2, | ||
'completed': false, | ||
'title': 'Capitain Bluebear', | ||
'content': 'The 13¹⁄₂ Lives of Captain Bluebear is a 1999 fantasy novel by German writer and cartoonist Walter Moers which details the numerous lives of a human-sized bear with blue fur.apple', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there "apple" at the end of almost every article? Might be something we had for the demo, but we probably should remove it now :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for the demo right, you need at least one word to guess on each article or you won't be able to complete it and level up (laziness got real here and I just added apples everywhere sorry) :D
|
||
const handleSubmit = (answer) => { | ||
if (confirmWord(german, answer)) { | ||
setSuccess(true); | ||
setOpened(false); | ||
onComplete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this being triggered? I got all words to "white" in the apple pie article, but it wasn't marked as completed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think the problem was that I had to click on every occurrence of the world "apple" again, even though it was already white.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly! You have to guess all the words to complete an article (: just like an exercise. but the interface is confusing now.
Since the beginning, I thought we have to change the confetti effect to be only on the occurrence of the word you guess. it is a bit counterintuitive atm (now even more with this update) - will look at it
package.json
Outdated
"proxy": "http://localhost:8000" | ||
"proxy": "http://localhost:8000", | ||
"devDependencies": { | ||
"prettier": "2.4.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
strict comparison on URL, removed commented routes, camel case refactoring
- Partial translation component is now loaded correctly into the DOM even when an article contains html tags - Old articles body restored - Minor warning from Material UI fixed
Alright, |
Each time all the words for a given article are guessed, the article is marked as completed and the user interface gets updated. Once all the articles from the level are completed, the user is moved to the next level and loads harder articles (still static).
The idea: each user has a level and on each level, we fetch a list of articles, progressively more complex and with a new vocabulary. Hence the user is supposed to find and learn a bunch of new words per level.