Fix : the local storage - user id

This commit is contained in:
duckietm 2024-03-27 15:04:35 +01:00
parent 55ed1aba63
commit 2f59dff14f
4 changed files with 22 additions and 26 deletions

View File

@ -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,10 +14,9 @@ interface CatalogPurchaseWidgetViewProps
export const CatalogPurchaseWidgetView: FC<CatalogPurchaseWidgetViewProps> = 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 [ 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<CatalogPurchaseWidgetViewProps> = 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<CatalogPurchaseWidgetViewProps> = pro
switch(purchaseState)
{
case CatalogPurchaseState.CONFIRM:
return <Button variant="warning" onClick={ event => purchase() }>{ LocalizeText('catalog.marketplace.confirm_title') }</Button>;
return <Button variant="warning" onClick={ () => purchase() }>{ LocalizeText('catalog.marketplace.confirm_title') }</Button>;
case CatalogPurchaseState.PURCHASE:
return <Button disabled><LayoutLoadingSpinnerView /></Button>;
case CatalogPurchaseState.FAILED:
@ -156,7 +148,7 @@ export const CatalogPurchaseWidgetView: FC<CatalogPurchaseWidgetViewProps> = pro
<>
<PurchaseButton />
{ (!noGiftOption && !currentOffer.isRentOffer) &&
<Button disabled={ ((purchaseOptions.quantity > 1) || !currentOffer.giftable || isLimitedSoldOut || (purchaseOptions.extraParamRequired && (!purchaseOptions.extraData || !purchaseOptions.extraData.length))) } onClick={ event => purchase(true) }>
<Button disabled={ ((purchaseOptions.quantity > 1) || !currentOffer.giftable || isLimitedSoldOut || (purchaseOptions.extraParamRequired && (!purchaseOptions.extraData || !purchaseOptions.extraData.length))) } onClick={ () => purchase(true) }>
{ LocalizeText('catalog.purchase_confirmation.gift') }
</Button> }
</>

View File

@ -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<InventoryFurnitureSearchViewProps> = props =>
{
const { groupItems = [], setGroupItems = null } = props;
const [ searchValue, setSearchValue ] = useState('');
const [ searchValue, setSearchValue ] = useLocalStorage('inventoryFurnitureSearchValue', '');
useEffect(() =>
{
@ -26,7 +27,8 @@ export const InventoryFurnitureSearchView: FC<InventoryFurnitureSearchViewProps>
{
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;

View File

@ -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<IChatEntry[]>([]);
const [ roomHistory, setRoomHistory ] = useState<IRoomHistoryEntry[]>([]);
const [ messengerHistory, setMessengerHistory ] = useState<IChatEntry[]>([]);
const [ needsRoomInsert, setNeedsRoomInsert ] = useState(false);
const [ chatHistory, setChatHistory ] = useLocalStorage<IChatEntry[]>('chatHistory', []);
const [ roomHistory, setRoomHistory ] = useLocalStorage<IRoomHistoryEntry[]>('roomHistory', []);
const [ messengerHistory, setMessengerHistory ] = useLocalStorage<IChatEntry[]>('messengerHistory', []);
const [ needsRoomInsert, setNeedsRoomInsert ] = useLocalStorage('needsRoomInsert', false);
const addChatEntry = (entry: IChatEntry) =>
{

View File

@ -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 = <T>(key: string, initialValue: T): [ T, Dispatch<SetStateAction<T>>] =>
{
key = userId ? `${ key }.${ userId }` : key;
const [ storedValue, setStoredValue ] = useState<T>(() =>
{
if(typeof window === 'undefined') return initialValue;
try
{
const item = GetLocalStorage<T>(key);
const item = typeof window !== 'undefined' ? GetLocalStorage<T>(key) as T : undefined;
return item ?? initialValue;
}