Merge pull request #65 from gempir/404

correctly display when we don't find any logs fixes #35
This commit is contained in:
Daniel Pasch 2020-10-01 02:02:30 +02:00 committed by GitHub
commit 61c612428d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 35 deletions

File diff suppressed because one or more lines are too long

View file

@ -6,7 +6,6 @@ import (
"net/url"
"github.com/gempir/go-twitch-irc/v2"
log "github.com/sirupsen/logrus"
)
// RandomQuoteJSON response when request a random message
@ -71,8 +70,7 @@ func (s *Server) getRandomQuote(request logRequest) (*chatLog, error) {
func (s *Server) writeAvailableLogs(w http.ResponseWriter, r *http.Request, q url.Values) {
logs, err := s.fileLogger.GetAvailableLogsForUser(q.Get("channelid"), q.Get("userid"))
if err != nil {
log.Error(err)
http.Error(w, "failed to get available logs: "+err.Error(), http.StatusInternalServerError)
http.Error(w, "failed to get available logs: "+err.Error(), http.StatusNotFound)
return
}

View file

@ -28,7 +28,8 @@ export default function (channel, username, year, month) {
} else {
var error = new Error(response.statusText)
error.response = response
throw error
dispatch(setLoading(false));
reject(error);
}
}).then((response) => {
return response.json()

View file

@ -28,7 +28,7 @@ export default function (channel, username, year, month) {
if (Object.keys(logs).length === 0) {
dispatch(setLoading(false));
reject(new Error("no logs found"));
reject(new Error("not found"));
return;
}
@ -60,6 +60,9 @@ export default function (channel, username, year, month) {
dispatch(setLoading(false));
reject(error);
});
}).catch((error) => {
dispatch(setLoading(false));
reject(new Error("not found"));
});
});
};

View file

@ -8,6 +8,18 @@ import LoadingSpinner from "./LoadingSpinner";
class Filter extends Component {
username;
state = {
buttonText: "Show logs"
}
componentDidMount() {
if (this.props.channel && this.props.username) {
this.props.dispatch(loadLogs()).catch(err => {
this.setState({buttonText: err.message});
});
}
}
render() {
return (
<form className="filter" autoComplete="off" onSubmit={this.onSubmit}>
@ -19,7 +31,7 @@ class Filter extends Component {
onChange={this.onUsernameChange}
value={this.props.username}
/>
<button type="submit" className="show-logs">{this.props.loading ? <LoadingSpinner /> : <>Show logs</>}</button>
<button type="submit" className="show-logs">{this.props.loading ? <LoadingSpinner /> : <>{this.state.buttonText}</>}</button>
</form>
)
}
@ -41,7 +53,9 @@ class Filter extends Component {
params.set('username', this.props.username);
window.location.search = params.toString();
this.props.dispatch(loadLogs());
this.props.dispatch(loadLogs()).catch(err => {
this.setState({buttonText: err.message});
});
}
}

View file

@ -3,9 +3,6 @@ import Filter from "./Filter";
import LogView from "./LogView";
import { connect } from "react-redux";
import loadChannels from "../actions/loadChannels";
import loadLogs from "../actions/loadLogs";
import { ToastContainer } from "react-toastify";
import 'react-toastify/dist/ReactToastify.min.css';
import loadBttvEmotes from "../actions/loadBttvEmotes";
import Settings from "./Settings";
@ -17,16 +14,9 @@ class LogSearch extends Component {
props.dispatch(loadBttvEmotes());
}
componentDidMount() {
if (this.props.channel && this.props.username) {
this.props.dispatch(loadLogs());
}
}
render() {
return (
<div className="log-search">
<ToastContainer />
<Settings/>
<Filter
channels={this.props.channels}

View file

@ -155,7 +155,7 @@ class LogView extends Component {
this.setState({ loading: true });
this.props.dispatch(loadLog(null, null, this.props.log.year, this.props.log.month)).then(() => this.setState({ loading: false })).catch(err => {
console.error(err);
this.setState({ loading: false, buttonText: "not found" });
this.setState({ loading: false, buttonText: err.message });
});
}