diff --git a/src/components/tile/Tile.js b/src/components/tile/Tile.js
index 8ee58a5..610c19e 100644
--- a/src/components/tile/Tile.js
+++ b/src/components/tile/Tile.js
@@ -83,13 +83,25 @@ function Tile({
borderRadius: "4px",
}}
/>
-
+
{badges.map((badge, i) => (
-
+
{badge}
))}
-
+
{canEdit && (
token.id);
- await updateTokens(selectedTokenIds, { hideInSidebar });
- onLoad(false);
+ updateTokensHidden(selectedTokenIds, hideInSidebar);
}
/**
diff --git a/src/components/token/TokenHiddenBadge.js b/src/components/token/TokenHiddenBadge.js
new file mode 100644
index 0000000..a7d633f
--- /dev/null
+++ b/src/components/token/TokenHiddenBadge.js
@@ -0,0 +1,21 @@
+import React from "react";
+import { Flex } from "theme-ui";
+
+import TokenShowIcon from "../../icons/TokenShowIcon";
+import TokenHideIcon from "../../icons/TokenHideIcon";
+
+function TokenHiddenBadge({ hidden }) {
+ return (
+
+ {hidden ? : }
+
+ );
+}
+
+export default TokenHiddenBadge;
diff --git a/src/components/token/TokenTiles.js b/src/components/token/TokenTiles.js
index 26df7f3..3b4e817 100644
--- a/src/components/token/TokenTiles.js
+++ b/src/components/token/TokenTiles.js
@@ -2,6 +2,7 @@ import React from "react";
import TokenTile from "./TokenTile";
import TokenTileGroup from "./TokenTileGroup";
+import TokenHiddenBadge from "./TokenHiddenBadge";
import SortableTiles from "../tile/SortableTiles";
@@ -35,7 +36,10 @@ function TokenTiles({ tokens, onTokenEdit, subgroup }) {
onSelect={onGroupSelect}
onTokenEdit={onTokenEdit}
canEdit={canEdit}
- badges={[`${token.defaultSize}x`]}
+ badges={[
+ `${token.defaultSize}x`,
+ ,
+ ]}
/>
);
} else {
diff --git a/src/contexts/TokenDataContext.js b/src/contexts/TokenDataContext.js
index f012e0b..e299a55 100644
--- a/src/contexts/TokenDataContext.js
+++ b/src/contexts/TokenDataContext.js
@@ -81,17 +81,24 @@ export function TokenDataProvider({ children }) {
const updateToken = useCallback(
async (id, update) => {
- const change = { lastModified: Date.now(), ...update };
- await database.table("tokens").update(id, change);
+ await database.table("tokens").update(id, update);
},
[database]
);
- const updateTokens = useCallback(
- async (ids, update) => {
- const change = { lastModified: Date.now(), ...update };
+ const updateTokensHidden = useCallback(
+ async (ids, hideInSidebar) => {
+ // Update immediately to avoid UI delay
+ setTokens((prevTokens) => {
+ let newTokens = [...prevTokens];
+ for (let id of ids) {
+ const tokenIndex = newTokens.findIndex((token) => token.id === id);
+ newTokens[tokenIndex].hideInSidebar = hideInSidebar;
+ }
+ return newTokens;
+ });
await Promise.all(
- ids.map((id) => database.table("tokens").update(id, change))
+ ids.map((id) => database.table("tokens").update(id, { hideInSidebar }))
);
},
[database]
@@ -167,11 +174,11 @@ export function TokenDataProvider({ children }) {
tokenGroups,
removeTokens,
updateToken,
- updateTokens,
tokensById,
tokensLoading,
getToken,
updateTokenGroups,
+ updateTokensHidden,
};
return (