LastSessionsView

- added missing localization
- no reload on delete
This commit is contained in:
Martin Bauer 2023-10-02 09:41:48 +02:00
parent 9b6bb7f126
commit a576e91290
4 changed files with 28 additions and 12 deletions

View File

@ -1,9 +1,10 @@
import moment from 'moment/min/moment-with-locales';
import {i18n} from './i18n';
function timeSince(timeStamp, lang = 'de') {
moment.locale(lang);
function timeSince(timeStamp) {
moment.locale(i18n.locale);
const now = Math.floor((new Date()).getTime() / 1000);
const secondsPast = now - timeStamp;
@ -23,7 +24,7 @@ function timeSince(timeStamp, lang = 'de') {
else if (timeStampDate.getDate() + 1 == dateNow.getDate())
dateStr = "Gestern, " + timeStampMoment.format("HH:mm");
else {
dateStr = timeStampMoment.format("ddd, DD.MM.YY um HH:mm");
dateStr = timeStampMoment.format("llll");
}
return dateStr;
}

View File

@ -11,7 +11,8 @@ const translation_store = {
settings: "Settings",
lastSessions: "Last Sessions",
mainMenu_social: "Social",
mainMenu_swimNow: "Swim now"
mainMenu_swimNow: "Swim now",
delete_session_button: "Delete",
},
de : {
connecting: "Verbindung aufbauen",
@ -23,6 +24,7 @@ const translation_store = {
lastSessions: "Letzte Sessions",
mainMenu_social: "Freunde",
mainMenu_swimNow: "Jetzt schwimmen",
delete_session_button: "Löschen",
}
}

View File

@ -55,7 +55,7 @@ function SessionCardBehindSwipe(props) {
style={sessionCardStyles.deleteButton}
onPress={props.onDelete}
>
<Text style={{ fontSize: 18, color: "white" }}>Löschen</Text>
<Text style={{ fontSize: 18, color: "white" }}>{i18n.t('delete_session_button')}</Text>
</TouchableOpacity>
</View>
);
@ -137,9 +137,6 @@ function parsePropfind(text) {
const parser = new XMLParser();
const xmlDoc = parser.parseFromString(text);
//const parser = new DOMParser();
//const xmlDoc = parser.parseFromString(text, "text/xml");
const responses = xmlDoc.getElementsByTagName("D:response");
let result = [];
for (let i = 0; i < responses.length; ++i) {
@ -183,6 +180,7 @@ async function getFullData(swimTrackerHost, analysisSettings) {
const da = new DataAnalysis();
e.analysis = da.analyze(analysisSettings, e.startTime, e.values);
}
console.log("full data", parsed);
return parsed;
}
@ -203,9 +201,14 @@ class LastSessionsView extends React.Component {
render() {
const deleteSession = async sessionFileName => {
this.setState({ sessions: null });
await request({ url: "http://" + this.props.swimTrackerHost + "/webdav/" + sessionFileName, method: "DELETE" });
this.setState({ sessions: await getFullData(this.props.swimTrackerHost, this.props.analysisSettings) });
const filteredSession = this.state.sessions.filter((element) => element.name != sessionFileName);
this.setState({ sessions: filteredSession });
request({ url: "http://" + this.props.swimTrackerHost + "/webdav/" + sessionFileName, method: "DELETE" })
.then((value) => console.log("Successfully deleted", sessionFileName, value))
.catch((err) => console.error("Failed to delete", sessionFileName, err));
//this.setState({ sessions: null });
//await request({ url: "http://" + this.props.swimTrackerHost + "/webdav/" + sessionFileName, method: "DELETE" });
//this.setState({ sessions: await getFullData(this.props.swimTrackerHost, this.props.analysisSettings) });
};
const onRefresh = async () => {

View File

@ -21,7 +21,12 @@ as of 2023-09
`npx expo install react-native-web react-dom @expo/webpack-config`
3. Install Dependencies
3. Run
------
npx expo start -w
4. Install Dependencies
-----------------------
use `npx expo install` instead of `yarn add` !
@ -56,3 +61,8 @@ react-xml-parser
# Graph
react-native-svg
# Time since
# to be replaced
react-native-swipe-list-view