Skip to content

Commit

Permalink
camelCase only in editable cell
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis committed Aug 9, 2024
1 parent 3573556 commit 2e600ce
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 181 deletions.
1 change: 0 additions & 1 deletion packages/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/better-sqlite3": "^7.6.4",
"@types/lodash": "^4.17.7",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
5 changes: 3 additions & 2 deletions packages/explorer/src/app/(home)/EditableTableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { waitForTransactionReceipt } from "@wagmi/core";
import { Checkbox } from "../../components/ui/Checkbox";
import { ACCOUNT_PRIVATE_KEYS } from "../../consts";
import { useWorldAddress } from "../../hooks/useWorldAddress";
import { camelCase } from "../../lib/utils";
import { useStore } from "../../store";
import { wagmiConfig } from "../_providers";
import { TableConfig } from "../api/table/route";
Expand Down Expand Up @@ -37,7 +38,7 @@ export function EditableTableCell({
const [value, setValue] = useState<unknown>(defaultValue);

const tableId = config?.table_id;
const fieldType = config?.value_schema[name] as SchemaAbiType;
const fieldType = config?.value_schema[camelCase(name)] as SchemaAbiType;

const handleSubmit = async (newValue: unknown) => {
const valueToSet = newValue === undefined ? value : newValue;
Expand All @@ -54,7 +55,7 @@ export function EditableTableCell({

const toastId = toast.loading("Transaction submitted");
try {
const fieldIdx = getFieldIdx(config?.value_schema, name);
const fieldIdx = getFieldIdx(config?.value_schema, camelCase(name));
const encodedField = encodeField(fieldType, valueToSet);
const txHash = await writeContractAsync({
account: privateKeyToAccount(ACCOUNT_PRIVATE_KEYS[account]),
Expand Down
3 changes: 0 additions & 3 deletions packages/explorer/src/app/api/schema/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export async function GET(request: Request) {
const db = getDatabase();
const schema = db?.prepare("SELECT * FROM pragma_table_info(?)").all(table);

console.log("schema:");
console.log(schema);

return new Response(JSON.stringify({ schema }), { status: 200 });
} catch (error: unknown) {
if (error instanceof Error) {
Expand Down
7 changes: 7 additions & 0 deletions packages/explorer/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function camelCase(str: string) {
const a = str
.toLowerCase()
.replace(/[-_\s.]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ""));
return a.substring(0, 1).toLowerCase() + a.substring(1);
}
Loading

0 comments on commit 2e600ce

Please sign in to comment.