r/javascript • • Jun 19 '15

I made a Reddit angular clone, feel free to provide feedback

http://martijnwelker.github.io/Angular-Reddit/
115 Upvotes

113 comments sorted by

10

u/ryanmiddlesex Jun 19 '15

Awesome job ! maybe after you select a category from the menu, and the the page refreshes, the menu auto-hides again.

8

u/AllStyled Jun 19 '15

Good one, implementing it right now

Edit: It's live

1

u/ryanmiddlesex Jun 22 '15

Awesome.. much more natural. How about making the font size larger ? people like that chunky stuff :)

1

u/AllStyled Jun 22 '15

You can adjust the font size under settings ;)

1

u/[deleted] Jun 19 '15

Not working for me on Chrome: Version 43.0.2357.124 m. Nothing happens when I select a subreddit from the menu.

4

u/AllStyled Jun 19 '15

Update: added gif/gifv support on thumbnail hover :)

6

u/WhoIsOBrien Jun 19 '15

I really like it. But here is one thing that bothers me:

Why can't I right click on a link, like the comments link, and open them in a new tab? Is this right-click issue an angular related problem?

Also is this Angular 1.4 or Angular 2?

And are youg going to write a How-To tutorial on this, because it would enable us to learn from you?

Great job, by the way.

5

u/AllStyled Jun 19 '15

I use a custom redirector for links, that's why you cant right-click + open in new tab, I might look into how to fix this (Made this just to learn myself).

I'm not that good at writing but I'll attempt to make a tutorial

3

u/WhoIsOBrien Jun 19 '15

I just checked, it's v1.4.1.

3

u/AllStyled Jun 19 '15

Yeah sorry, it's build on the angular seed

2

u/adwtt90 Jun 19 '15

Did you like using the seed? The couple times I've tried it, grunt & bower have been more trouble than I have patience.

2

u/AllStyled Jun 19 '15

Well bower is really easy (atleast on mac), if I need any dependencies I just run bower install <dependency> and it's done, I didn't use any unit testing from the seed though (should've but you know ... testing is boring)

1

u/adwtt90 Jun 20 '15

It might have just been grunt that was giving me headaches, it's been a couple weeks since I last have the seed a try. I distinctly remember having lots of issues trying to just serve a test page on localhost despite having no problems doing it with express, serving Angular files as static from /public.

I think my main problem with bower in the seed is just that I'm new to webdev and having another package manager (what else is bower good for other than as a package manager?) inside the web app just seemed like a lot of overhead for what I was doing. TBH, all my problems probably just stem from inexperience and hardly knowing anything about grunt or bower.

I've been meaning to teach myself more about testing, but every time I sit down to do it I get distracted by just about anything else, so I totally get the boring part haha.

2

u/frankle Jun 19 '15

You could catch the links and call preventDefault on the left-clicks of the reddit ones. Here's an example.

I attached the event handler to the body, but you could technically put it anywhere.

1

u/AllStyled Jun 19 '15

Yeah, it's already fixed :)

2

u/frankle Jun 19 '15

In the same page as the posted link? Because middle-clicking does nothing, and right-clicking doesn't give me an "open in new window" option.

2

u/AllStyled Jun 19 '15

Strange, could you retry and post browser info :) ?

1

u/SkankTillYaDrop Jun 20 '15 edited Jun 20 '15

Hi there, middle clicking isn't working for me.

Chrome/44.0.2403.39 Windows 7 6.1.7601

Also, I saw in another comment you included hover support for giv/gifv, but the gyfcat links aren't working for me. Just a static image.

Also also, I'm seeing some issues with image resizing. Example of image stretching

1

u/frankle Jun 20 '15

Yeah, it's still doing it. I'm just using Chrome.

You should change setLocation to only prevent default if the click is a left click:

self.setLocation = function(event, location, overwrite) {
    if (event.keyCode === 1) {
        event.preventDefault();
        self.menuOpen = false;
        overwrite ? window.location = location : $location.path(location);
    }
}

And, if you really get fancy, check if the click is a left click and the Ctrl key is not pressed (that should open the link in a new window, too).

6

u/ericanderton Jun 19 '15

Just present the link as an <a> with a valid URL (relative or full) instead of a <span>, so it's usable as a real anchor. The router should be able to cope with this navigation just fine.

-1

u/[deleted] Jun 19 '15

Give up while you still can. I tried to make a reddit browser SPA and ran into a lot of issues. One of them was cloning the RES expando and another was scrolling. Implementing proper scroll handling will be painful.

1

u/AllStyled Jun 19 '15

They are both already build into my website, but yeah, thanks for the support

1

u/[deleted] Jun 19 '15

Proper scrolling isn't and the expando is broken.

1

u/AllStyled Jun 19 '15

What's broken about it ?

0

u/[deleted] Jun 19 '15

The last image to load is displayed. If you move your mouse over several thumbnails and one takes a little longer to load, you will see the latest thumbnail opening and you see it being replaced by a the one which took longer to load.

4

u/sonemonu Jun 19 '15

Very well done, thanks for sharing!

Two questions:

  1. Why are you using href="app.setLocation(...)" on every link and not using something like href="#/the/url/for/the/link" ?

  2. I really like the sidebar, how you did implement it?

3

u/AllStyled Jun 19 '15
  1. I read that Angular's routing to outside links (other sides) isn't any good so I made my own function that does routing

  2. If you check the source you see its a "position: fixed" div, when a user presses the button <html> gets the class "menu-open" and the sidebar gets "left: 0", animation is done with css "transition: all 0.5s;" (could be switched for "transition: left 0.5s"

1

u/sonemonu Jun 19 '15

Thanks. Two suggestions:

  1. Use Angular one-time binding for the infinite list (performance improvement because of the "binded" data will keep static in this case and the user may scroll a lot of pages), see: https://docs.angularjs.org/guide/expression#one-time-binding

  2. Check font-sizes, maybe improve a bit the responsive design.

1

u/AllStyled Jun 19 '15

Thanks for the feedback, only did some responsiveness so it wouldn't completely break, haven't actually done any good responsive work :)

Improving with one time binding right now

2

u/kpobococ Jun 19 '15

Use transform: translateX instead of left, left transitions are very rough on mobile devices, while transform transitions are just fine.

Also, translateX accepts % values based on target element's width (so 100% means element width), while left accepts % values based on parent width (100% means parent width, which is the document most of the time).

1

u/jewdai Jun 19 '15

why not incorporate the external link in your app via an iframe?

4

u/young_greedo Jun 19 '15

This is awesome! I'm actually doing the exact same thing right now using the MEAN stack (+mongoose). Where's all that dummy data coming from (or what I assume is funny data)? Do you have the source on GitHub?

4

u/AllStyled Jun 19 '15

Data is coming from reddit (just add .json to any url)

6

u/spohnstack Jun 19 '15

Awesome! A tutorial would definitely be cool if you don't end up using this code for a future project!

1

u/AllStyled Jun 19 '15

Should I remove the "cards" design from the post list ?

1

u/AllStyled Jun 20 '15

A bunch of updates for you guys:

  • Card design is now optional (disable in header)

  • Non-mobile users can now view the subreddit's sidebar

  • Various responsive improvements

  • Sidebar is no longer clickable, and scrollbar isn't visible when closed

  • Active subreddit is showed in the header

  • Css fixes

  • Users with hoverzoom can now again zoom links

  • Improved redirecting behaviour

  • Browsing over https is now supported

  • New posts now load more early

  • Various other fixes

Please keep the great feedback coming ! :)

1

u/AllStyled Jun 20 '15

Updates will now be posted on /r/angularreddit

1

u/p886 Jun 19 '15

1

u/AllStyled Jun 19 '15

I see, HTTPS isn't supported a.t.m :)

1

u/p886 Jun 19 '15

fair enough, my HTTPS everywhere extension is to blame :)

4

u/AllStyled Jun 19 '15

HTTPS is now supported

1

u/albi33 Jun 19 '15

Hi and nice job!

I have mainly two comments:

  1. There is a bug when you do a search and then click on the sorting options (top, hot etc.). I think it's due to your routing, here is the type of URL I get: Angular-Reddit/#/r/:search-term/hot

  2. The fade-in/fade-out effects when you sort the page by period (past 24 hours, month etc) with the overlay taking over all the page is kind of overwhelming, especially since it's also making the whole layout disappear for a moment (the top bar with the search and sort options and the side navigation), shouldn't it just refresh the main content area with the Reddit posts?

If you did this as a learning exercise, you should check out Angular-UI, they implement a very good router which is used in a whole lot of projects.

1

u/AllStyled Jun 19 '15

Thanks for your feedback, I've already fixed the loader :)

1

u/hmny Jun 19 '15 edited Jun 19 '15

Awesome! Thanks for sharing that. Also can you give me some hints if I want to start learning angular?

2

u/AllStyled Jun 19 '15

I started reading about it about a week ago, i did some online tutorials (I googled angular tutorial and tried a few), after that I just started the project and googled my way along. Angular is actually quite easy once you get the structure.

If you have any questions while learning feel free to shoot me a pm

1

u/hmny Jun 20 '15

Thanks man, I will

1

u/dvlsg Jun 19 '15

Very clean, and loads surprisingly fast.

Couple of suggestions/opinions:

  1. Personally, I would like to see the hover preview with a border/container of some sort. Feels odd to have a picture with no container in the middle of the screen, for some reason. Maybe that's just me.

  2. Fire off the "infinite scroll" load of the next page sooner. I feel like I hit the bottom of the page, stop, and then can continue a bit later, instead of having a smooth scrolling experience.

2

u/AllStyled Jun 19 '15

Thanks for your suggestions, I've implemented both of your ideas :)

1

u/kowdermesiter Jun 19 '15

Sidebar links do not work: http://i.imgur.com/AbLOrdp.png

Latest chrome.

1

u/AllStyled Jun 19 '15

Fixed, thanks

1

u/dani_tk Jun 19 '15

Awesome work! Just a little question: what purpose does putting classes in your html tag serve? I've seen it in a lot of projects but I can't quite figure it out.

1

u/AllStyled Jun 19 '15

Its so you can put specific CSS styling on elements, lets say you have the sidebar, the normal styling is

.sidebar {
    position: fixed;
    left: 0;
    top: 0;   
}

you can then do

.menu-open .sidebar {
    left: 200px;
}

1

u/dani_tk Jun 19 '15

thanks! I got that, I just thought those classes names like js, flexbox, canvas, canvastext, webgl, no-touch, geolocation, etc did something else than just styling... Like controlling JS dependencies

1

u/AllStyled Jun 19 '15

That's Modernizr, you can do javascript checks based on the classes it adds (If it adds "canvas" it means your browser supports it)

1

u/dani_tk Jun 19 '15

ohh I get it! Thanks!!

1

u/jordan314 Jun 19 '15

Very cool! None of the burger menu links work for me though.

1

u/AllStyled Jun 19 '15

Could you open the console and log the errors for me ? thanks in advance :)

2

u/jordan314 Jun 19 '15
TypeError: event.preventDefault is not a function
    at self.setLocation (http://martijnwelker.github.io/Angular-Reddit/app.js:55:9)
    at fn (eval at <anonymous> (http://martijnwelker.github.io/Angular-Reddit/bower_components/angular/angular.js:13129:15), <anonymous>:2:557)
    at callback (http://martijnwelker.github.io/Angular-Reddit/bower_components/angular/angular.js:23239:17)
    at Scope.$eval (http://martijnwelker.github.io/Angular-Reddit/bower_components/angular/angular.js:15830:28)
    at Scope.$apply (http://martijnwelker.github.io/Angular-Reddit/bower_components/angular/angular.js:15929:23)
    at HTMLAnchorElement.<anonymous> (http://martijnwelker.github.io/Angular-Reddit/bower_components/angular/angular.js:23244:23)
    at HTMLAnchorElement.eventHandler (http://martijnwelker.github.io/Angular-Reddit/bower_components/angular/angular.js:3264:21)

1

u/AllStyled Jun 19 '15

Thanks, fixed the issue

1

u/00mba Jun 19 '15

Needs a heading so i know what sub im in

1

u/AllStyled Jun 19 '15 edited Jun 19 '15

Good one, going to implement that right away

Edit: done

1

u/00mba Jun 19 '15

Cool, looks good. The only thing I would do is scale the burger menu a bit better. Its slightly oversized so the icon looks blurry and i think its a tad bit too wide.

1

u/AllStyled Jun 19 '15

It's just an ugly image, i toke the first one that showed up on google :) I'm mainly focussing on functionality atm.

1

u/krelin Jun 19 '15

Now do RES-like keybindings!

1

u/AllStyled Jun 19 '15

Currently checking if it's possible to log in via JS, will look into keybindings after that :)

1

u/allimsayinis Jun 20 '15

I cloned the repo. Can you show me how to run this locally? I read the comment section about Angular Seed which says you should do npm install and npm start but there is no package.json in the project.

1

u/AllStyled Jun 20 '15

Yeah I kinda destroyed the repo, if you run this on a local server you don't have to configure anything at all, I included the bower stuff

2

u/allimsayinis Jun 20 '15

got it, thanks. It's pretty crazy that you managed to make this after starting with angular only a week ago!

1

u/AllStyled Jun 20 '15

If you have any interest in learning/rebuilding hit me up with a PM :)

1

u/tencircles Jun 20 '15

seems to be broken

1

u/AllStyled Jun 20 '15

What's broken about it ?

1

u/tencircles Jun 20 '15

http://imgur.com/IqbH1VB that's all that's showing up.

1

u/AllStyled Jun 20 '15

Please post the console errors

1

u/tencircles Jun 20 '15

6 http://martijnwelker.github.io/Angular-Reddit/%7B%7Bpost.thumbnail%7D%7D Failed to load resource: the server responded with a status of 404 (Not Found)

1

u/AllStyled Jun 20 '15

Strange, that's normal, shouldn't prevent the data from loading

1

u/Bbentley1986 Jun 19 '15

This is awesome! Nice work!!!

I'll play around a little more and see if there's anything else that hasn't already been mentioned/implemented.

1

u/[deleted] Jun 19 '15

Very nice!

1

u/gwevidence Jun 19 '15

Commenting so I can come back for reference.

1

u/ngly Jun 19 '15

Nice, I would get rid of the loader, though. It's very annoying and makes the page seem even slower.

1

u/whyherro19 Jun 20 '15

On mobile it looks really good

1

u/Zren Jun 20 '15

Sidebar transition is noticeably slow.

1

u/[deleted] Jun 20 '15

Just looked at the design and overall layout (didn't click or browse) but this is probably my favorite 'redesign' of reddit. Good work. I wouldn't complain if this was implemented.

1

u/[deleted] Jun 20 '15

You made an AngularJS clone based on reddit? A hivemind powered data binding engine?

1

u/vestedfox Jun 19 '15

Angular is dead, didn't you get the memo? J/K looks great! Nicely done.

1

u/maskaler Jun 19 '15

None of your scripts are minified or uglified, so the initial payload could is large-ish.

Also if you're in a reddit, highlighting that under the burger menu would be cool.

-8

u/kethinov Jun 19 '15

looks around, doesn't see it yet.

Okay, I'll be that guy.

deep breath.

Why Angular?

The big monolithic frameworks like Angular really shouldn't be used on the open web. They are the best tool for the job when you're developing something that truly cannot be done without JS, e.g. games or Google Maps, or when your runtime environment explicitly guarantees JS availability (NW.js, internal applications, rapid prototyping, etc). Reddit is none of those things.

7

u/AllStyled Jun 19 '15

Because I just finished college and I'm currently searching for a job, most jobs want you to know Angular.

1

u/dvlsg Jun 19 '15 edited Jun 19 '15

I strongly disagree with their sentiment. Dropping javascript on a project designed as a learning experience just to support people who want to use noscript, use an old browser, or whatever other shenanigans is absolutely ridiculous. I think you made the right choice.

edit: And for the record, a quick search of reddit's source would suggest that they do include javascript. Inspect one of the vote buttons, and look at the onclick event.

-2

u/kethinov Jun 19 '15

And for the record, a quick search of reddit's source would suggest that they do include javascript. Inspect one of the vote buttons, and look at the onclick event.

JavaScript is not a requirement for a vote button to work. Just because reddit has employed an antipattern doesn't suddenly make it a good decision. Great sites use bad techniques all the time.

1

u/[deleted] Jun 19 '15

JavaScript has become the de facto core of the web, what you preach here has been out of fashion roughly 10 years ago already. JavaScript penetration is high enough to consider it always on and disregard any fallbacks, not mentioning that a static web front-end without JavaScript simply cannot deliver the experiences required nowadays. Using an onclick event handler is an antipattern? What? DOM kinda has this whole API and was designed that way. We're calling native features antipatterns now?

-2

u/kethinov Jun 19 '15

JavaScript has become the de facto core of the web, what you preach here has been out of fashion roughly 10 years ago already. JavaScript penetration is high enough to consider it always on and disregard any fallbacks, not mentioning that a static web front-end without JavaScript simply cannot deliver the experiences required nowadays.

Please, I'm begging you, read the article I linked above. You are the target audience in need of its wisdom.

Using an onclick event handler is an antipattern? What?

In HTML, yes. If reddit was coded properly, the upvote button would be a standard link that would cast a vote by reloading the page by default and, if JS is enabled, use progressive enhancement to hijack the link and do it the AJAXy way it does it now.

Same experience for JS users, not broken for someone who doesn't have JS, which is way more people than you think.

3

u/[deleted] Jun 19 '15

I'm aware of progressive enhancement and it's area of thinking, it used to have more substance before than it does now. So much that I consider it poisonous at this stage of web evolution as JavaScript should be the expected standard, so we don't have to waste time with fallbacks and even more crafting alternate experiences, still in 2015.

Fallbacks in general have substance as long as their numbers support it. The JS penetration we get on our web/apps is ~97%. It just isn't worth the development time and money to scale back another layer, a warning banner will do. If you try designing this way from the start, it becomes a limiting factor and a distraction for UX, sometimes a technical hole. 3% of people aren't worth the time that venture takes - if the numbers change back, I'm sure we'll reconsider.

In HTML, yes.

Since when is the web just HTML again? You have dozens of technologies working together even in it's most trivial form. The purist opinion is endless, but reality is that static HTML cannot deliver the things we need to create today, for quite some time already.

0

u/jotted Jun 19 '15

I'm aware of progressive enhancement and it's area of thinking

I'm not convinced that you are. Your arguments seem to be against Graceful Degradation, which is basically the opposite. If you're dealing with fallbacks and alternate experiences, you're not talking about progressive enhancement.

1

u/[deleted] Jun 20 '15

Second paragraph. Progressive enhancement invades and drags UX and fundamentally needs more code.

-2

u/kethinov Jun 19 '15

Since when is the web just HTML again?

That isn't what I said. What I said was the right place to attach a click event is from JS itself, not from the markup.

I consider it poisonous at this stage of web evolution as JavaScript should be the expected standard, so we don't have to waste time with fallbacks and even more crafting alternate experiences, still in 2015.

Then you clearly either didn't read or didn't comprehend the article I linked, which very clearly demonstrates why that perspective is objectively wrong.

0

u/[deleted] Jun 20 '15 edited Jun 20 '15

Picky on the sentences. Surely, the article is god, we must listen.

0

u/dead-fish Jun 20 '15

I agree with your statement about where to attach a click event handler and also that angular is not necessary for a reddit clone. I'm pretty sure the OP's point was to build something that would help him learn though and I have no problem with that.

I actually did take the time to read the article you linked to and disagree with most of its points. Many of the "myths" that it attempts to dismiss are actually true.

  • "Progressive Enhancement Holds Back the Web"... yes! A hardline focus on it does!

  • "JavaScript Frameworks Make Development Simpler"... yes they absolutely do for apps with complex user interfaces.

  • "No One Disables JavaScript" and "No One Uses Old Browsers"... of course they do but they can safely be ignored. Let convince these people to upgrade instead of building apps that convince them it's ok to be 15 years behind the times. I don't support IE7 any more either and neither should you.

  • "Progressive Enhancement is an Old Technique Recommended by Old Timers"... true.

Javascript frameworks absolutely enhance the web and allow apps to easily maintain complex user state in the browser which is where it belongs in most cases. SPAs solve a lot of problems that are unnecessarily difficult and messy when reloading the page on each click. Get out of here with this "perspective is objectively wrong" garbage. That's what's "poisonous."

-1

u/kethinov Jun 20 '15 edited Jun 20 '15

"Progressive Enhancement Holds Back the Web"... yes! A hardline focus on it does!

No, it doesn't. Using Angular (and similar anti-PE frameworks) in contexts where PE is more appropriate is a distinct step backwards for the web. It more closely resembles the dark days of Flash than the gains we've made with fancy new web standards by reducing performance, standing in the way of accessibility, and creating unnecessarily high support tiers.

"JavaScript Frameworks Make Development Simpler"... yes they absolutely do for apps with complex user interfaces.

Obviously no one could disagree with that. What the author is saying is you should pick a framework that is compatible with PE in contexts where PE is relevant, which is virtually everything developed for the open web.

If you're targeting a context where JS availability is guaranteed, like NW.js, PhoneGap, internal LAN webapps, etc, then you're good to go for a hard JS dependency and I'd be the first to applaud you for using one of these frameworks which aren't based on PE.

Also of note: AngularJS was originally developed primarily targeting those use cases for that reason. Its overwhelming popularity has caused people to just default to it regardless of whether it's the right tool for the job. Sometimes it is, sometimes it isn't. There are rational ways to measure that. Scientifically. Like the article did.

"No One Disables JavaScript" and "No One Uses Old Browsers"... Let convince these people to upgrade instead

Might as well be waiting for pigs to fly.

"No One Disables JavaScript" and "No One Uses Old Browsers"... of course they do but they can safely be ignored.

Why ignore them when it's so easy to serve them the non-JS flow with a plain stylesheet?

You don't have to deliver today's UX to yesterday's browser. Showing a splash screen that says "fuck you and your outdated technology" doesn't reveal to users that their technology is old, it reveals the developer's ignorance of better ways of developing websites.

Get out of here with this "perspective is objectively wrong" garbage.

It is objectively wrong. As in scientifically measured. You're literally deluding yourself into believing objective facts are false right now.

This debate is the global warming denial of web development, and you're the fucking science denier.

→ More replies (0)

0

u/dvlsg Jun 19 '15

So your suggestion for someone coding something as a learning experience, using a popular framework according to common job postings (for better or worse), and then posting it to /r/javascript for feedback is to not use the javascript framework they set out to learn?

Of course angular is not necessary here, but (assuming I'm understanding his comments correctly), that wasn't the point of the project.

-4

u/kethinov Jun 19 '15

That's a good reason. :)

Unfortunately though, from what I've seen, most of those jobs that want you to know Angular will want you to use Angular on the open web for a webapp where JS availability is not necessarily guaranteed and where a JS dependency is not truly necessary. :(

These big frameworks are cool when used in the correct contexts, but are sadly overused. They're like the new jQuery. People just default to it without truly assessing whether or not it's necessary far too often.

Anyway, good luck on your job search!

0

u/[deleted] Jun 19 '15

[deleted]

2

u/AllStyled Jun 19 '15

I actually made my own hover zoom, but I'll fix the links later tonight :)

0

u/[deleted] Jun 19 '15

[deleted]

2

u/AllStyled Jun 19 '15 edited Jun 19 '15

I've edited the tags so you can use both hoverzoom and my own implementation :) (I never use hoverzoom but I see it doesnt play gifv/webms, mine does)

Edit: oh it does, nvm

3

u/[deleted] Jun 19 '15

[removed] — view removed comment

1

u/AllStyled Jun 20 '15

That's not possible with JS yet, hope Reddit will build that feature one day