-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introduce a new component, `StatsTimestamp`, responsible for displaying timestamps with tooltips. This component accepts a `messageType` prop to determine whether to show a generic or project-specific message. The inconsistent icon usage has been resolved, now consistently using an info icon. - Reorganized the codebase by removing timestamp implementations from the User Contributions and Project Stats components. Instead, these components now utilize the newly introduced `StatsTimestamp` component for timestamp display. - Integrated the `StatsTimestamp` component into the Total Features section of the overall statistics page.
- Loading branch information
1 parent
c6a4bb0
commit 0c30aea
Showing
11 changed files
with
111 additions
and
69 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,44 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import ReactTooltip from 'react-tooltip'; | ||
|
||
import { fetchExternalJSONAPI } from '../../network/genericJSONRequest'; | ||
import { OHSOME_STATS_BASE_URL } from '../../config'; | ||
import { InfoIcon } from '../svgIcons'; | ||
import messages from './messages'; | ||
|
||
function StatsTimestamp({ messageType }) { | ||
const intl = useIntl(); | ||
const [lastUpdated, setLastUpdated] = useState(null); | ||
|
||
useEffect(() => { | ||
fetchExternalJSONAPI(`${OHSOME_STATS_BASE_URL}/metadata`) | ||
.then((res) => { | ||
setLastUpdated(res.result.max_timestamp); | ||
}) | ||
.catch((error) => console.error(error)); | ||
}, []); | ||
|
||
const dateOptions = { | ||
year: 'numeric', | ||
month: 'short', | ||
day: '2-digit', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
}; | ||
|
||
return ( | ||
<div> | ||
<InfoIcon | ||
className="blue-grey h1 w1 v-mid ml2 pointer" | ||
data-tip={intl.formatMessage(messages[messageType], { | ||
formattedDate: intl.formatDate(lastUpdated, dateOptions), | ||
})} | ||
data-for="ohsome-timestamp" | ||
/> | ||
<ReactTooltip id="ohsome-timestamp" place="top" className="mw6" effect="solid" /> | ||
</div> | ||
); | ||
} | ||
|
||
export default StatsTimestamp; |
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,13 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
export default defineMessages({ | ||
generic: { | ||
id: 'stats.ohsome.timestamp.generic', | ||
defaultMessage: 'These statistics were last updated at {formattedDate}', | ||
}, | ||
project: { | ||
id: 'stats.ohsome.timestamp.project', | ||
defaultMessage: | ||
'These stats were retrieved using the default changeset comment of the project and were last updated at {formattedDate}', | ||
}, | ||
}); |
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
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