I actually liked the scene where Brienne filled in the pages of the book for Jaime. They were both outcasts who developed a deep bond based on mutual admiration and respect. God knows they saved each other multiple times. And just like Jaime knew that Brienne deserved to be knighted and gain the respect of others, Brienne knew how much those pages in the white book meant to him. Plus, as Lord Commander of the Kingsguard, Brienne would have seen it as her duty to write down his good deeds.
That said, I'm probably one of the few people who is glad that Jaime slept with Brienne. Some people are calling it a mercy fuck, but I think of it as him giving in to his feelings for her. Jaime had prided himself on being faithful to Cersei, and he had never had sex with anyone else despite many opportunities. Thus, it was a big step for him to make the move on Brienne.
It has been clear for some time that he has had feelings for Brienne that went beyond respect. Go back to the scene where Jaime and Brienne were inside the tent outside Riverrun. Bronn not only talks about the way she looks at Jaime, he tells Pod that he knows Jaime would "fuck her." Why? Because he knows Jaime and senses his feelings for the female warrior. That's also the scene where Brienne tries to give Jaime back the Valerian Steel sword and he refuses it, telling her "it's yours. It will always be yours." The subtext is that a part of his heart will always be with her.
During a "Knight of the Seven Kingdoms episode," it's clear that Jaime has romantic feelings for Brienne. You can see it when he stares at her on the battlements while she is watching the sword training. Later on, you can see the shot of Tyrion looking up at his brother when he greets Brienne when she comes inside for warmth by the fire. It's obvious to Tyrion that his brother is really taken with this woman. The feelings the two had for one another are shown clearly during the knighting ceremony.
Is it tragic that Jaime decided to leave Brienne and go back and save Cersei or die with her? Yes. I wish he hadn't made that choice and had stayed with Brienne. In a way, it made no sense after he learned that she had hired Bronn to kill both him and Tyrion. And I think we all wanted him to come to his senses about his sister-lover after seeing so many people sacrifice themselves to fight for the army of the dead. But Jaime put up with her infidelities. He allowed her to ridicule him, reject him for not having a hand and to insist that Tommen had betrayed her when he demanded to know why his youngest son committed suicide. She refused to listen to him when he warned her repeatedly that they couldn't beat the Dothraki or the dragons. It was a toxic relationship through and through, and certainly one-sided on Jaime's part.
But I don't think that diminishes the fact that he had romantic feelings for Brienne, and allowed himself to express them, albeit temporarily. Cersei being pregnant with his unborn child also compelled him to go back. And I think that was one of the main reasons Jaime fought the army of the dead--he wanted a future for his child, and for Cersei. Sure, he was going to keep his promise to fight for the living. But he told Cersei correctly that they were dead either way if they betray the North.
Jaime's story is a tragic one. He was a man who tried to redeem himself in many ways, but ultimately gave in to his darker half. And what makes it all the more tragic is that I believe that Jaime would have stayed with Brienne if she had been the one who was pregnant and Cersei was not.