diff --git a/CHANGELOG.md b/CHANGELOG.md index d42694d..a28553c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Calendar Versioning](https://calver.org). -## [Unreleased] +## [23.1] - 2023-08-04 + +A small update to fix a few bugs and add a changelog link to the PyPI page. + +### Fixed +* Name for db file +* New day not starting out empty +* Limit on sidebar posts ### Added * Changelog link to PyPI page diff --git a/src/words_tui/tui/app.py b/src/words_tui/tui/app.py index 809ca09..ab35680 100644 --- a/src/words_tui/tui/app.py +++ b/src/words_tui/tui/app.py @@ -3,7 +3,7 @@ from textual.app import App, ComposeResult from textual.widgets import Footer, Static -from words_tui.tui.db import Post +from words_tui.tui.db import Post, get_posts from words_tui.tui.text_editor import TextEditor @@ -29,6 +29,7 @@ def get_post_summary(post: Post) -> str: def get_sidebar_text(posts: list[Post]) -> str: + posts = get_posts() return "[bold] # Date Words/Goal[/bold]\n" + "\n".join(map(get_post_summary, posts)) @@ -44,12 +45,12 @@ class WordsTui(App): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) # TODO: Find a better place for this - self.posts: list[Post] = list(Post.select().order_by(Post.created_date.desc()).limit(10)) - todays_post: list[Post] = [post for post in self.posts if post.created_date.date() == datetime.date.today()] + self.posts = get_posts() + todays_post = [post for post in self.posts if post.created_date.date() == datetime.date.today()] if todays_post: - self.todays_post = todays_post[0] + self.todays_post: Post = todays_post[0] else: - self.todays_post = Post.create(content="") + self.todays_post: Post = Post.create(content="") self.posts.insert(0, self.todays_post) self.editor = TextEditor(id="editor") @@ -67,9 +68,7 @@ def update_word_count(self) -> None: self.todays_post.content = text self.todays_post.save() - posts = Post.select().order_by(Post.created_date.desc()).limit(10) - - sidebar.update(get_sidebar_text(posts)) + sidebar.update(get_sidebar_text()) def compose(self) -> ComposeResult: """Create child widgets for the app.""" diff --git a/src/words_tui/tui/db.py b/src/words_tui/tui/db.py index 59b63be..a394de1 100644 --- a/src/words_tui/tui/db.py +++ b/src/words_tui/tui/db.py @@ -14,6 +14,8 @@ class Post(BaseModel): content = TextField() created_date = DateTimeField(default=datetime.datetime.now) +def get_posts() -> list[Post]: + return list(Post.select().order_by(Post.created_date.desc())) def init_db(db_path: str): db = SqliteDatabase(db_path)