-
Notifications
You must be signed in to change notification settings - Fork 16
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 #85 from mnsrulz/main
sync: main to stage
- Loading branch information
Showing
4 changed files
with
116 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use client'; | ||
import { useCachedReleaseSymbolData } from '@/lib/socket'; | ||
import { Dialog, DialogContent, DialogTitle, ImageList, ImageListItem, useMediaQuery, useTheme } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { IconButton } from '@mui/material'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
import { useMyLocalWatchList } from '@/lib/hooks'; | ||
export const HistoricalDex = (props: { dt: string, showAllSymbols: boolean }) => { | ||
const { wl } = useMyLocalWatchList([]); | ||
const mytickersSymbols = wl.map(r => r.symbol); | ||
const { dt, showAllSymbols } = props; | ||
const { cachedSummarySymbolsData } = useCachedReleaseSymbolData(dt); | ||
const theme = useTheme(); | ||
const matchesXs = useMediaQuery(theme.breakpoints.down("sm")); | ||
const matchesMd = useMediaQuery(theme.breakpoints.down("md")); | ||
const numberOfItemsToDisplay = matchesXs ? 2 : matchesMd ? 3 : 4; | ||
const ts = cachedSummarySymbolsData.filter(r => showAllSymbols || mytickersSymbols.includes(r.name)); //make sure to load only those which are part of the watchlist. | ||
|
||
const [openDialog, setOpenDialog] = useState(false); | ||
const [selectedImage, setSelectedImage] = useState(''); | ||
|
||
const handleImageClick = (imageSrc: string) => { | ||
setSelectedImage(imageSrc); | ||
setOpenDialog(true); | ||
}; | ||
|
||
const handleCloseDialog = () => { | ||
setOpenDialog(false); | ||
}; | ||
return <><ImageList cols={numberOfItemsToDisplay} gap={1}> | ||
{ts.map((item) => ( | ||
<ImageListItem key={item.name} sx={{ width: '100%', height: '100px' }}> | ||
<img src={`https://mztrading-data.deno.dev/images?dt=${dt}&s=${item.name}`} | ||
style={{ | ||
width: '100%', height: 'auto', objectFit: 'cover', | ||
transition: 'all 0.3s ease-in-out', | ||
cursor: 'pointer', | ||
// boxShadow: '0 0 10px rgba(0, 0, 0, 0.2)', | ||
// '&:hover': { | ||
// boxShadow: '0 0 20px rgba(0, 0, 0, 0.5)', | ||
// transform: 'scale(1.05)', | ||
// } | ||
|
||
}} | ||
loading="lazy" | ||
onClick={() => handleImageClick(`https://mztrading-data.deno.dev/images?dt=${dt}&s=${item.name}`)} /> | ||
</ImageListItem> | ||
))} | ||
</ImageList> | ||
<Dialog open={openDialog} onClose={handleCloseDialog} fullScreen={matchesXs}> | ||
<DialogTitle> | ||
<IconButton | ||
aria-label="close" | ||
onClick={handleCloseDialog} | ||
sx={{ position: 'absolute', right: 8, top: 8 }} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</DialogTitle> | ||
<DialogContent> | ||
<img src={selectedImage} style={{ width: '100%', objectFit: 'contain' }} /> | ||
</DialogContent> | ||
</Dialog> | ||
</>; | ||
} |
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 |
---|---|---|
@@ -1,13 +1,33 @@ | ||
'use client'; | ||
import { useCallback, useState } from "react" | ||
import { useLocalStorage } from "@uidotdev/usehooks"; | ||
import { SearchTickerItem } from "./types"; | ||
|
||
export const useShowCloseTrades = () => { | ||
const [showCloseTrades, setShowCloseTrades] = useState((typeof window !== "undefined" ? window?.localStorage?.getItem("showCloseTrades") == 'true': false) || false); | ||
const [showCloseTrades, setShowCloseTrades] = useState((typeof window !== "undefined" ? window?.localStorage?.getItem("showCloseTrades") == 'true' : false) || false); | ||
const toggleShowCloseTrades = useCallback((newstate: boolean) => { | ||
setShowCloseTrades(newstate); | ||
window?.localStorage?.setItem("showCloseTrades", `${newstate}`); | ||
}, []); | ||
|
||
return {showCloseTrades, toggleShowCloseTrades } | ||
return { showCloseTrades, toggleShowCloseTrades } | ||
} | ||
|
||
export const useMyLocalWatchList = (initialState: SearchTickerItem[]) => { | ||
const [wl, setWl] = useLocalStorage("localwatchlist", initialState); | ||
|
||
const removeFromMyList = (item: SearchTickerItem) => { | ||
setWl(v => v.filter((ticker) => ticker.symbol != item.symbol)); | ||
} | ||
|
||
const addToMyList = (item: SearchTickerItem) => { | ||
setWl(v => { | ||
v.push(item) | ||
return v; | ||
}); | ||
} | ||
|
||
return { wl, removeFromMyList, addToMyList } | ||
} | ||
|
||
|