-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from Yiroh/Hiding-Data
Successfully implemented hiding and showing
- Loading branch information
Showing
25 changed files
with
514 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { formatAmount } from '@/lib/utils'; | ||
|
||
interface AmountDisplayProps { | ||
value: number; | ||
currency: string; | ||
isHidden: boolean; | ||
} | ||
|
||
export function AmountDisplay({ value, currency, isHidden }: AmountDisplayProps) { | ||
return <span>{isHidden ? '••••' : formatAmount(value, currency)}</span>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useBalancePrivacy } from '@/context/privacy-context'; | ||
import { cn } from '@/lib/utils'; | ||
import { formatAmount } from '@/lib/utils'; | ||
|
||
interface PrivacyAmountProps extends React.HTMLAttributes<HTMLSpanElement> { | ||
value: number; | ||
currency: string; | ||
} | ||
|
||
export function PrivacyAmount({ value, currency, className, ...props }: PrivacyAmountProps) { | ||
const { isBalanceHidden } = useBalancePrivacy(); | ||
|
||
return ( | ||
<span className={cn(className)} {...props}> | ||
{isBalanceHidden ? '••••' : formatAmount(value, currency)} | ||
</span> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useBalancePrivacy } from '@/context/privacy-context'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Icons } from '@/components/icons'; | ||
import { cn } from '@/lib/utils'; | ||
|
||
interface PrivacyToggleProps { | ||
className?: string; | ||
} | ||
|
||
export function PrivacyToggle({ className }: PrivacyToggleProps) { | ||
const { isBalanceHidden, toggleBalanceVisibility } = useBalancePrivacy(); | ||
|
||
return ( | ||
<Button | ||
variant="secondary" | ||
size="icon" | ||
className={cn('mt-1 h-8 w-8 rounded-full', className)} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
toggleBalanceVisibility(); | ||
}} | ||
> | ||
{isBalanceHidden ? <Icons.Eye className="h-4 w-4" /> : <Icons.EyeOff className="h-4 w-4" />} | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { formatStockQuantity } from '@/lib/utils'; | ||
|
||
interface QuantityDisplayProps { | ||
value: number; | ||
isHidden: boolean; | ||
} | ||
|
||
export function QuantityDisplay({ value, isHidden }: QuantityDisplayProps) { | ||
return <span>{isHidden ? '••••' : formatStockQuantity(value)}</span>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createContext, useContext, useEffect, useState } from 'react'; | ||
|
||
interface PrivacyContextType { | ||
isBalanceHidden: boolean; | ||
toggleBalanceVisibility: () => void; | ||
} | ||
|
||
const PrivacyContext = createContext<PrivacyContextType | undefined>(undefined); | ||
|
||
const STORAGE_KEY = 'privacy-settings'; | ||
|
||
export function PrivacyProvider({ children }: { children: React.ReactNode }) { | ||
const [isBalanceHidden, setIsBalanceHidden] = useState(() => { | ||
const stored = localStorage.getItem(STORAGE_KEY); | ||
return stored ? JSON.parse(stored) : false; | ||
}); | ||
|
||
useEffect(() => { | ||
localStorage.setItem(STORAGE_KEY, JSON.stringify(isBalanceHidden)); | ||
}, [isBalanceHidden]); | ||
|
||
function toggleBalanceVisibility() { | ||
setIsBalanceHidden((prev: boolean) => !prev); | ||
} | ||
|
||
return ( | ||
<PrivacyContext.Provider value={{ isBalanceHidden, toggleBalanceVisibility }}> | ||
{children} | ||
</PrivacyContext.Provider> | ||
); | ||
} | ||
|
||
export function useBalancePrivacy() { | ||
const context = useContext(PrivacyContext); | ||
if (context === undefined) { | ||
throw new Error('useBalancePrivacy must be used within a PrivacyProvider'); | ||
} | ||
return context; | ||
} |
Oops, something went wrong.