Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Footer displays 'login' or 'logout' when suitable. #654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rtv/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
i : Display new messages
s : Show subscribed subreddits
S : Show subscribed multireddits
w : Save a submission/comment
w : Save a submission/comment
l : View comments, or open comment in pager
h : Return to subreddit
o : Open the submission or comment url
Expand Down Expand Up @@ -108,6 +108,10 @@
[?]Help [q]Quit [l]Comments [/]Prompt [u]Login [o]Open [c]Post [a/z]Vote [r]Refresh
"""

FOOTER_SUBREDDIT_LOGGED_IN = """
[?]Help [q]Quit [l]Comments [/]Prompt [u]Logout [o]Open [c]Post [a/z]Vote [r]Refresh
"""

FOOTER_SUBMISSION = """
[?]Help [q]Quit [h]Return [space]Fold/Expand [o]Open [c]Comment [a/z]Vote [r]Refresh
"""
Expand Down
2 changes: 2 additions & 0 deletions rtv/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def login(self):
else:
self.oauth.authorize()

self.refresh_content()

@PageController.register(Command('DELETE'))
@logged_in
def delete_item(self):
Expand Down
8 changes: 8 additions & 0 deletions rtv/subreddit_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def __init__(self, reddit, term, config, oauth, name):
self.content = SubredditContent.from_name(reddit, name, term.loader)
self.nav = Navigator(self.content.get)
self.toggled_subreddit = None
self.FOOTER = self.reload_footer()

def refresh_content(self, order=None, name=None):
"""
Re-download all submissions and reset the page index
"""

self.FOOTER = self.reload_footer()
order = order or self.content.order

# Preserve the query if staying on the current page
Expand All @@ -60,6 +62,12 @@ def refresh_content(self, order=None, name=None):
if not self.term.loader.exception:
self.nav = Navigator(self.content.get)

def reload_footer(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a great place to use a property, e.g.

@property
def footer(self):
    if self.reddit.user is None:
        return docs.FOOTER_SUBREDDIT
    else:
        return docs.FOOTER_SUBREDDIT_LOGGED_IN

Then all you would need to do is change the other pages to lowercase, e.g. for the subscription page

footer = docs.FOOTER_SUBSCRIPTION

and update the base class to use self.footer instead of self.FOOTER. I agree that uppercase no longer makes sense, and it was probably a questionable decision when it was added in the first place. If you want to change self.HEADER to lowercase at the same time I'm on board with it.

if self.reddit.user is None:
return docs.FOOTER_SUBREDDIT
else:
return docs.FOOTER_SUBREDDIT_LOGGED_IN

@SubredditController.register(Command('SORT_HOT'))
def sort_content_hot(self):
if self.content.query:
Expand Down