Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
repos:
# General checks
- repo: local
hooks:
- name: Prevent committing to main
id: no-commit-to-branch
language: system
entry: no-commit-to-branch
args: [--branch, main]
pass_filenames: false
- name: Make sure files end with a newline character
id: end-of-file-fixer
language: system
entry: end-of-file-fixer
types: [text]
- name: Remove trailing whitespace
id: trailing-whitespace-fixer
language: system
entry: trailing-whitespace-fixer
types: [text]
- name: Check for files that would conflict on case-insensitive filesystem
id: check-case-conflict
language: system
entry: check-case-conflict
- name: Check for merge conflicts
id: check-merge-conflict
language: system
entry: check-merge-conflict
- name: Check executable files have a shebang
id: check-executables-have-shebangs
language: system
entry: check-executables-have-shebangs
types: [executable]
- name: Check scripts with a shebang are executable
id: check-shebang-scripts-are-executable
language: system
entry: check-shebang-scripts-are-executable
- name: Don't allow adding large files
id: check-added-large-files
language: system
entry: check-added-large-files

# Roc
- repo: https://github.com/hasnep/pre-commit-roc
rev: v0.1.0
hooks:
- name: Lint Roc files
id: check
args: [src/main.roc]
- name: Format Roc files
id: format

# YAML
- repo: local
hooks:
- name: Format YAML files
id: yaml-format
language: system
entry: prettier --write
types: [yaml]

# Markdown
- repo: local
hooks:
- name: Format markdown files
id: markdown-format
language: system
entry: prettier --write
types: [markdown]

# GitHub Actions
- repo: local
hooks:
- name: Validate GitHub Actions workflow files
id: github-workflows-check
language: system
entry: actionlint
types: [yaml]
files: \.github/workflows/.*\.ya?ml$

# Nix
- repo: local
hooks:
- name: Format Nix files
id: nix-format
language: system
entry: nixfmt
types: [nix]
94 changes: 52 additions & 42 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 42 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
{
description = "devShell flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
roc.url = "github:roc-lang/roc";
nixpkgs.follows = "roc/nixpkgs";

# to easily make configs for multiple architectures
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, roc, flake-utils }:
let supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
in flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = import nixpkgs { inherit system; };
rocPkgs = roc.packages.${system};

sharedInputs = (with pkgs; [
rocPkgs.cli
]);
in {
nixConfig = {
extra-trusted-public-keys = "roc-lang.cachix.org-1:6lZeqLP9SadjmUbskJAvcdGR2T5ViR57pDVkxJQb8R4=";
extra-trusted-substituters = "https://roc-lang.cachix.org";
};

devShell = pkgs.mkShell {
buildInputs = sharedInputs;
outputs =
inputs@{
self,
nixpkgs,
flake-parts,
roc,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
perSystem =
{ inputs', pkgs, ... }:
{
devShells.default = pkgs.mkShell {
name = "roc-html";
packages = [
inputs'.roc.packages.cli
pkgs.actionlint
pkgs.check-jsonschema
pkgs.fd
pkgs.just
pkgs.nixfmt-rfc-style
pkgs.nodePackages.prettier
pkgs.pre-commit
pkgs.python312Packages.pre-commit-hooks
pkgs.ratchet
];
shellHook = "pre-commit install --overwrite";
};
formatter = pkgs.nixfmt-rfc-style;
};

formatter = pkgs.nixpkgs-fmt;
});
};
}
42 changes: 25 additions & 17 deletions src/Controllers/Product.roc
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@ handle_routes! :
db_path : Str,
}
=> Result Response _
handle_routes! = \{ req, url_segments, db_path } ->
handle_routes! = |{ req, url_segments, db_path }|

query_params =
req.uri
|> Helpers.parse_query_params
|> Result.withDefault (Dict.empty {})
|> Result.with_default(Dict.empty({}))

partial =
query_params
|> Dict.get "partial"
|> Result.map \val -> if val == "true" then Bool.true else Bool.false
|> Result.withDefault Bool.false
|> Dict.get("partial")
|> Result.map_ok(|val| if val == "true" then Bool.true else Bool.false)
|> Result.with_default(Bool.false)

when (req.method, url_segments) is
(GET, []) ->
products = Sql.Product.list!? { db_path }
products = Sql.Product.list!({ db_path })?

view = Views.Pages.pageProducts {
products,
}
view = Views.Pages.page_products(
{
products,
},
)

if partial then
view
|> Helpers.respond_template! 200 [
{ name: "HX-Push-Url", value: "/products" },
]
|> Helpers.respond_template!(
200,
[
{ name: "HX-Push-Url", value: "/products" },
],
)
else
view
|> Views.Layout.sidebar
|> Helpers.respond_template! 200 [
{ name: "HX-Push-Url", value: "/products" },
]

_ -> Err (NotHandled req)
|> Helpers.respond_template!(
200,
[
{ name: "HX-Push-Url", value: "/products" },
],
)

_ -> Err(NotHandled(req))
Loading