fix: concurrency

This commit is contained in:
2025-11-19 12:26:37 -07:00
parent e1396e2d24
commit 80e57eaa2b
19 changed files with 175 additions and 60 deletions

View File

@@ -5,6 +5,8 @@ import { ItemHistoryTable } from "./ItemHistoryTable"
import useAsyncEffect from "use-async-effect"
import { useItemStore } from "../providers/ItemsProvider"
import { Mutex } from "async-mutex"
import { useCurrentAuthenticatedUserStore } from "../providers"
import { useShallow } from "zustand/shallow"
type ItemTableListRowProps = {
item: ItemPriceResponse
@@ -56,15 +58,25 @@ export const ItemTableListRow = ({item}: ItemTableListRowProps) => {
const [shouldPushNewItemPrice, setShouldPushNewItemPrice] = useState<boolean>(false)
const authUserStore = useCurrentAuthenticatedUserStore(useShallow((state) => state))
useAsyncEffect(async () => {
if(shouldPushNewItemPrice)
if(shouldPushNewItemPrice && authUserStore.Admin)
{
const release = await itemTableListRowMutex.acquire()
setShouldPushNewItemPrice(false)
await itemStore.setItemPrice(item.ItemId, newItemPrice)
await release()
}
}, [shouldPushNewItemPrice])
}, [shouldPushNewItemPrice, authUserStore])
useAsyncEffect(async () => {
if (authUserStore.Id === -1) {
const release = await itemTableListRowMutex.acquire()
await authUserStore.sync()
await release()
}
}, [authUserStore])
return (
<li>
@@ -79,7 +91,7 @@ export const ItemTableListRow = ({item}: ItemTableListRowProps) => {
price: {Math.trunc(item.ItemPrice * 100) / 100}
</ItemFieldContainer>
</ItemOverviewContainer>
{shouldShowDetails && (
{shouldShowDetails && authUserStore.Admin && (
<>
<ItemDetailsContainer>
<h1 className="text-xl">Set Item Price</h1>