Mayank0255 / Stackoverflow-Clone-Frontend

Clone project of a famous Q/A website for developers built using MySQL, Express, React, Node, Sequelize :globe_with_meridians:
https://stackoverflow-clone-client.vercel.app
MIT License
543 stars 207 forks source link

Fix(#87): Add Some Basic Validations For Better UX #89

Closed ozair-dev closed 2 years ago

ozair-dev commented 2 years ago

I have added a function censorBadWords (which can take string, object or array of strings as arguments and convert the bad words to censored words) to the services directory and it is being used in the formSubmit before dispatching.

Screenshot from 2022-07-05 03-57-14 Screenshot from 2022-07-05 03-54-34

Please review the PR and let me know if you want more changes.

vercel[bot] commented 2 years ago

Someone is attempting to deploy a commit to a Personal Account owned by @Mayank0255 on Vercel.

@Mayank0255 first needs to authorize it.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Updated
stackoverflow-clone-frontend โœ… Ready (Inspect) Visit Preview Jul 13, 2022 at 8:08AM (UTC)
Mayank0255 commented 2 years ago

@ozair-dev

Not able to see the censorship working actually,

https://stackoverflow-clone-fronten-git-fbdb88-mayank2aggarwal-gmailcom.vercel.app/tags/penis https://stackoverflow-clone-fronten-git-fbdb88-mayank2aggarwal-gmailcom.vercel.app/questions/95e661a4-2364-4a1d-aa21-2fcf731d54d3 https://stackoverflow-clone-fronten-git-fbdb88-mayank2aggarwal-gmailcom.vercel.app/questions/957a9d9d-247d-4710-a55c-9bc2c99d388b https://stackoverflow-clone-fronten-git-fbdb88-mayank2aggarwal-gmailcom.vercel.app/questions/371f797c-b749-43ff-83c8-b6607e1bdc7b

ozair-dev commented 2 years ago

The censorship is applied when a new post, comment or answer is submitted. Please try adding a new post and test for yourself if it works. And if you don't like it this way! then I'll apply censorship to the post, answer, comment preview instead of submission stage

Mayank0255 commented 2 years ago

@ozair-dev I think you can remove censorchip from submission, as I think we can store uncensored data, and display with censorship

ozair-dev commented 2 years ago

@Mayank0255 sure, I will censor comments, answers, and the posts. But I think the tags should not be censored because what's the point of showing a tag named s**t? Instead, I won't allow swear words for tags while submission. By doing that, we wont get new abusive tags.

ozair-dev commented 2 years ago

@Mayank0255 please review the PR, I'hv censored the bad words in a way that only first and last letter is shown. Also note that some abusive words won't be censored when joined with other words, for example ass in assume wont be censored, like wise pooppoopoop wont be censored. This is just how the package (which I used for censoring) works. But you'll see that it works very well in common scenerios. Screenshot from 2022-07-07 01-20-59

Screenshot from 2022-07-07 01-27-08

Tags are not censored. Instead, they are detected at post submission and an error is shown Screenshot from 2022-07-07 01-33-44

Mayank0255 commented 2 years ago

@ozair-dev cool, One suggestion, can change the tags censor text to, "Inappropriate words are not allowed"

As the current text seems like that only tags cannot be Inappropriate ๐Ÿ˜…, though they can write inappropriate words for title and body but why tell them that

ozair-dev commented 2 years ago

One suggestion, can change the tags censor text to, "Inappropriate words are not allowed"

Can do, but

As the current text seems like that only tags cannot be Inappropriate sweat_smile, though they can write inappropriate words for title and body but why tell them that

If the title or body contain inappropriate words, it won't terminate the dispatching of the formData, so user is actually allowed to write inappropriate words there, but If the tags contain the inappropriate words then dispatching is stopped, so I specifically mentioned tags cannot contains inappropriate words. But I'll still make the changes as you have asked for.

ozair-dev commented 2 years ago

@Mayank0255 Just a quick heads-up before you merge the changes! While matching and replacing bad words, a bunch a regex operations happens behind the scenes on each post, comment and answer, and this makes the page loading very slow. And in my opinion, to avoid this, the data must be censored on each submission. So we don't have to use regex on page load. I don't know how big companies do these censorship on data, but as far as I know, we just can't (or shouldn't) do it after data retrieval.

Mayank0255 commented 2 years ago

By how much is the page loading time increasing?

ozair-dev commented 2 years ago

On my machine, it's taking about 43 seconds. IMO, each post takes anywhere from 100-300ms, (speed may vary depending on processor speed), so it is wise to censor bad words on submission.

ozair-dev commented 2 years ago

I'm busy these couple of days. Will try when I am free In sha'Allah.

Mayank0255 commented 2 years ago

I'm busy these couple of days. Will try when I am free In sha'Allah.

Sure, no problem

ozair-dev commented 2 years ago

I have removed censoring for posts on data retrieval and instead, I am censoring title and body of each PostItem.compoent component on render. It stills takes about 43 seconds for HomePage to load. And additional 43 seconds (more or less depending on amount of text and machine's speed etc) on each pagination.

Here in the screenshot, you can see in console how much time each text is taking to be censored. Even the amount of time taken to censor even a small string is not negligible

Long story short, censoring text on rendering also does not reduce the loading time.

Screenshot from 2022-07-12 15-53-12

Deploy the changes and see the time time taken to censor each text in console to get a better idea.

Mayank0255 commented 2 years ago

@ozair-dev

questions page is breaking

ozair-dev commented 2 years ago

fixed

Mayank0255 commented 2 years ago

@ozair-dev looks good enough, just remove the logs and I will merge

ozair-dev commented 2 years ago

Done

Mayank0255 commented 2 years ago

@ozair-dev Merged๐ŸŽ‰๐ŸŽ‰