Skip to content

Commit 1063e56

Browse files
committed
fixes
1 parent 2c1a2b9 commit 1063e56

File tree

12 files changed

+250
-128
lines changed

12 files changed

+250
-128
lines changed

app/db/sql/queries/tag_quries.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ WHERE mod_id = :id AND tag_name = :oldName;
1515
INSERT OR IGNORE INTO tag(tag_name, mod_id) VALUES(:tagName, :modId);
1616

1717
-- name: DeleteTag :exec
18-
DELETE FROM tag WHERE tag_name = :name AND mod_id = :modId;
18+
DELETE FROM tag WHERE tag_name = :name AND mod_id = :modId;
19+
20+
-- name: SelectTagsByModId :many
21+
SELECT * FROM tag WHERE mod_id = :modId;

app/db/tag_quries.sql.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/frontend/src/components/AsyncImage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function AsyncImage(props: AsyncImageProps) {
88
const ref = useRef<HTMLImageElement>(null)
99

1010
useLayoutEffect(() => {
11-
const uri = ref?.current?.src
11+
const uri = props.src
1212
if (!uri) return
1313
if (uri.startsWith("file://")) {
1414
ReadImageFile(uri).then((base64) => {
@@ -20,5 +20,5 @@ export default function AsyncImage(props: AsyncImageProps) {
2020
}
2121
}, [props.src, ref])
2222

23-
return <img {...props} />
23+
return <img ref={ref} {...props} />
2424
}

app/frontend/src/data/database.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { CancelFn } from "@/lib/tsutils";
22
import { useEffect } from "react";
3-
import { CreateCustomCharacter, CreatePlaylist, DeleteCharacter, DeleteModById, DeletePlaylistById, DeleteTextureById, InsertTag, InsertTagForAllModsByCharacterIds, RenameMod, RenameTexture, SelectCharactersByGame, SelectCharacterWithModsTagsAndTextures, SelectClosestCharacter, SelectModById, SelectModsByCharacterName, SelectModsByGbId, SelectPlaylistWithModsAndTags, UpdateDisableAllModsByGame, UpdateModEnabledById, UpdateModGbId, UpdateModImages, UpdateModsEnabledFromSlice, UpdatePlaylistName, UpdateTextureEnabledById } from "wailsjs/go/dbh/DbHelper";
3+
import { CreateCustomCharacter, CreatePlaylist, DeleteCharacter, DeleteModById, DeletePlaylistById, DeleteTag, DeleteTextureById, InsertTag, InsertTagForAllModsByCharacterIds, RenameMod, RenameTexture, SelectCharactersByGame, SelectCharacterWithModsTagsAndTextures, SelectClosestCharacter, SelectModById, SelectModsByCharacterName, SelectModsByGbId, SelectPlaylistWithModsAndTags, SelectTagsByModId, UpdateDisableAllModsByGame, UpdateModEnabledById, UpdateModGbId, UpdateModImages, UpdateModsEnabledFromSlice, UpdatePlaylistName, UpdateTextureEnabledById } from "wailsjs/go/dbh/DbHelper";
44
import { SplitTexture } from "wailsjs/go/main/App";
5-
import { EventsEmit, EventsOn, LogDebug } from "wailsjs/runtime/runtime";
5+
import { EventsEmit, EventsOn, LogDebug, LogError } from "wailsjs/runtime/runtime";
66

77

88
type DBKey = "characters" | "mods" | "tags" | "playlist" | "all"
@@ -11,20 +11,31 @@ const DBEvent = "DB_EVENT"
1111
type DBEventData = DBKey[]
1212

1313
const subscribeToDbUpdates = (key: DBKey[] | DBKey, callback: () => void, runOnStart: boolean = false): CancelFn => {
14+
const runCallbackCatching = () => {
15+
try {
16+
callback()
17+
} catch (e: any) {
18+
if (e instanceof Error) {
19+
LogError("subscribe listener failed with unhandled Error: " + e.message);
20+
} else {
21+
LogError("subscribe listener failed with unknown error" + e);
22+
}
23+
}
24+
}
1425

1526
if (runOnStart) {
16-
callback()
27+
runCallbackCatching()
1728
}
1829

1930
return EventsOn(DBEvent, (keys: DBEventData) => {
2031
LogDebug("received DBEVENT event keys=" + keys)
2132
if (typeof key === 'string') {
2233
if (key === "all" || keys.includes(key)) {
23-
callback()
34+
runCallbackCatching()
2435
}
2536
} else {
2637
if (key.any((k) => k === "all" || keys.includes(k))) {
27-
callback()
38+
runCallbackCatching()
2839
}
2940
}
3041
})
@@ -43,8 +54,8 @@ const broadcastCharacterUpdate = () => EventsEmit(DBEvent, ["characters"])
4354
const broadcastModsUpdate = () => EventsEmit(DBEvent, ["mods"])
4455
const broadcastTagsUpdate = () => EventsEmit(DBEvent, ["tags"])
4556
const broadcastPlaylistUpdate = () => EventsEmit(DBEvent, ["playlist"])
46-
//const broadcastMultiUpdate = (keys: DBKey[]) => EventsEmit(DBEvent, keys)
4757

58+
//const broadcastMultiUpdate = (keys: DBKey[]) => EventsEmit(DBEvent, keys)
4859
const DB = {
4960
onValueChangedListener: subscribeToDbUpdates,
5061
deleteMod: async (id: number) => {
@@ -121,6 +132,12 @@ const DB = {
121132
},
122133
updatePlaylistName: (id: number, name: string) => {
123134
return UpdatePlaylistName(id, name).then(broadcastPlaylistUpdate)
135+
},
136+
selectTagsByModId: (modId: number) => {
137+
return SelectTagsByModId(modId)
138+
},
139+
deleteTag: (modId: number, name: string) => {
140+
return DeleteTag(name, modId).then(broadcastTagsUpdate)
124141
}
125142
}
126143

app/frontend/src/lib/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function useStateProducer<T extends any>(
7777
producer: (
7878
update: (value: T) => void,
7979
onDispose: (dipose: () => void) => void,
80-
) => Promise<void>,
80+
) => void,
8181
keys: ReadonlyArray<unknown> = []
8282
): T {
8383
const [value, setValue] = useState(defaultValue);
@@ -107,8 +107,7 @@ export function useStateProducer<T extends any>(
107107
disposeFn = dispose
108108
disposeIfAborted()
109109
}
110-
)
111-
.catch((e) => LogError(e));
110+
);
112111
} catch (e: any) {
113112
LogError(e);
114113
}

0 commit comments

Comments
 (0)