Skip to content

Commit

Permalink
Change SAVE button text according to session already existing
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszKlonowski committed Aug 17, 2024
1 parent 8edbe56 commit d8697a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions app/src/popup/MainPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
import ReactDOM from "react-dom";
import ExpandedSessionListInput from "./components/ExpandedSessionListInput";
import ActionButton from "./components/ActionButton";
import Database from "../engine/Database";

if (!browser) {
var browser = require("webextension-polyfill");
Expand All @@ -13,15 +14,35 @@ export class MainPopup extends React.Component {
super(props);
this.state = {
extensionName: "Session Storage",
selectedSession: "",
saveButtonTitle: "",
};

this.onTextInputChange = this.onTextInputChange.bind(this);
this.onSessionsLoad = this.onSessionsLoad.bind(this);
}

onSessionsLoad(sessions) {
const buttonTitle = sessions.includes(this.state.selectedSession) ? "OVERWRITE" : "SAVE";
this.setState({saveButtonTitle: buttonTitle});
}

onTextInputChange(newValue) {
const db = new Database();
this.setState({selectedSession: newValue});
db.loadSessions(this.onSessionsLoad);
}

render() {
return (
<form id="mainForm">
<ExpandedSessionListInput />
<ExpandedSessionListInput onTextInputChange={this.onTextInputChange} />
<div className="panel-actions">
<ActionButton name="saveButton" text="SAVE" icon="glyphicon glyphicon-floppy-disk" />
<ActionButton
name="saveButton"
text={this.state.saveButtonTitle}
icon="glyphicon glyphicon-floppy-disk"
/>
<ActionButton name="deleteButton" text="DELETE" icon="glyphicon glyphicon-trash" />
<ActionButton name="reopenButton" text="REOPEN" icon="glyphicon glyphicon-refresh" />
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/src/popup/components/ExpandedSessionListInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ export class ExpandedSessionListInput extends React.Component {
}

onSelect(session) {
this.props.onTextInputChange(session);
this.setState({selectedSessionName: session});
}

onChange(event) {
const newValue = event.target.value;
this.props.onTextInputChange(newValue);
this.setState({selectedSessionName: newValue});
}

Expand Down

0 comments on commit d8697a6

Please sign in to comment.