Skip to content

Commit

Permalink
fix: remove ignore copied request file, prepare build-specific-js for…
Browse files Browse the repository at this point in the history
… http mode
  • Loading branch information
rolznz committed Jan 22, 2024
1 parent 4d5f61a commit c2c5f05
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ frontend/node_modules
frontend/wailsjs
package.json.md5

build
build

frontend/src/utils/request.ts
8 changes: 4 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev:wails": "yarn prepare:wails && VITE_NWC_APP_TYPE=WAILS vite",
"build": "tsc && vite build",
"dev": "yarn prepare:http && vite",
"dev:wails": "yarn prepare:wails && vite",
"build": "yarn prepare:http && tsc && vite build",
"prepare:wails": "cp ./platform_specific/wails/src/utils/request.ts src/utils/request.ts",
"prepare:http": "cp ./platform_specific/http/src/utils/request.ts src/utils/request.ts",
"build:wails": "yarn prepare:wails && tsc && VITE_NWC_APP_TYPE=WAILS vite build",
"build:wails": "yarn prepare:wails && tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
Expand Down
12 changes: 3 additions & 9 deletions frontend/platform_specific/http/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import toast from "../components/Toast";
import { ErrorResponse } from "../types";
import { ErrorResponse } from "src/types";

export const request = async <T,>(
export const request = async <T>(
...args: Parameters<typeof fetch>
): Promise<T | undefined> => {
try {
Expand All @@ -18,7 +17,7 @@ export const request = async <T,>(
throw new Error(
fetchResponse.status +
" " +
((body as ErrorResponse)?.message || "Unknown error"),
((body as ErrorResponse)?.message || "Unknown error")
);
}
return body;
Expand All @@ -27,8 +26,3 @@ export const request = async <T,>(
throw error;
}
};

export function handleRequestError(message: string, error: unknown) {
console.error(message, error);
toast.error(message + ": " + error);
}
11 changes: 2 additions & 9 deletions frontend/platform_specific/wails/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import toast from "../components/Toast";

import { WailsRequestRouter } from "wailsjs/go/main/WailsApp";

export const request = async <T,>(
export const request = async <T>(
...args: Parameters<typeof fetch>
): Promise<T | undefined> => {
try {
const res = await WailsRequestRouter(
args[0].toString(),
args[1]?.method || "GET",
args[1]?.body?.toString() || "",
args[1]?.body?.toString() || ""
);

console.log("Wails request", ...args, res);
Expand All @@ -23,8 +21,3 @@ export const request = async <T,>(
throw error;
}
};

export function handleRequestError(message: string, error: unknown) {
console.error(message, error);
toast.error(message + ": " + error);
}
3 changes: 2 additions & 1 deletion frontend/src/screens/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Loading from "src/components/Loading";
import { useCSRF } from "src/hooks/useCSRF";
import { useInfo } from "src/hooks/useInfo";
import { BackendType } from "src/types";
import { request, handleRequestError } from "src/utils/request";
import { handleRequestError } from "src/utils/handleRequestError";
import { request } from "src/utils/request"; // build the project for this to appear

export function Setup() {
const [backendType, setBackendType] = React.useState<BackendType>("BREEZ");
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/screens/apps/NewApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { LightningIcon } from "src/components/icons/LightningIcon";
import { InvoiceIcon } from "src/components/icons/InvoiceIcon";
import { SearchIcon } from "src/components/icons/SearchIcon";
import { TransactionsIcon } from "src/components/icons/TransactionsIcon";
import { handleRequestError, request } from "src/utils/request";
import { request } from "src/utils/request"; // build the project for this to appear
import { handleRequestError } from "src/utils/handleRequestError";

const NewApp = () => {
const { data: csrf } = useCSRF();
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/screens/apps/ShowApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useApp } from "src/hooks/useApp";
import { useCSRF } from "src/hooks/useCSRF";
import toast from "src/components/Toast";
import Loading from "src/components/Loading";
import { handleRequestError, request } from "src/utils/request";
import { request } from "src/utils/request"; // build the project for this to appear
import { handleRequestError } from "src/utils/handleRequestError";

function ShowApp() {
const { data: info } = useInfo();
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/handleRequestError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import toast from "src/components/Toast";

export function handleRequestError(message: string, error: unknown) {
console.error(message, error);
toast.error(message + ": " + error);
}

0 comments on commit c2c5f05

Please sign in to comment.