Skip to content

Commit

Permalink
Prepare 23.1
Browse files Browse the repository at this point in the history
  • Loading branch information
anze3db committed Aug 4, 2023
1 parent 21b5658 commit c027f8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/words_tui/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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))


Expand All @@ -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")
Expand All @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions src/words_tui/tui/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c027f8f

Please sign in to comment.