class UIContext: context = "all" prev_context = "" data = { "feed": "", "post_url": "", "search_query": "", "items": [], } def revert_context(self): self.context, self.prev_context = self.prev_context, self.context def change_context(self, new_context): if new_context not in ["all", "feed", "unread", "search"]: raise NotImplementedError(f"There is no UI context {new_context}.") self.prev_context = self.context self.context = new_context # Clear data fields so there's no lingering state from previous context self.data["feed"] = "" self.data["post_url"] = "" self.data["search_query"] = "" self.data["items"] = []