Add last modified date to all sidebar pages

This commit is contained in:
Tyler Hallada 2022-03-14 23:53:55 -04:00
parent 8c86871723
commit e43352ba94
2 changed files with 55 additions and 33 deletions

View File

@ -69,6 +69,17 @@ const Sidebar: React.FC<Props> = ({
return <PluginDetail hash={plugin} counts={counts} />; return <PluginDetail hash={plugin} counts={counts} />;
}; };
const renderLastModified = (lastModified: string | null | undefined) => {
if (lastModified) {
return (
<div className={styles["sidebar-modified-date"]}>
<strong>Last updated:</strong>{" "}
{formatRelative(new Date(lastModified), new Date())}
</div>
);
}
};
const renderOpenSidebar = () => { const renderOpenSidebar = () => {
if (selectedCell) { if (selectedCell) {
return ( return (
@ -76,6 +87,7 @@ const Sidebar: React.FC<Props> = ({
className={styles.sidebar} className={styles.sidebar}
style={!open ? { display: "none" } : {}} style={!open ? { display: "none" } : {}}
> >
<div className={styles["sidebar-content"]}>
<div className={styles["sidebar-header"]}> <div className={styles["sidebar-header"]}>
<button className={styles.close} onClick={onClose}> <button className={styles.close} onClick={onClose}>
<Image src={close} width={24} height={24} alt="close" /> <Image src={close} width={24} height={24} alt="close" />
@ -85,6 +97,8 @@ const Sidebar: React.FC<Props> = ({
Cell {selectedCell.x}, {selectedCell.y} Cell {selectedCell.x}, {selectedCell.y}
</h1> </h1>
{renderCellData(selectedCell)} {renderCellData(selectedCell)}
{renderLastModified(lastModified)}
</div>
</div> </div>
); );
} else if (router.query.mod) { } else if (router.query.mod) {
@ -94,12 +108,15 @@ const Sidebar: React.FC<Props> = ({
className={styles.sidebar} className={styles.sidebar}
style={!open ? { display: "none" } : {}} style={!open ? { display: "none" } : {}}
> >
<div className={styles["sidebar-content"]}>
<div className={styles["sidebar-header"]}> <div className={styles["sidebar-header"]}>
<button className={styles.close} onClick={onClose}> <button className={styles.close} onClick={onClose}>
<Image src={close} width={24} height={24} alt="close" /> <Image src={close} width={24} height={24} alt="close" />
</button> </button>
</div> </div>
{!Number.isNaN(modId) && renderModData(modId)} {!Number.isNaN(modId) && renderModData(modId)}
{renderLastModified(lastModified)}
</div>
</div> </div>
); );
} else if (router.query.plugin) { } else if (router.query.plugin) {
@ -108,6 +125,7 @@ const Sidebar: React.FC<Props> = ({
className={styles.sidebar} className={styles.sidebar}
style={!open ? { display: "none" } : {}} style={!open ? { display: "none" } : {}}
> >
<div className={styles["sidebar-content"]}>
<div className={styles["sidebar-header"]}> <div className={styles["sidebar-header"]}>
<button className={styles.close} onClick={onClose}> <button className={styles.close} onClick={onClose}>
<Image src={close} width={24} height={24} alt="close" /> <Image src={close} width={24} height={24} alt="close" />
@ -118,6 +136,8 @@ const Sidebar: React.FC<Props> = ({
? router.query.plugin ? router.query.plugin
: router.query.plugin[0] : router.query.plugin[0]
)} )}
{renderLastModified(lastModified)}
</div>
</div> </div>
); );
} else { } else {
@ -126,7 +146,7 @@ const Sidebar: React.FC<Props> = ({
className={styles.sidebar} className={styles.sidebar}
style={!open ? { display: "none" } : {}} style={!open ? { display: "none" } : {}}
> >
<div className={styles["default-sidebar"]}> <div className={styles["sidebar-content"]}>
<h2>Modmapper</h2> <h2>Modmapper</h2>
<p className={styles.subheader}> <p className={styles.subheader}>
An interactive map of Skyrim mods. An interactive map of Skyrim mods.
@ -134,12 +154,7 @@ const Sidebar: React.FC<Props> = ({
<DataDirPicker /> <DataDirPicker />
<PluginTxtEditor /> <PluginTxtEditor />
<PluginsList /> <PluginsList />
{lastModified && ( {renderLastModified(lastModified)}
<div className={styles["sidebar-modified-date"]}>
<strong>Last updated:</strong>{" "}
{formatRelative(new Date(lastModified), new Date())}
</div>
)}
</div> </div>
</div> </div>
); );
@ -157,13 +172,17 @@ const Sidebar: React.FC<Props> = ({
className={styles.open} className={styles.open}
onClick={() => setOpen(true)} onClick={() => setOpen(true)}
title="Show sidebar" title="Show sidebar"
><Image src={arrow} alt="show" width={16} height={16} /></button> >
<Image src={arrow} alt="show" width={16} height={16} />
</button>
) : ( ) : (
<button <button
className={styles.hide} className={styles.hide}
onClick={() => setOpen(false)} onClick={() => setOpen(false)}
title="Hide sidebar" title="Hide sidebar"
><Image src={arrow} alt="hide" width={16} height={16} /></button> >
<Image src={arrow} alt="hide" width={16} height={16} />
</button>
)} )}
{renderOpenSidebar()} {renderOpenSidebar()}
</> </>

View File

@ -11,6 +11,7 @@
padding-top: 24px; padding-top: 24px;
font-size: 0.875rem; font-size: 0.875rem;
border: 1px solid #222222; border: 1px solid #222222;
height: 100%;
} }
@media only screen and (max-width: 600px) { @media only screen and (max-width: 600px) {
@ -134,7 +135,7 @@
word-wrap: break-word; word-wrap: break-word;
} }
.default-sidebar { .sidebar-content {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%; height: 100%;
@ -142,6 +143,8 @@
.sidebar-modified-date { .sidebar-modified-date {
margin-top: auto; margin-top: auto;
padding-top: 12px;
padding-bottom: 12px;
} }
.subheader { .subheader {