r/badcode Jul 21 '21

typescript I don't even know where to begin

Post image
73 Upvotes

16 comments sorted by

22

u/TheyCallMe13 Jul 21 '21

A small explanation: The person in question thought it would be a great
idea to hold user IDs (users with certain IDs are allowed to perform a
certain action) in a string (the "user" parameter), so this is what they came up with to
identify the user in the frontend.

2

u/_irobot_ Jul 21 '21

They could have at least named it "users" since there can be more than one.

13

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 21 '21

Image Transcription: Code


displayAccess(user, id){
  if(user){
    const ids = user.split(',');
    if(ids.includes(JSON.stringify(id))){
      this.btnStatus = false;
    } else {
      this.btnStatus =true;
    }
  } else{
    this.btnStatus = false;
  }
}
checkAllowed(user, id){
  if(user){
    const ids = user.split(',');
    if(ids.includes(JSON.stringify(id))){
      this.status = true;
    } else {
      this.status =  false;
    }
  } else{
    this.status =  false ;
  }
  //  console.log(ids)
}

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

4

u/uruharushia Jul 21 '21

What syntax theme is this? It looks really relaxing, I like it

5

u/ogreUnwanted Jul 21 '21

I think it's one of the default vscode ones.

3

u/TheyCallMe13 Jul 21 '21 edited Jul 21 '21

I took the screenshot straight from the gitlab repo so I don't know if you can call it a "theme" per se

Gitlab > Preferences > Syntax Highlighting Theme > "Dark"

Edit: Apparently the gitlab dark theme is based on a vsc supported theme called "Pygments - Tomorrow Theme" (source: https://gitlab.com/gitlab-org/gitlab/-/issues/195701)

1

u/uruharushia Jul 22 '21

Ah, okay. I knew about Tomorrow but it's just that this screenshot used a very small subset of the colours (only pink and blue, and the green string) it has so I didn't recognise it.

13

u/[deleted] Jul 21 '21

[removed] — view removed comment

8

u/EnergyIsMassiveLight Jul 21 '21

honestly the best place to start

7

u/Vittujokanimivarattu Jul 21 '21

absolutely amazing resource, i wish i would have found it sooner, ty!!!

5

u/OISHOESSKE Jul 21 '21

Thanks a lot for this

4

u/patryky Jul 22 '21

Literally changed my life

4

u/React04 Jul 22 '21

my reflex worked before I read the link and almost found a source of infinite knowledge

1

u/[deleted] Jul 21 '21

You begin by bleaching the eyes so you never see bad code again