Skip to content

Commit

Permalink
Best version yet
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Jul 19, 2024
1 parent e92c2d9 commit 003b82b
Show file tree
Hide file tree
Showing 34 changed files with 570 additions and 429 deletions.
9 changes: 7 additions & 2 deletions app/history.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package app

import (
"sync"

"github.com/TrueBlocks/trueblocks-core/sdk/v3"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)

var addrToHistoryMap = map[base.Address][]types.Transaction{}
var m = sync.Mutex{}

func (a *App) GetHistory(addr string, first, pageSize int) []types.Transaction {
address := base.HexToAddress(addr)
m.Lock()
defer m.Unlock()

if len(addrToHistoryMap[address]) == 0 {
opts := sdk.ExportOptions{
Addrs: []string{addr},
Articulate: true,
Addrs: []string{addr},
Globals: sdk.Globals{
Cache: true,
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"eslint-plugin-react-hooks": "^4.6.2",
"prettier": "^3.3.2",
"typescript": "^5.3.3",
"vite": "^3.2.0"
"vite": "^5.3.4",
"vite-tsconfig-paths": "^4.3.2"
}
}
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
629562b1124538ac4adc569d85596259
b2847408bf3098df9dcf115aa2c4ab87
9 changes: 3 additions & 6 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, { useEffect } from "react";
import { AppShell, Text } from "@mantine/core";
import Aside from "./components/global/Aside";
import Header from "./components/global/Header";
import Navbar from "./components/global/Navbar";
import Routes from "./components/global/Routes";
import classes from "/App.module.css";
import { EventsOn, EventsOff, EventsEmit } from "../wailsjs/runtime";
import { Aside, Header, Navbar, Routes } from "@components";
import classes from "@/App.module.css";
import { EventsOn, EventsOff, EventsEmit } from "@runtime";

function App() {
const [showHelp, setShowHelp] = React.useState(true);
Expand Down
18 changes: 8 additions & 10 deletions frontend/src/components/EditableSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { Select } from '@mantine/core';
import { GetExistingAddrs } from '@gocode/app/App';
import React, { useState, useEffect } from "react";
import { Select } from "@mantine/core";
import { GetExistingAddrs } from "@gocode/app/App";

type SelectItem = {
value: string;
Expand All @@ -14,7 +14,7 @@ interface EditableSelectProps {
placeholder: string;
}

const EditableSelect: React.FC<EditableSelectProps> = ({ value, onChange, label, placeholder }) => {
export const EditableSelect: React.FC<EditableSelectProps> = ({ value, onChange, label, placeholder }) => {
const [options, setOptions] = useState<SelectItem[]>([]);
const [inputValue, setInputValue] = useState<string>(value);

Expand All @@ -24,7 +24,7 @@ const EditableSelect: React.FC<EditableSelectProps> = ({ value, onChange, label,
const formattedOptions = existingAddrs.map((addr) => ({ value: addr, label: addr }));
setOptions(formattedOptions);
if (!existingAddrs.includes(value)) {
setInputValue(existingAddrs.length > 0 ? existingAddrs[0] : '');
setInputValue(existingAddrs.length > 0 ? existingAddrs[0] : "");
} else {
setInputValue(value); // Ensure the inputValue is set to the prop value if it exists in the options
}
Expand All @@ -34,7 +34,7 @@ const EditableSelect: React.FC<EditableSelectProps> = ({ value, onChange, label,
}, [value]);

const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter' && inputValue.trim() !== '') {
if (event.key === "Enter" && inputValue.trim() !== "") {
const newOption: SelectItem = { value: inputValue, label: inputValue };
setOptions((current) => {
const existingIndex = current.findIndex((option) => option.value.toLowerCase() === inputValue.toLowerCase());
Expand All @@ -47,7 +47,7 @@ const EditableSelect: React.FC<EditableSelectProps> = ({ value, onChange, label,
onChange(inputValue);
event.preventDefault();
setTimeout(() => {
const selectElement = document.querySelector('.mantine-Select-input') as HTMLElement;
const selectElement = document.querySelector(".mantine-Select-input") as HTMLElement;
if (selectElement) {
selectElement.blur();
}
Expand All @@ -72,9 +72,7 @@ const EditableSelect: React.FC<EditableSelectProps> = ({ value, onChange, label,
onSearchChange={setInputValue}
onChange={handleChange}
onKeyDown={handleKeyDown}
style={{ width: '600px' }}
style={{ width: "600px" }}
/>
);
};

export default EditableSelect;
2 changes: 1 addition & 1 deletion frontend/src/components/ImageDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
import { Text, Image } from "@mantine/core";
import { GetTitle } from "../../wailsjs/go/app/App";
import { GetTitle } from "@gocode/app/App";

export const ImageDisplay = ({ address, loading }: { address: string; loading: boolean }) => {
var [title, setTitle] = useState<string>("");
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/components/ResultDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React from 'react';
import { Modal, Text } from '@mantine/core';
import React from "react";
import { Modal, Text } from "@mantine/core";

interface ResultDialogProps {
opened: boolean;
onClose: () => void;
success: boolean;
}

const ResultDialog: React.FC<ResultDialogProps> = ({ opened, onClose, success }) => {
export const ResultDialog: React.FC<ResultDialogProps> = ({ opened, onClose, success }) => {
return (
<Modal opened={opened} onClose={onClose} title="Result">
<Text>{success ? 'Success!' : 'Failed!'}</Text>
<Text>{success ? "Success!" : "Failed!"}</Text>
</Modal>
);
};

export default ResultDialog;
6 changes: 2 additions & 4 deletions frontend/src/components/StringTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import { Table, Checkbox, Anchor } from "@mantine/core";
import { Link, useLocation } from "wouter";
import { SetLast } from "../../wailsjs/go/app/App";
import { SetLast } from "@gocode/app/App";

export interface DataItem {
id: number;
Expand All @@ -12,7 +12,7 @@ interface StringTableProps {
data: DataItem[];
}

const StringTable: React.FC<StringTableProps> = ({ data }) => {
export const StringTable: React.FC<StringTableProps> = ({ data }) => {
const [selectedIds, setSelectedIds] = useState<number[]>([]);
const [location, setLocation] = useLocation();

Expand Down Expand Up @@ -73,5 +73,3 @@ const StringTable: React.FC<StringTableProps> = ({ data }) => {
</Table>
);
};

export default StringTable;
4 changes: 1 addition & 3 deletions frontend/src/components/global/AppStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from "react";
import { Text } from "@mantine/core";

function AppStatus() {
export function AppStatus() {
return <Text size="sm">unchained index progress</Text>;
}

export default AppStatus;
6 changes: 2 additions & 4 deletions frontend/src/components/global/Aside.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useEffect } from "react";
import { EventsOn, EventsOff } from "../../../wailsjs/runtime";
import { EventsOn, EventsOff } from "@runtime";
import { Text } from "@mantine/core";

function Aside() {
export function Aside() {
return <Text>Help file</Text>;
}

export default Aside;
6 changes: 2 additions & 4 deletions frontend/src/components/global/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React from "react";
import { Group, Title } from "@mantine/core";
import AppStatus from "./AppStatus";
import { AppStatus } from "./";

const Header = ({ title }: { title: string }) => {
export const Header = ({ title }: { title: string }) => {
return (
<Group w={"100%"} justify="space-between">
<Title order={1}>{title}</Title>
<AppStatus />
</Group>
);
};

export default Header;
6 changes: 2 additions & 4 deletions frontend/src/components/global/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { ReactNode, useEffect, useState } from "react";
import { NavLink } from "@mantine/core";
import { IconHome, IconSettings, IconTag, IconList, IconSpider } from "@tabler/icons-react";
import { Link, useRoute } from "wouter";
import { GetLast, SetLast } from "../../../wailsjs/go/app/App";
import { GetLast, SetLast } from "@gocode/app/App";

function Menu() {
export function Menu() {
const [activeRoute, setActiveRoute] = useState("/");

useEffect(() => {
Expand Down Expand Up @@ -43,8 +43,6 @@ function Menu() {
);
}

export default Menu;

type StyledNavLinkParams = {
label: string;
href: string;
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/global/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from "react";
import { Stack } from "@mantine/core";
import Menu from "./Menu";
import ServerStatus from "./ServerStatus";
import { Menu, ServerStatus } from "./";

function Navbar() {
export function Navbar() {
return (
<Stack h={"100%"} justify="space-between">
<Menu />
<ServerStatus />
</Stack>
);
}

export default Navbar;
8 changes: 3 additions & 5 deletions frontend/src/components/global/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect } from "react";
import { Route, Switch, useLocation } from "wouter";
import classes from "/App.module.css";
import { DalleView, NamesView, HomeView, SeriesView, HistoryView, SettingsView } from "../../views";
import { GetLast } from "../../../wailsjs/go/app/App";
import classes from "@/App.module.css";
import { DalleView, NamesView, HomeView, SeriesView, HistoryView, SettingsView } from "@views";
import { GetLast } from "@gocode/app/App";

export const Routes = () => {
const [, setLocation] = useLocation();
Expand Down Expand Up @@ -34,5 +34,3 @@ export const Routes = () => {
</div>
);
};

export default Routes;
4 changes: 1 addition & 3 deletions frontend/src/components/global/ServerStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Flex, Space, Text } from "@mantine/core";
import { IconCheck } from "@tabler/icons-react";

function ServerStatus() {
export function ServerStatus() {
return (
<Flex justify="center" align="center">
<IconCheck />
Expand All @@ -13,5 +13,3 @@ function ServerStatus() {
</Flex>
);
}

export default ServerStatus;
7 changes: 7 additions & 0 deletions frontend/src/components/global/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./AppStatus";
export * from "./Aside";
export * from "./Header";
export * from "./Menu";
export * from "./Navbar";
export * from "./Routes";
export * from "./ServerStatus";
6 changes: 6 additions & 0 deletions frontend/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./EditableSelect";
export * from "./ImageDisplay";
export * from "./ResultDialog";
export * from "./StringTable";
export * from "./global";
export * from "./view";
2 changes: 1 addition & 1 deletion frontend/src/components/view/View.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactNode } from "react";
import { Stack } from "@mantine/core";
import classes from "/App.module.css";
import classes from "@/App.module.css";

export function View(params: { title?: string; children: ReactNode }) {
return <Stack className={classes.mainContent}>{params.children}</Stack>;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./useKeyboardPaging";
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useState } from 'react';
import { useEffect, useState } from "react";
import { useHotkeys } from "react-hotkeys-hook";

type FetchItemsFn<T> = (curItem: number, perPage: number) => Promise<T[]>;
type FetchCountFn = () => Promise<number>;

function useKeyboardPaging<T>(
export function useKeyboardPaging<T>(
fetchItems: FetchItemsFn<T>,
fetchCount: FetchCountFn,
dependency?: any,
Expand Down Expand Up @@ -46,8 +46,10 @@ function useKeyboardPaging<T>(
useEffect(() => {
const fetch = async () => {
const fetchedItems = await fetchItems(curItem, perPage);
console.log("fetchedItems", fetchedItems.length);
setItems(fetchedItems);
const cnt = await fetchCount();
console.log("cnt", cnt);
setNItems(cnt);
};
fetch();
Expand All @@ -59,5 +61,3 @@ function useKeyboardPaging<T>(

return { items, nItems, curItem };
}

export default useKeyboardPaging;
9 changes: 3 additions & 6 deletions frontend/src/views/Dalle/DalleView.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useState, useEffect } from "react";
import { Stack, Title, Paper, Grid, Button, Group } from "@mantine/core";
import classes from "/App.module.css";
import { View, ViewStatus } from "../../components/view";
import EditableSelect from "../../components/EditableSelect";
import ResultDialog from "../../components/ResultDialog";
import classes from "@/App.module.css";
import { View, ViewStatus, EditableSelect, ResultDialog, ImageDisplay } from "@components";
import {
GetJson,
GetData,
Expand All @@ -16,8 +14,7 @@ import {
GetLast,
SetLast,
Save,
} from "../../../wailsjs/go/app/App";
import { ImageDisplay } from "../../components/ImageDisplay";
} from "@gocode/app/App";
import Tabber from "./Tabber";

export function DalleView() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Dalle/Tabber.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Tabs, Text } from "@mantine/core";
import classes from "../View.module.css";
import classes from "../Views.module.css";

interface TabItem {
value: string;
Expand Down
Loading

0 comments on commit 003b82b

Please sign in to comment.