Skip to content

Commit

Permalink
Cleaned up code (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras authored Apr 27, 2024
1 parent dddb2b8 commit a4d7542
Show file tree
Hide file tree
Showing 32 changed files with 90 additions and 23 deletions.
5 changes: 5 additions & 0 deletions copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ port:
help: The port on which the app will listen
default: 3000

keyprefix:
type: str
help: The prefix for various keys used in the app (e.g. for storage)
default: "{{ appname | lower | replace('_', '-') }}"

docs:
type: bool
help: Whether to include a documentation site for the app
Expand Down
2 changes: 1 addition & 1 deletion src/.envrc.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# reload when these files change
watch_file flake.lock ./*.nix package.json package-lock.json Taskfile.dist.yaml {taskfile,Taskfile}.{yaml,yml}
watch_file flake.lock ./*.nix

# activate the default development shell in the current shell
# --accept-flake-config will accept the nix configuration from the flake without prompting
Expand Down
9 changes: 6 additions & 3 deletions src/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ module.exports = {
root: true,

rules: {
// Allow empty destructuring patterns
"no-empty-pattern": "off",

// Allow anonymous default exports
"import/no-anonymous-default-export": "off",

// Allow empty block statements
"no-empty": "off",

// Allow empty destructuring patterns
"no-empty-pattern": "off",
},
};
2 changes: 2 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ SHELL ["/app/scripts/shell.sh"]
COPY --from=build /build/build/ build/
# Copy dependencies from build
COPY --from=build /build/node_modules/ node_modules/
# Copy public files
COPY --from=build /build/public/ public/
# Copy package files
COPY --from=build /build/package.json /build/package-lock.json ./
# Copy Next.js config
Expand Down
3 changes: 1 addition & 2 deletions src/package.json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"run": "next start --hostname \"${ {{- envprefix }}__SERVER__HOST:-0.0.0.0}\" --port \"${ {{- envprefix }}__SERVER__PORT:-{{ port -}} }\"",
"build": "next build",
"clean": "rm --recursive --force build/",
"update": "ncu --peer --doctor --upgrade && npm i --no-audit --no-fund",
"test": "npm run -- build"
"update": "ncu --peer --upgrade && npm i --no-audit --no-fund"
},
"dependencies": {
"@mantine/core": "^7.7.1",
Expand Down
7 changes: 7 additions & 0 deletions src/src/actions/helloWorld/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use server";

import { HelloWorldProps } from "./types";

export async function helloWorld({}: HelloWorldProps = {}) {
return "Hello, World!";
}
2 changes: 2 additions & 0 deletions src/src/actions/helloWorld/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./action";
export * from "./types";
3 changes: 3 additions & 0 deletions src/src/actions/helloWorld/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type HelloWorldProps = {
[key: string]: never;
};
1 change: 1 addition & 0 deletions src/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./helloWorld";
21 changes: 17 additions & 4 deletions src/src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use client";

import { Title } from "@mantine/core";
import { Button, Stack, Title } from "@mantine/core";
import { IconRefresh } from "@tabler/icons-react";
import { Metadata } from "next";
import { labels } from "../config/labels.ts";
import { labels } from "../config/labels";

export const metadata: Metadata = {
title: labels.pages.error.title,
Expand All @@ -14,6 +15,18 @@ export type ErrorProps = Readonly<{
reset: () => void;
}>;

export default function Error({}: ErrorProps) {
return <Title>{labels.pages.error.text}</Title>;
export default function Error({ reset }: ErrorProps) {
return (
<Stack>
<Title>{labels.pages.error.text}</Title>
<Button
variant="subtle"
color="gray"
onClick={reset}
leftSection={<IconRefresh />}
>
{labels.pages.error.buttons.retry.label}
</Button>
</Stack>
);
}
2 changes: 1 addition & 1 deletion src/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Metadata } from "next";
import { ReactNode } from "react";
import { PageLayout } from "../components";
import { colorSchemeStorageKey, defaultColorScheme } from "../config/constants";
import { labels } from "../config/labels.ts";
import { labels } from "../config/labels";
import { ThemeProvider } from "../contexts";

export const metadata: Metadata = {
Expand Down
2 changes: 1 addition & 1 deletion src/src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Title } from "@mantine/core";
import { Metadata } from "next";
import { labels } from "../config/labels.ts";
import { labels } from "../config/labels";

export const metadata: Metadata = {
title: labels.pages.notFound.title,
Expand Down
14 changes: 12 additions & 2 deletions src/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
"use client";

import { Button } from "@mantine/core";
import { labels } from "../config/labels.ts";
import { useCallback } from "react";
import { helloWorld } from "../actions";
import { labels } from "../config/labels";
import { useToasts } from "../hooks";
import { useStore } from "../store";

export default function IndexPage() {
const [color, hydrated] = useStore((state) => state.color);
const [flipColor] = useStore((state) => state.flipColor);

const { success } = useToasts();

const onClick = useCallback(async () => {
success(await helloWorld());
flipColor();
}, [success, flipColor]);

return (
<Button
loading={!hydrated}
size="xl"
color={hydrated ? color : undefined}
onClick={hydrated ? flipColor : undefined}
onClick={hydrated ? onClick : undefined}
>
{labels.pages.index.buttons.main.label}
</Button>
Expand Down
4 changes: 0 additions & 4 deletions src/src/config/constants.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/src/config/constants.ts.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const colorSchemeStorageKey = "{{ keyprefix }}-color-scheme";
export const defaultColorScheme = "auto";
export const stateStorageKey = "{{ keyprefix }}-state";
5 changes: 5 additions & 0 deletions src/src/config/labels.ts.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const labels = {
title: "Error • {{ appname }}",
description: "{{ appname }}",
text: "Something went wrong",
buttons: {
retry: {
label: "Retry",
},
},
},
},
};
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Theme";
export * from "./ThemeProvider";
3 changes: 2 additions & 1 deletion src/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Toasts";
export * from "./useHydrated";
export * from "./useToasts";
1 change: 1 addition & 0 deletions src/src/hooks/useHydrated/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./useHydrated";
13 changes: 13 additions & 0 deletions src/src/hooks/useHydrated/useHydrated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "client-only";

import { useEffect, useState } from "react";

export function useHydrated() {
const [hydrated, setHydrated] = useState(false);

useEffect(() => {
setHydrated(true);
}, []);

return hydrated;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IconX,
} from "@tabler/icons-react";
import { useCallback } from "react";
import { labels } from "../../config/labels.ts";
import { labels } from "../../config/labels";
import { Toast } from "./useToasts.types";

export function useToasts() {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./store";
export * from "./store.types";
export * from "./types";
2 changes: 1 addition & 1 deletion src/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StateCreator, create } from "zustand";
import { PersistOptions, persist } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";
import { stateStorageKey } from "../config/constants";
import { Store } from "./store.types";
import { Store } from "./types";

type Initializer = StateCreator<Store, [["zustand/immer", never]]>;

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"module": "esnext",
"moduleResolution": "bundler",
"noEmit": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"plugins": [
{
Expand Down
1 change: 1 addition & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def data() -> dict[str, str]:
"repourl": "https://github.com/radio-aktywne/app-foo",
"envprefix": "FOO",
"port": "3000",
"keyprefix": "foo",
"docs": "true",
"docsurl": "https://radio-aktywne.github.io/app-foo",
"releases": "false",
Expand Down
1 change: 1 addition & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def data() -> dict[str, str]:
"repourl": "https://github.com/radio-aktywne/app-foo",
"envprefix": "FOO",
"port": "3000",
"keyprefix": "foo",
"docs": "true",
"docsurl": "https://radio-aktywne.github.io/app-foo",
"releases": "true",
Expand Down

0 comments on commit a4d7542

Please sign in to comment.