Skip to content

Commit

Permalink
#317 share view
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed May 22, 2024
1 parent 97fbc43 commit 258dc1e
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 160 deletions.
10 changes: 9 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { useTranslation } from "react-i18next";
import Store from "./Store";
import { logout } from "./utils/loginUtils";
import ShareCenter from "./states/ShareCenter";
import AddSensorModal from "./components/AddSensorModal";
import SettingsModal from "./components/SettingsModal";
import MyAccountModal from "./components/MyAccountModal";
const SignIn = React.lazy(() => import("./states/SignIn"));
const Dashboard = React.lazy(() => import("./states/Dashboard"));
const UserMenu = React.lazy(() => import("./components/UserMenu"));
Expand Down Expand Up @@ -265,7 +268,7 @@ export default function App() {
</>}
<div>
<Routes>
<Route path="/shares" element={<ShareCenter />} />
<Route path="/shares" element={<ShareCenter showDialog={showDialog} closeDialog={() => setShowDialog("")} />} />
<Route path="/:id" element={<Dashboard reloadTags={() => { setReloadSub(reloadSub + 1); forceUpdate() }} showDialog={showDialog} closeDialog={() => setShowDialog("")} />} />
<Route path="/" element={<Dashboard reloadTags={() => { setReloadSub(reloadSub + 1); forceUpdate() }} showDialog={showDialog} closeDialog={() => setShowDialog("")} />} />
</Routes>
Expand All @@ -274,6 +277,11 @@ export default function App() {
<div style={versionText}>v{pjson.version} <a href="https://f.ruuvi.com/t/5039/9999" target="_blank" rel="noreferrer">{t("changelog")}</a></div>
</div>
</BrowserRouter>
<AddSensorModal open={showDialog === "addsensor"} onClose={() => setShowDialog("")} updateApp={() => { setReloadSub(reloadSub + 1); forceUpdate() }} />
<SettingsModal open={showDialog === "settings"} onClose={() => setShowDialog("")} updateUI={() => this.forceUpdate()} />
{showDialog === "myaccount" &&
<MyAccountModal open={true} onClose={() => setShowDialog("")} updateApp={() => this.props.reloadTags()} />
}
</ChakraProvider>
);
}
12 changes: 11 additions & 1 deletion src/NetworkApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NetworkApi {
document.cookie = `station_status=signedIn;domain=${domain};Max-Age=-99999999`
}
isStaging() {
return localStorage.getItem("env") === "staging"
return localStorage.getItem("env") === "staging"
}
setEnv(env) {
localStorage.setItem("env", env)
Expand Down Expand Up @@ -224,6 +224,16 @@ class NetworkApi {
success(response);
})
}
async shareAsync(mac, email) {
const response = await fetch(this.url + "/share", {
...this.options,
method: 'POST',
body: JSON.stringify({ sensor: mac, user: email }),
});
checkStatusCode(response);
const data = await response.json();
return data
}
unshare(mac, email, success) {
fetch(this.url + "/unshare", {
...this.options,
Expand Down
2 changes: 1 addition & 1 deletion src/TextHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function addNewlines(str, newlineChar) {

export function addVariablesInString(str, variables) {
for (let i = 0; i < variables.length; i++) {
str = str.replace(/{(.*?)}/, variables[i])
str = str.replace(/{.*?\}/, variables[i])
}
return str
}
2 changes: 1 addition & 1 deletion src/components/ShareDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ShareDialog extends Component {
}
unshare(email) {
if (this.state.loading) return;
var confirmMessage = this.props.t("share_sensor_unshare_confirm").replace("{%@^%1$s}", email)
var confirmMessage = addVariablesInString(this.props.t("share_sensor_unshare_confirm"), [email])
if (window.confirm(confirmMessage)) {
this.setState({ ...this.state, loading: true })
new NetworkApi().unshare(this.props.sensor.sensor, email, resp => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UserMenu extends Component {
<MenuItem style={{ fontFamily: "mulish", fontSize: 15, fontWeight: 800 }} onClick={() => this.seeSettings()}>Show settings</MenuItem>
<MenuItem style={{ fontFamily: "mulish", fontSize: 15, fontWeight: 800 }} onClick={() => this.seeAlerts()}>Show alerts</MenuItem>
*/}
<MenuItem style={{ fontFamily: "mulish", fontSize: 15, fontWeight: 800 }} onClick={() => this.props.navigate('/shares')}>{t("shares")}</MenuItem>
<MenuItem style={{ fontFamily: "mulish", fontSize: 15, fontWeight: 800 }} onClick={() => this.props.navigate('/shares')}>{t("share_center")}</MenuItem>
<MenuDivider />
<MenuItem style={{ fontFamily: "mulish", fontSize: 15, fontWeight: 800 }} onClick={() => this.settings()}>{t("settings")}</MenuItem>
<MenuDivider />
Expand Down
90 changes: 80 additions & 10 deletions src/localization_i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ago": "ago",
"movement": "Movement",
"alert_movement_description": "Movement alert is triggered if the value of the sensor's internal motion counter changes. This alert can be used, for example, to detect door movement or vibration in the vicinity of the sensor.",
"alert_description": "Alert when less than {%.0f^%1$s} or more than {%.0f^%2$s}",
"alert_description": "Alert when less than {%@^%1$s} or more than {%@^%2$s}",
"battery_voltage": "Battery Voltage",
"calibrate": "Calibrate",
"cancel": "Cancel",
Expand Down Expand Up @@ -149,6 +149,7 @@
"successfully_unshared": "Successfully unshared",
"zoom": "Zoom",
"alert_enabled": "Alert successfully enabled",
"select_sensor": "Select sensor",
"movements": "movements",
"history": "History",
"selected": "Selected",
Expand Down Expand Up @@ -248,7 +249,20 @@
"latest_measured_value": "Latest measured value: {%@^%1$s}",
"pick_first_day": "Please pick the start date.",
"pick_second_day": "Please pick the end date.",
"set": "Set"
"set": "Set",
"upgrade_plan": "Upgrade plan",
"active_shares": "Active shares",
"remove_share_title": "Remove share",
"share_center": "Share center",
"share_center_subtitle": "Share your sensors with others",
"share_center_description": "Share your sensor data securely and easily.",
"shared_by_me": "Shared by me",
"shared_to_me": "Shared to me",
"sharing_progress": "Sharing {}/{}...",
"sensor_shared_to_email": "{} shared to {}",
"sensor_not_shared_to_email": "{} not shared to {}",
"share_result": "Share result",
"sensor_removed": "Sensor removed"
}
},
"fi": {
Expand Down Expand Up @@ -276,7 +290,7 @@
"ago": "sitten",
"movement": "Liike",
"alert_movement_description": "Liikehälytys laukeaa, jos anturin sisäisen liikelaskurin arvo muuttuu. Tätä hälytystä voi käyttää esimerkiksi havaitsemaan oven liikkeen tai tärinän anturin läheisyydessä.",
"alert_description": "Hälytä, mikäli alle {%.0f^%1$s} tai yli {%.0f^%2$s}",
"alert_description": "Hälytä, mikäli alle {%@^%1$s} tai yli {%@^%2$s}",
"battery_voltage": "Paristojännite",
"calibrate": "Kalibroi",
"cancel": "Peruuta",
Expand Down Expand Up @@ -401,6 +415,7 @@
"successfully_unshared": "Jakamisen peruutus onnistui",
"zoom": "Zoomaa",
"alert_enabled": "Hälytys käynnistetty onnistuneesti",
"select_sensor": "Valitse anturi",
"movements": "liikettä",
"history": "Historia",
"selected": "Valittu",
Expand Down Expand Up @@ -500,7 +515,20 @@
"latest_measured_value": "Viimeisin mitattu arvo: {%@^%1$s}",
"pick_first_day": "Valitse aloituspäivä.",
"pick_second_day": "Valitse päättymispäivä.",
"set": "Aseta"
"set": "Aseta",
"upgrade_plan": "Päivitä tilaustaso",
"active_shares": "Aktiiviset jaot",
"remove_share_title": "Poista jako",
"share_center": "Jako keskus",
"share_center_subtitle": "Jaa anturisi muiden kanssa",
"share_center_description": "Jaa anturidatasi turvallisesti ja helposti.",
"shared_by_me": "Minun jakamani",
"shared_to_me": "Minulle jaettu",
"sharing_progress": "Jaetaan {}/{}...",
"sensor_shared_to_email": "{} jaettu {}",
"sensor_not_shared_to_email": "{} ei jaettu {}",
"share_result": "Jaa tulos",
"sensor_removed": "Anturi poistettu"
}
},
"sv": {
Expand Down Expand Up @@ -528,7 +556,7 @@
"ago": "sedan",
"movement": "Rörelse",
"alert_movement_description": "Ett rörelselarm utlöses om värdet på sensorns interna rörelseräknare ändras. Detta larm kan till exempel användas för att detektera dörrrörelser eller vibrationer i närheten av sensorn.",
"alert_description": "Alarmera när mindre än {%.0f^%1$s} eller mer än {%.0f^%2$s}",
"alert_description": "Alarmera när mindre än {%@^%1$s} eller mer än {%@^%2$s}",
"battery_voltage": "Batterispänning",
"calibrate": "Kalibrera",
"cancel": "Avbryt",
Expand Down Expand Up @@ -653,6 +681,7 @@
"successfully_unshared": "Delningen har tagits bort",
"zoom": "Zoom",
"alert_enabled": "Alarm har aktiverats",
"select_sensor": "Välj sensor",
"movements": "rörelser",
"history": "Historik",
"selected": "Vald",
Expand Down Expand Up @@ -752,7 +781,20 @@
"latest_measured_value": "Senaste uppmätta värde: {%@^%1$s}",
"pick_first_day": "Välj ett startdatum.",
"pick_second_day": "Välj ett slutdatum.",
"set": "Ange"
"set": "Ange",
"upgrade_plan": "Uppgradera plan",
"active_shares": "Aktiva delningar",
"remove_share_title": "Ta bort delning",
"share_center": "Delningscenter",
"share_center_subtitle": "Dela dina sensorer med andra",
"share_center_description": "Dela din sensordata säkert och enkelt.",
"shared_by_me": "Delat av mig",
"shared_to_me": "Delat till mig",
"sharing_progress": "Delar {}/{}...",
"sensor_shared_to_email": "{} delat till {}",
"sensor_not_shared_to_email": "{} inte delat till {}",
"share_result": "Dela resultat",
"sensor_removed": "Sensor borttagen"
}
},
"fr": {
Expand Down Expand Up @@ -780,7 +822,7 @@
"ago": "avant",
"movement": "Mouvement",
"alert_movement_description": "Une alarme de mouvement se déclenche si la valeur du compteur de mouvement interne du capteur change. Cette alarme peut être utilisée, par exemple, pour détecter un mouvement ou une vibration de porte à proximité du capteur.",
"alert_description": "Notifier si la valeur est inférieure à {%.0f^%1$s} ou supérieure à {%.0f^%2$s}",
"alert_description": "Notifier si la valeur est inférieure à {%@^%1$s} ou supérieure à {%@^%2$s}",
"battery_voltage": "Tension de la pile",
"calibrate": "Calibrer",
"cancel": "Annuler",
Expand Down Expand Up @@ -905,6 +947,7 @@
"successfully_unshared": "Partage annulé avec succès",
"zoom": "Agrandir",
"alert_enabled": "Alerte activée avec succès",
"select_sensor": "Choisissez le capteur",
"movements": "mouvements",
"history": "Historique",
"selected": "Choisi",
Expand Down Expand Up @@ -1004,7 +1047,20 @@
"latest_measured_value": "Dernière valeur mesurée : {%@^%1$s}",
"pick_first_day": "Sélectionnez une date de début.",
"pick_second_day": "Sélectionnez une date de fin.",
"set": "Définir"
"set": "Définir",
"upgrade_plan": "Mettre à niveau le plan",
"active_shares": "Partages actifs",
"remove_share_title": "Supprimer le partage",
"share_center": "Centre de partage",
"share_center_subtitle": "Partagez vos capteurs avec d'autres",
"share_center_description": "Partagez vos données de capteur en toute sécurité et facilement.",
"shared_by_me": "Partagé par moi",
"shared_to_me": "Partagé avec moi",
"sharing_progress": "Partage {}/{}...",
"sensor_shared_to_email": "{} partagé à {}",
"sensor_not_shared_to_email": "{} pas partagé à {}",
"share_result": "Partager le résultat",
"sensor_removed": "Capteur supprimé"
}
},
"de": {
Expand Down Expand Up @@ -1032,7 +1088,7 @@
"ago": "vor",
"movement": "Bewegung",
"alert_movement_description": "Ändert sich der Wert des sensorinternen Bewegungszählers, wird ein Bewegungsalarm ausgelöst. Mit diesem Alarm können beispielsweise Türbewegungen oder Vibrationen in der Nähe des Sensors erkannt werden.",
"alert_description": "Warnung bei weniger als {%.0f^%1$s} oder mehr als {%.0f^%2$s}",
"alert_description": "Warnung bei weniger als {%@^%1$s} oder mehr als {%@^%2$s}",
"battery_voltage": "Batteriespannung",
"calibrate": "Kalibrieren",
"cancel": "Abbrechen",
Expand Down Expand Up @@ -1157,6 +1213,7 @@
"successfully_unshared": "Erfolgreich enteilt",
"zoom": "Zoom",
"alert_enabled": "Benachrichtigung erfolgreich aktiviert",
"select_sensor": "Sensor auswählen",
"movements": "bewegungen",
"history": "Verlauf",
"selected": "Ausgewählt",
Expand Down Expand Up @@ -1256,7 +1313,20 @@
"latest_measured_value": "Letzter Messwert: {%@^%1$s}",
"pick_first_day": "Wählen Sie ein Startdatum.",
"pick_second_day": "Wählen Sie ein Enddatum aus.",
"set": "Setzen"
"set": "Setzen",
"upgrade_plan": "Plan aufwerten",
"active_shares": "Aktive Freigaben",
"remove_share_title": "Freigabe entfernen",
"share_center": "Freigabezentrum",
"share_center_subtitle": "Teilen Sie Ihre Sensoren mit anderen",
"share_center_description": "Teilen Sie Ihre Sensordaten sicher und einfach.",
"shared_by_me": "Von mir geteilt",
"shared_to_me": "Mit mir geteilt",
"sharing_progress": "Teilen {}/{}...",
"sensor_shared_to_email": "{} geteilt mit {}",
"sensor_not_shared_to_email": "{} nicht geteilt mit {}",
"share_result": "Ergebnis teilen",
"sensor_removed": "Sensor entfernt"
}
}
}
5 changes: 0 additions & 5 deletions src/states/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,6 @@ class Dashboard extends Component {
</Box>
</Box>
</Box>
<SettingsModal open={this.showModal("settings")} onClose={() => this.closeModal()} updateUI={() => this.forceUpdate()} />
{this.showModal("myaccount") &&
<MyAccountModal open={this.showModal("myaccount")} onClose={() => this.closeModal()} updateApp={() => this.props.reloadTags()} />
}
<AddSensorModal open={this.showModal("addsensor")} onClose={() => this.closeModal()} updateApp={() => this.props.reloadTags()} />
<ShareDialog open={this.state.showShareFor} onClose={() => this.setState({ ...this.state, showShareFor: null })} sensor={this.state.showShareFor} updateSensor={(s) => this.updateSensor(s)} />
<EditNameDialog open={this.state.rename} onClose={() => this.setState({ ...this.state, rename: null })} sensor={this.state.rename} updateSensor={(s) => this.updateSensor(s)} />
<ConfirmationDialog open={this.state.showResetOrderConfirmation} title="dialog_are_you_sure" description='reset_order_confirmation' onClose={(yes) => this.resetOrder(yes)} />
Expand Down
Loading

0 comments on commit 258dc1e

Please sign in to comment.