Learning-HTMX/16-countries-page-from-api
efim e13fa186e1 feat: preserving name \ region on active search
by using post - all inputs of same form are sent
so in active search scenario changing region also sends current name,
or changing name also sends current region

had to make additional post endpoint,
but with cask i can directly use form-value as function argument
and can reuse the code, yay
2023-10-11 03:22:31 +00:00
..
design init: adding resource files 2023-09-23 04:17:48 +00:00
project feat: enabling jar build with nix 2023-09-26 16:03:51 +00:00
src feat: preserving name \ region on active search 2023-10-11 03:22:31 +00:00
.gitignore feat: enabling jar build with nix 2023-09-26 16:03:51 +00:00
.project init: simple cask, initial template 2023-09-22 17:01:43 +00:00
.scalafmt.conf feat: loading country data from resourse json 2023-09-23 09:31:04 +00:00
README.org docs: readme for exercise 16 2023-09-27 06:59:43 +00:00
build.sbt feat: loading data from api on start 2023-09-27 05:41:38 +00:00
default.nix fix: flake naming for countries page 2023-09-27 06:14:20 +00:00
desktop-main.png docs: readme for exercise 16 2023-09-27 06:59:43 +00:00
desktop-single.png docs: readme for exercise 16 2023-09-27 06:59:43 +00:00
mobile-main.png docs: readme for exercise 16 2023-09-27 06:59:43 +00:00
mobile-single.png docs: readme for exercise 16 2023-09-27 06:59:43 +00:00
style-guide.md init: adding resource files 2023-09-23 04:17:48 +00:00
tailwind.config.js feat: dark theme, font icons 2023-09-26 16:01:37 +00:00

README.org

Frontend Mentor - REST Countries API with color theme switcher solution

This is a solution to the REST Countries API with color theme switcher challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Overview

The challenge

Users should be able to:

  • See all countries from the API on the homepage
  • Search for a country using an input field
  • Filter countries by region
  • Click on a country to see more detailed information on a separate page
  • Click through to the border countries on the detail page
  • Toggle the color scheme between light and dark mode (optional)

Screenshot

/efim/Learning-HTMX/media/commit/9c8ec7fb0dcf0d8fa7a3faf59527e43cb0484df7/16-countries-page-from-api/mobile-main.png /efim/Learning-HTMX/media/commit/9c8ec7fb0dcf0d8fa7a3faf59527e43cb0484df7/16-countries-page-from-api/mobile-single.png /efim/Learning-HTMX/media/commit/9c8ec7fb0dcf0d8fa7a3faf59527e43cb0484df7/16-countries-page-from-api/desktop-main.png /efim/Learning-HTMX/media/commit/9c8ec7fb0dcf0d8fa7a3faf59527e43cb0484df7/16-countries-page-from-api/desktop-single.png

My process

Built with

  • Scala Server Side Rendering
  • Htmx
  • TailwindCSS
  • Flexbox
  • CSS Grid
  • Mobile-first workflow

What I learned

polling download for 'infinite scroll'

https://htmx.org/examples/infinite-scroll/

I've done almost same thing as example, but i'm appending additional empty div, that inserts responses instead of itself

this way i have one template fragment with repeater, and don't have to add hx attributes to the last one,

i just have separate fragment that i append to response which will trigger new load on enter view.

having html 5 native autocomplete with <datalist> tag

just server side rendering it with all country names is yay

inserting thymeleaf templates by css selector

https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#appendix-c-markup-selector-syntax

this way i can insert <script> tag from index page, without declaring it as a fragment, because i'll want is static anyway.

and can share 'dark mode' js code between pages

building docker image

First off: using nix docker tools, and sbt assembly to create 'uber jar' now 'nix build .#countries-page-image' builds an image and symlinks it to ./result

$ docker load < result loads the image

and it can be started $ docker image list $ docker run -d -p 9090:8080 <image-id>

deploying to render.com

need to auth the docker cli, then tag an image with my repository name $ docker login $ docker tag 141 efim1234/rock-paper-scissors:latest $ podman push localhost/efim1234/countries-page:latest docker.io/efim1234/countries-page:latest

and now render.com, when creating "new service" can find "efim1234/countries-page:latest" as public image and use it

using browser history

with either server side HX-Push -> "some-url" or hx-push-url="true" in the html side

so that url is put into address bar, and browser save the body into history

and now my website has forward and backward navigation

only bug - the 'filter by region' for some reason doesn't maintain the selected value

Continued development

In future project i'll probably want to lean and use go. For smaller binaries of the server, using PocketBase as embedded backend functions, and maybe having a better chances of just doing some real world small projects.

Useful resources