diff --git a/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx b/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx index 83190db..7bf99c2 100644 --- a/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx +++ b/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx @@ -1,8 +1,8 @@ import { PurchaseFromCatalogComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { CatalogPurchaseState, CreateLinkEvent, DispatchUiEvent, GetClubMemberLevel, LocalizeText, LocalStorageKeys, Offer, SendMessageComposer } from '../../../../../api'; +import { CatalogPurchaseState, CreateLinkEvent, DispatchUiEvent, GetClubMemberLevel, LocalStorageKeys, LocalizeText, Offer, SendMessageComposer } from '../../../../../api'; import { Button, LayoutLoadingSpinnerView } from '../../../../../common'; -import { CatalogEvent, CatalogInitGiftEvent, CatalogPurchasedEvent, CatalogPurchaseFailureEvent, CatalogPurchaseNotAllowedEvent, CatalogPurchaseSoldOutEvent } from '../../../../../events'; +import { CatalogEvent, CatalogInitGiftEvent, CatalogPurchaseFailureEvent, CatalogPurchaseNotAllowedEvent, CatalogPurchaseSoldOutEvent, CatalogPurchasedEvent } from '../../../../../events'; import { useCatalog, useLocalStorage, usePurse, useUiEvent } from '../../../../../hooks'; interface CatalogPurchaseWidgetViewProps @@ -14,11 +14,10 @@ interface CatalogPurchaseWidgetViewProps export const CatalogPurchaseWidgetView: FC = props => { const { noGiftOption = false, purchaseCallback = null } = props; - const [ purchaseWillBeGift, setPurchaseWillBeGift ] = useState(false); const [ purchaseState, setPurchaseState ] = useState(CatalogPurchaseState.NONE); - const [ catalogSkipPurchaseConfirmation, setCatalogSkipPurchaseConfirmation ] = useLocalStorage(LocalStorageKeys.CATALOG_SKIP_PURCHASE_CONFIRMATION, false); - const { currentOffer = null, currentPage = null, purchaseOptions = null, setPurchaseOptions = null } = useCatalog(); - const { getCurrencyAmount = null } = usePurse(); + const [ catalogSkipPurchaseConfirmation ] = useLocalStorage(LocalStorageKeys.CATALOG_SKIP_PURCHASE_CONFIRMATION, false); + const { currentOffer = null, purchaseOptions = null, setPurchaseOptions = null, getNodesByOfferId = null } = useCatalog(); + const { getCurrencyAmount = null } = usePurse(); const onCatalogEvent = useCallback((event: CatalogEvent) => { @@ -89,13 +88,6 @@ export const CatalogPurchaseWidgetView: FC = pro let pageId = currentOffer.page.pageId; - // if(pageId === -1) - // { - // const nodes = getNodesByOfferId(currentOffer.offerId); - - // if(nodes) pageId = nodes[0].pageId; - // } - SendMessageComposer(new PurchaseFromCatalogComposer(pageId, currentOffer.offerId, purchaseOptions.extraData, purchaseOptions.quantity)); } @@ -139,7 +131,7 @@ export const CatalogPurchaseWidgetView: FC = pro switch(purchaseState) { case CatalogPurchaseState.CONFIRM: - return ; + return ; case CatalogPurchaseState.PURCHASE: return ; case CatalogPurchaseState.FAILED: @@ -156,7 +148,7 @@ export const CatalogPurchaseWidgetView: FC = pro <> { (!noGiftOption && !currentOffer.isRentOffer) && - } diff --git a/src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx b/src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx index 12a459f..c677e3a 100644 --- a/src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx +++ b/src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx @@ -1,7 +1,8 @@ -import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'; +import { Dispatch, FC, SetStateAction, useEffect } from 'react'; import { FaSearch } from 'react-icons/fa'; import { GroupItem, LocalizeText } from '../../../../api'; import { Button, Flex } from '../../../../common'; +import { useLocalStorage } from '../../../../hooks'; export interface InventoryFurnitureSearchViewProps { @@ -12,7 +13,7 @@ export interface InventoryFurnitureSearchViewProps export const InventoryFurnitureSearchView: FC = props => { const { groupItems = [], setGroupItems = null } = props; - const [ searchValue, setSearchValue ] = useState(''); + const [ searchValue, setSearchValue ] = useLocalStorage('inventoryFurnitureSearchValue', ''); useEffect(() => { @@ -26,7 +27,8 @@ export const InventoryFurnitureSearchView: FC { if(comparison && comparison.length) { - if(item.name.toLocaleLowerCase().includes(comparison)) return item; + if(comparison === 'rare' && item.isSellable) return item; + if(comparison !== 'rare' && item.name.toLocaleLowerCase().includes(comparison)) return item; } return null; diff --git a/src/hooks/chat-history/useChatHistory.ts b/src/hooks/chat-history/useChatHistory.ts index a2f3c34..4c0aa03 100644 --- a/src/hooks/chat-history/useChatHistory.ts +++ b/src/hooks/chat-history/useChatHistory.ts @@ -3,6 +3,7 @@ import { useState } from 'react'; import { useBetween } from 'use-between'; import { ChatEntryType, ChatHistoryCurrentDate, IChatEntry, IRoomHistoryEntry, MessengerHistoryCurrentDate } from '../../api'; import { useMessageEvent, useRoomSessionManagerEvent } from '../events'; +import { useLocalStorage } from '../useLocalStorage'; const CHAT_HISTORY_MAX = 1000; const ROOM_HISTORY_MAX = 10; @@ -13,10 +14,10 @@ let MESSENGER_HISTORY_COUNTER: number = 0; const useChatHistoryState = () => { - const [ chatHistory, setChatHistory ] = useState([]); - const [ roomHistory, setRoomHistory ] = useState([]); - const [ messengerHistory, setMessengerHistory ] = useState([]); - const [ needsRoomInsert, setNeedsRoomInsert ] = useState(false); + const [ chatHistory, setChatHistory ] = useLocalStorage('chatHistory', []); + const [ roomHistory, setRoomHistory ] = useLocalStorage('roomHistory', []); + const [ messengerHistory, setMessengerHistory ] = useLocalStorage('messengerHistory', []); + const [ needsRoomInsert, setNeedsRoomInsert ] = useLocalStorage('needsRoomInsert', false); const addChatEntry = (entry: IChatEntry) => { diff --git a/src/hooks/useLocalStorage.ts b/src/hooks/useLocalStorage.ts index 1e55fb9..62576e8 100644 --- a/src/hooks/useLocalStorage.ts +++ b/src/hooks/useLocalStorage.ts @@ -2,16 +2,17 @@ import { NitroLogger } from '@nitrots/nitro-renderer'; import { Dispatch, SetStateAction, useState } from 'react'; import { GetLocalStorage, SetLocalStorage } from '../api'; +const userId = new URLSearchParams(window.location.search).get('userid') || 0; + const useLocalStorageState = (key: string, initialValue: T): [ T, Dispatch>] => { + key = userId ? `${ key }.${ userId }` : key; + const [ storedValue, setStoredValue ] = useState(() => { - if(typeof window === 'undefined') return initialValue; - try { - const item = GetLocalStorage(key); - + const item = typeof window !== 'undefined' ? GetLocalStorage(key) as T : undefined; return item ?? initialValue; }