-
Editing Bookmark / Reply Titles with HTMX
byThis post is a followup to Allow editing of replies/titles and describes some of the changes made to enable this functionality (#265) and my thoughts after my first steps with HTMX.Unable to change bookmark / reply titles βΉοΈ
Above is the before state, which is a static view of title/url of a bookmark/reply. Below is aΒ gif of what I built and the finished state. There's a new change button, which you can click to reveal a form that allows you to edit the record. This form allows you to save or cancel. Save updates the record and changes the screen back to the "read only" view, while cancel just loads the current "read only" view. Zero custom Javascript.Editing a bookmark url / title in Tanzawa
Powering this is two new simple views in the admin site. One loads the entry's bookmark/reply and returns the read only view. The other loads the same record and displays a form on get, updates it on post.
The htmx and these two small views were the simple part of this feature. The heavier lift was decoupling the Tanzawa micropub endpoint from the admin views/forms, and then updating the admin views to no longer expect IndieWeb extension data (reply/bookmark url/titles etc...) on update (it's still required on create).
Thankfully I had functional tests for my micropub endpoint, so I could be confident that my refactoring didn't break existing functionality. Those tests allowed me to extract the logic from the admin forms and put them into a application function. This new application functions are reused by all interfaces creating/updating entries.
The next phase was adding tests to the admin views and then updating them to use the common application functions. This work was mostly a slog because I needed to add tests and better factories for my tests before doing the actual refactor. There's still more improvement that can be made in the test factories to make them a bit more DRY, but they're good enough for now.
Working with HTMX has been a dream. Rather than usingΒ Javascript to tweak DOM, I can simply make calls to the backend to get html from the backend by adding just a couple of attributes to my template dom. All of this using the same django templates.
My next steps with HTMX are going to be to look into integrating django-components, so I can wrap up the Javascript I do need with the their templates/css and do some more refactoring. For example, right now reply/bookmarks have effectively the same templates / views duplicated. Using components, I should be able to have a single logical component to power both.
If the components strategy works, I will look at breaking out various parts of Tanzawa into htmx/django-components for easier maintenance e.g. the location selector or location view on the bottom of checkins. -
Response to
byThis PR started as an experiment with HTMX to allow Tanzawa to edit reply/bookmark titles. As all of the entry creation forms/views are inherited from similar base-classes for easy/speed of initial...
I've re-worked all of the create/update views for each post type to use application functions and added functional tests. Editing the url/title for reply posts, works really well. HTMX is allowing me to create the simple interactions I want without Javascript.
The biggest change is reply data is no longer updated all at once with the rest of the post, but rather when you finish editing the title/url, similar to how editing a GitHub PR title works.
The last bit that I think needs some more work, unrelated to the rest main objective of his issue, is the first step when creating a reply where I request the URL to, and it uses Turbo to fetch the meta-data / return a page that can create a reply.
This flow may need a bit more yak shaving so it doesn't use Turbo at all. Will give it a fiddle to see if I can refactor and simplify the flow using HTMX. -
The Week #129
by- After years of regularly and then sporadically saving for retirement, I've finally automated it again...kinda. If I were in the US, I'd have access to regular retirement accounts and things could be deducted in a tax efficient way from my pay check. As an American, I also can't take advantage of any non-US retirement savings schemes (π€ͺ). So what I'm basically left with is depositing some amount into into a regular taxed brokerage account.
What I've setup is: an automatic from Wise to my US bank account, and a few days after an automatic withdrawal from my US bank account to Vanguard. The two bits I can't automate are: the wire/furikomi from my Japanese bank account to Wise and once the money is actually in Vanguard, purchasing of ETFs (VOO index funds, mostly). My hope is that Wise will send me an email with the amount I need to send in yen each month (because exchange rates change). - Setting this up makes really happy. It's been one of those tasks in the back of my head for quite a while and the crap exchange rate made it even less attractive. The exchange rate is still horrible (but less so). I reckon it will all even out in the end. But perhaps the best bit is I discovered I can now purchase fractional ETFs.
I'll explain. Let's say I have $200, and I want to buy 1 share of VOO (a S&P 500 index fund) that I'll sell off when I rewrite, and it costs $350. Normally,I have to hold my $200, not earning anything, wait until I had $350 and hope that by the time I did the cost hasn't risen to $400 and make my purchase. Now I can just buy $200 worth of the stock, which makes it much easier to invest the same amount each month, no matter the price of the stock. - There was a bunch of noise on the bird site with the owner doing stupid, stupid shit. Like blocking linking the other sites stupid. ON THE INTERNET. :facepalm: Good riddance. So glad I've made my home on the internet my own domain / IndieWeb enabled.
- I've been making really good progress on my major refactoring of the Tanzawa. This has me mostly pulling logic out of ModelForms and moving them into application/domain functions that I can reuse throughout my site. The create methods have been refactored and the update methods are mostly so. I reckon I'll need another pass at views themselves as they're a bit crufty, still.Β
- We had a Christmas social at work to celebrate the year and it was a lot of fun. We've grown so much in the past year. We went to Soul Food House in Tokyo. I've been wanting to try that place for years, but it's in central Tokyo β some place I'm not going to go unless I'm in the area. Maybe it was the classic American cooking, or maybe it wasΒ the Christmas poem read in an English accent, but it finally felt like Christmas is starting.
- Friday was Leo's Christmas pageant where the school puts on a play about the birth of Jesus andΒ then they sing some Christmas songs. When thinking about the amount of chaos you'd expect at a pre-school production of...anything, and then reflecting on the various happenings (kids crying, kids running around, props falling over) that happened during the production...I came to the conclusion that there was just the right amount of chaos this year that it kept things interesting. Not enough and it gets kinda boring, "what are these kids? professionals?" you think to yourself. But they really hit the mark so well, I even heard one of the moms mention the chaos during the show. I'm looking forward to next year when it's Leo's grade's turn to have speaking roles...and maybe a bit less chaos.
- After years of regularly and then sporadically saving for retirement, I've finally automated it again...kinda. If I were in the US, I'd have access to regular retirement accounts and things could be deducted in a tax efficient way from my pay check. As an American, I also can't take advantage of any non-US retirement savings schemes (π€ͺ). So what I'm basically left with is depositing some amount into into a regular taxed brokerage account.
-
Checkin to Starbucks
Coffee and handwriting practice. -
bySaw this flat with about 10 of those portable solar generators haphazardly hung on / around his balcony. Love it. Wonder how theyβre actually using itβ¦.
-
Checkin to Soul Food House @ 148 (γ½γ¦γ«γγΌγγγ¦γΉ)
by in Tokyo, Tokyo, JapanChicken and waffles! -
The Week #128
by- We bought tickets to visit America for 2 weeks during February π. Leo will turn 5 in Texas. I'm really excited for him to meet everyone. I'm also excited to see what happens when he's throw into a pure English environment. It's only two weeks, but will he come back speaking more English, even if just a temporary boost? Ticket prices were still a bit painful, but not ludicrous like they were 6 months ago.
- The US not having a proper public transit system sure makes visiting a pain because it means you've got to rent a car. Which means me getting an international driver's permit (my US license expired and I can no longer renew it online). And also means me potentially futzing with a child seat after a 14 hour flight...so much better to just have trains that connect people to the places they want to go.
- Last week I started on some upgrades to Tanzawa that will allow me to update reply/bookmark titles without resorting to the Django admin. And as I started, I realized that there was a yak that needed shaving. It was time to do the next chunk of refactoring: moving my business logic out of views/django forms and into re-usable "application" functions.
It's a much larger chunk of work, but also very important. You see, to share as much code as possible during my initial development of Tanzawa, my micropub endpoint mostly just converts the micropub request format to that of my authoring views, and uses the same forms for processing.
This is problematic, not because not because it doesn't work, but because it's all too entangled together. It's a problem because it doesn't make sense that editing my author form will effect my micropub endpoint (so change it as little as possible π).Β
My functional end-to-end tests for posting just test micropub under the assumption that they're the same, so I never bothered writing tests for my author views because if it busted, I could always fallback to any micropub client for posting.
All of this is a long-winded way to say I've got a lot of refactoring ahead of me, but it's a lot of fun making things not just work, but making them right β with tests. - I started watching The Playlist, a drama about starting Spotify. I''m really liking it. Each episode is told from the perspective of one founding / important member or another, which is something I've never seen before.
- I made some overnight white bread with Leo, as his request. Each time I make this, I think I should make it more often. It's vastly superior to anything I can buy locally in the shops. If I could find a loaf like this, it'd be at least Β₯1,000.Β And because it's done overnight, it's much easier to manage the fermenting/timing of things. Slam it in the fridge and bake it the next day (or so) when you have some time.
Overnight white bread
-
Checkin to γ€γ³γγ«γͺγΌγγ€γγ³γ° γ³γγ©γ«γγ§
Cheese nan and curries. π -
byFussing with package managers on the weekend on my Mac. Makes me think I may as well just run linux.
-
Checkin to Single O Hamacho
by in Chuo, Tokyo, JapanBanana bread with espresso butter. π