Merge pull request #65 from gempir/404
correctly display when we don't find any logs fixes #35
This commit is contained in:
commit
61c612428d
7 changed files with 33 additions and 35 deletions
File diff suppressed because one or more lines are too long
|
@ -6,7 +6,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v2"
|
"github.com/gempir/go-twitch-irc/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RandomQuoteJSON response when request a random message
|
// 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) {
|
func (s *Server) writeAvailableLogs(w http.ResponseWriter, r *http.Request, q url.Values) {
|
||||||
logs, err := s.fileLogger.GetAvailableLogsForUser(q.Get("channelid"), q.Get("userid"))
|
logs, err := s.fileLogger.GetAvailableLogsForUser(q.Get("channelid"), q.Get("userid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
http.Error(w, "failed to get available logs: "+err.Error(), http.StatusNotFound)
|
||||||
http.Error(w, "failed to get available logs: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ export default function (channel, username, year, month) {
|
||||||
} else {
|
} else {
|
||||||
var error = new Error(response.statusText)
|
var error = new Error(response.statusText)
|
||||||
error.response = response
|
error.response = response
|
||||||
throw error
|
dispatch(setLoading(false));
|
||||||
|
reject(error);
|
||||||
}
|
}
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default function (channel, username, year, month) {
|
||||||
|
|
||||||
if (Object.keys(logs).length === 0) {
|
if (Object.keys(logs).length === 0) {
|
||||||
dispatch(setLoading(false));
|
dispatch(setLoading(false));
|
||||||
reject(new Error("no logs found"));
|
reject(new Error("not found"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,9 @@ export default function (channel, username, year, month) {
|
||||||
dispatch(setLoading(false));
|
dispatch(setLoading(false));
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
dispatch(setLoading(false));
|
||||||
|
reject(new Error("not found"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,18 @@ import LoadingSpinner from "./LoadingSpinner";
|
||||||
class Filter extends Component {
|
class Filter extends Component {
|
||||||
username;
|
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() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<form className="filter" autoComplete="off" onSubmit={this.onSubmit}>
|
<form className="filter" autoComplete="off" onSubmit={this.onSubmit}>
|
||||||
|
@ -19,7 +31,7 @@ class Filter extends Component {
|
||||||
onChange={this.onUsernameChange}
|
onChange={this.onUsernameChange}
|
||||||
value={this.props.username}
|
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>
|
</form>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +53,9 @@ class Filter extends Component {
|
||||||
params.set('username', this.props.username);
|
params.set('username', this.props.username);
|
||||||
window.location.search = params.toString();
|
window.location.search = params.toString();
|
||||||
|
|
||||||
this.props.dispatch(loadLogs());
|
this.props.dispatch(loadLogs()).catch(err => {
|
||||||
|
this.setState({buttonText: err.message});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@ import Filter from "./Filter";
|
||||||
import LogView from "./LogView";
|
import LogView from "./LogView";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import loadChannels from "../actions/loadChannels";
|
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 loadBttvEmotes from "../actions/loadBttvEmotes";
|
||||||
import Settings from "./Settings";
|
import Settings from "./Settings";
|
||||||
|
|
||||||
|
@ -17,16 +14,9 @@ class LogSearch extends Component {
|
||||||
props.dispatch(loadBttvEmotes());
|
props.dispatch(loadBttvEmotes());
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
if (this.props.channel && this.props.username) {
|
|
||||||
this.props.dispatch(loadLogs());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="log-search">
|
<div className="log-search">
|
||||||
<ToastContainer />
|
|
||||||
<Settings/>
|
<Settings/>
|
||||||
<Filter
|
<Filter
|
||||||
channels={this.props.channels}
|
channels={this.props.channels}
|
||||||
|
|
|
@ -155,7 +155,7 @@ class LogView extends Component {
|
||||||
this.setState({ loading: true });
|
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 => {
|
this.props.dispatch(loadLog(null, null, this.props.log.year, this.props.log.month)).then(() => this.setState({ loading: false })).catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
this.setState({ loading: false, buttonText: "not found" });
|
this.setState({ loading: false, buttonText: err.message });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue