I think doing assignments in a ternary operator makes it pretty hard to see what's going on. Split this into an if/else.