diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a6276eb..10d39ba9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,11 +3,12 @@ stages: - bundle variables: - VERSION: 0.0.6 + VERSION: 0.0.7 build-go: image: golang:1.16.2 stage: build + only: master script: - go build -o goscrobble cmd/go-scrobble/*.go artifacts: @@ -21,6 +22,7 @@ build-go: build-react: image: node:15.12.0 stage: build + only: master script: - cd web - npm install @@ -33,6 +35,7 @@ build-react: bundle: image: bash:latest stage: bundle + only: master variables: GIT_STRATEGY: none before_script: diff --git a/docs/changelog.md b/docs/changelog.md index 19a35080..d92978d8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,8 @@ +# 0.0.7 +- Switch redux -> Context +- Remove excess packages + + # 0.0.6 - Fix hitting dashboard when logged out - Clean up app.js diff --git a/internal/goscrobble/user.go b/internal/goscrobble/user.go index 2b3fff66..c1626325 100644 --- a/internal/goscrobble/user.go +++ b/internal/goscrobble/user.go @@ -61,10 +61,8 @@ func createUser(req *RegisterRequest, ip net.IP) error { // Check username is valid if !isUsernameValid(req.Username) { - log.Println("user is invalid") return errors.New("Username contains invalid characters") } - log.Println("user is valid") // If set an email.. validate it! if req.Email != "" { diff --git a/web/package-lock.json b/web/package-lock.json index a86fda08..de4226a5 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -19,21 +19,13 @@ "react": "^17.0.2", "react-bootstrap": "^1.5.2", "react-cookie": "^4.0.3", - "react-data-grid": "*", "react-dom": "^17.0.2", "react-redux": "^7.2.3", "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", "react-spinners": "^0.10.6", - "react-table": "^7.6.3", - "react-toast": "^1.0.1", - "react-toast-notifications": "^2.4.3", "react-toastify": "^7.0.3", - "reactstrap": "^8.9.0", - "redux": "^4.0.5", - "redux-persist": "^6.0.0", - "redux-thunk": "^2.3.0", - "web-vitals": "^1.1.1" + "reactstrap": "^8.9.0" }, "devDependencies": { "redux-devtools-extension": "^2.13.9", @@ -16328,18 +16320,6 @@ "react": ">= 16.3.0" } }, - "node_modules/react-data-grid": { - "version": "7.0.0-canary.38", - "resolved": "https://registry.npmjs.org/react-data-grid/-/react-data-grid-7.0.0-canary.38.tgz", - "integrity": "sha512-JjMyChuh9KxOtYmpxrOuPBI6EYIbNLn/+pjwoQYeD7d5vkWMURWWhyLX1NJkT5bt5LF2qxOSQiFf3G6YndxlAg==", - "dependencies": { - "clsx": "^1.1.1" - }, - "peerDependencies": { - "react": "^16.14 || ^17.0", - "react-dom": "^16.14 || ^17.0" - } - }, "node_modules/react-dev-utils": { "version": "11.0.4", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-11.0.4.tgz", @@ -16733,39 +16713,6 @@ "react-dom": "^16.0.0 || ^17.0.0" } }, - "node_modules/react-table": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/react-table/-/react-table-7.6.3.tgz", - "integrity": "sha512-hfPF13zDLxPMpLKzIKCE8RZud9T/XrRTsaCIf8zXpWZIZ2juCl7qrGpo3AQw9eAetXV5DP7s2GDm+hht7qq5Dw==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/tannerlinsley" - }, - "peerDependencies": { - "react": "^16.8.3 || ^17.0.0-0" - } - }, - "node_modules/react-toast": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/react-toast/-/react-toast-1.0.1.tgz", - "integrity": "sha512-xqkO5ZJiJDOLxycZts7xi729blKw4frhg2I4bcIjT7mVlshxu0AsaHlKAdPhVeACAnn8nnamxg6zoYoC9BEjjg==", - "peerDependencies": { - "react": ">=16" - } - }, - "node_modules/react-toast-notifications": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/react-toast-notifications/-/react-toast-notifications-2.4.3.tgz", - "integrity": "sha512-Ya/i2dCjN95Ytb/pwbAVmDMSKQwGeeGOhUThtjFQx2XAFKE+fQnodLlIylhgZfsInxdUXPFGFnzTdGS8JafuLA==", - "dependencies": { - "@emotion/core": "^10.0.14", - "react-transition-group": "^4.4.1" - }, - "peerDependencies": { - "react": "^16.8.0 || ^17.0.0", - "react-dom": "^16.8.0 || ^17.0.0" - } - }, "node_modules/react-toastify": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-7.0.3.tgz", @@ -17011,14 +16958,6 @@ "redux": "^3.1.0 || ^4.0.0" } }, - "node_modules/redux-persist": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz", - "integrity": "sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==", - "peerDependencies": { - "redux": ">4.0.0" - } - }, "node_modules/redux-thunk": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz", @@ -20691,11 +20630,6 @@ "minimalistic-assert": "^1.0.0" } }, - "node_modules/web-vitals": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-1.1.1.tgz", - "integrity": "sha512-jYOaqu01Ny1NvMwJ3dBJDUOJ2PGWknZWH4AUnvFOscvbdHMERIKT2TlgiAey5rVyfOePG7so2JcXXZdSnBvioQ==" - }, "node_modules/webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", @@ -35007,14 +34941,6 @@ "universal-cookie": "^4.0.0" } }, - "react-data-grid": { - "version": "7.0.0-canary.38", - "resolved": "https://registry.npmjs.org/react-data-grid/-/react-data-grid-7.0.0-canary.38.tgz", - "integrity": "sha512-JjMyChuh9KxOtYmpxrOuPBI6EYIbNLn/+pjwoQYeD7d5vkWMURWWhyLX1NJkT5bt5LF2qxOSQiFf3G6YndxlAg==", - "requires": { - "clsx": "^1.1.1" - } - }, "react-dev-utils": { "version": "11.0.4", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-11.0.4.tgz", @@ -35331,27 +35257,6 @@ "@emotion/core": "^10.0.35" } }, - "react-table": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/react-table/-/react-table-7.6.3.tgz", - "integrity": "sha512-hfPF13zDLxPMpLKzIKCE8RZud9T/XrRTsaCIf8zXpWZIZ2juCl7qrGpo3AQw9eAetXV5DP7s2GDm+hht7qq5Dw==", - "requires": {} - }, - "react-toast": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/react-toast/-/react-toast-1.0.1.tgz", - "integrity": "sha512-xqkO5ZJiJDOLxycZts7xi729blKw4frhg2I4bcIjT7mVlshxu0AsaHlKAdPhVeACAnn8nnamxg6zoYoC9BEjjg==", - "requires": {} - }, - "react-toast-notifications": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/react-toast-notifications/-/react-toast-notifications-2.4.3.tgz", - "integrity": "sha512-Ya/i2dCjN95Ytb/pwbAVmDMSKQwGeeGOhUThtjFQx2XAFKE+fQnodLlIylhgZfsInxdUXPFGFnzTdGS8JafuLA==", - "requires": { - "@emotion/core": "^10.0.14", - "react-transition-group": "^4.4.1" - } - }, "react-toastify": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-7.0.3.tgz", @@ -35543,12 +35448,6 @@ "dev": true, "requires": {} }, - "redux-persist": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz", - "integrity": "sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==", - "requires": {} - }, "redux-thunk": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz", @@ -38488,11 +38387,6 @@ "minimalistic-assert": "^1.0.0" } }, - "web-vitals": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-1.1.1.tgz", - "integrity": "sha512-jYOaqu01Ny1NvMwJ3dBJDUOJ2PGWknZWH4AUnvFOscvbdHMERIKT2TlgiAey5rVyfOePG7so2JcXXZdSnBvioQ==" - }, "webidl-conversions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-6.1.0.tgz", diff --git a/web/package.json b/web/package.json index 745e2036..44605bb0 100644 --- a/web/package.json +++ b/web/package.json @@ -14,21 +14,13 @@ "react": "^17.0.2", "react-bootstrap": "^1.5.2", "react-cookie": "^4.0.3", - "react-data-grid": "*", "react-dom": "^17.0.2", "react-redux": "^7.2.3", "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", "react-spinners": "^0.10.6", - "react-table": "^7.6.3", - "react-toast": "^1.0.1", - "react-toast-notifications": "^2.4.3", "react-toastify": "^7.0.3", - "reactstrap": "^8.9.0", - "redux": "^4.0.5", - "redux-persist": "^6.0.0", - "redux-thunk": "^2.3.0", - "web-vitals": "^1.1.1" + "reactstrap": "^8.9.0" }, "scripts": { "start": "react-scripts start", diff --git a/web/src/Actions/api.js b/web/src/Actions/api.js deleted file mode 100644 index 57e591d2..00000000 --- a/web/src/Actions/api.js +++ /dev/null @@ -1,18 +0,0 @@ -import ApiService from "../Services/api.service"; - -export const getStats = () => { - return ApiService.getStats().then( - (data) => { - return data.data; - } - ); -}; - -export const getRecentScrobbles = (id) => { - return ApiService.getRecentScrobbles(id).then( - (data) => { - return data.data; - } - ); -}; - diff --git a/web/src/Actions/auth.js b/web/src/Actions/auth.js deleted file mode 100644 index 8f37d2f4..00000000 --- a/web/src/Actions/auth.js +++ /dev/null @@ -1,105 +0,0 @@ -import { - REGISTER_SUCCESS, - REGISTER_FAIL, - LOGIN_SUCCESS, - LOGIN_FAIL, - LOGOUT, -} from "./types"; - - import { toast } from 'react-toastify'; - import jwt from 'jwt-decode' - import AuthService from "../Services/auth.service"; - import eventBus from "./eventBus"; - - export const register = (username, email, password) => (dispatch) => { - return AuthService.register(username, email, password).then( - (data) => { - if (data.message) { - toast.success('Successfully registered. Please sign in'); - dispatch({ - type: REGISTER_SUCCESS, - }); - - return Promise.resolve(); - } - - toast.error(data.error ? data.error: 'An Unknown Error has occurred') - dispatch({ - type: REGISTER_FAIL, - }); - - return Promise.reject(); - }, - (error) => { - const message = - (error.response && - error.response.data && - error.response.data.message) || - error.message || - error.toString(); - - toast.error(message); - - dispatch({ - type: REGISTER_FAIL, - }); - - return Promise.reject(); - } - ); - }; - - export const login = (username, password) => (dispatch) => { - return AuthService.login(username, password).then( - (data) => { - if (data.token) { - toast.success('Login Success'); - let user = jwt(data.token) - - dispatch({ - type: LOGIN_SUCCESS, - payload: { jwt: data.token, sub: user.sub, exp: user.exp }, - }); - return Promise.resolve(); - } - - toast.error(data.error ? data.error: 'An Unknown Error has occurred') - dispatch({ - type: LOGIN_FAIL, - }); - return Promise.reject(); - }, - (error) => { - const message = - (error.response && - error.response.data && - error.response.data.error) || - error.message || - error.toString(); - - toast.error('Error: ' + message) - dispatch({ - type: LOGIN_FAIL, - }); - - return Promise.reject(); - } - ); - }; - - export const logout = (dispatch) => { - // Clear local data - AuthService.logout() - - // window.location.pathname("/") - window.location.reload() - - // TODO; Clear Redux - ENABLE THIS WHEN I FIGURE OUT HOW 2 DISPATCH - // dispatch({ - // type: LOGOUT, - // payload: {}, - // }); - - // // Issue to all listeners to reload - eventBus.dispatch(LOGOUT); - }; diff --git a/web/src/Actions/eventBus.js b/web/src/Actions/eventBus.js deleted file mode 100644 index 17bfcd26..00000000 --- a/web/src/Actions/eventBus.js +++ /dev/null @@ -1,13 +0,0 @@ -const eventBus = { - on(event, callback) { - document.addEventListener(event, (e) => callback(e.detail)); - }, - dispatch(event, data) { - document.dispatchEvent(new CustomEvent(event, { detail: data })); - }, - remove(event, callback) { - document.removeEventListener(event, callback); - }, -}; - -export default eventBus \ No newline at end of file diff --git a/web/src/Actions/types.js b/web/src/Actions/types.js deleted file mode 100644 index 98fda989..00000000 --- a/web/src/Actions/types.js +++ /dev/null @@ -1,5 +0,0 @@ -export const REGISTER_SUCCESS = "REGISTER_SUCCESS"; -export const REGISTER_FAIL = "REGISTER_FAIL"; -export const LOGIN_SUCCESS = "LOGIN_SUCCESS"; -export const LOGIN_FAIL = "LOGIN_FAIL"; -export const LOGOUT = "LOGOUT"; diff --git a/web/src/Api/index.js b/web/src/Api/index.js new file mode 100644 index 00000000..ba263584 --- /dev/null +++ b/web/src/Api/index.js @@ -0,0 +1,74 @@ +import axios from 'axios'; +import jwt from 'jwt-decode' +import { toast } from 'react-toastify'; + +function getHeaders() { + // Todo: move this to use Context values instead. + const user = JSON.parse(localStorage.getItem('user')); + + if (user && user.jwt) { + return { Authorization: 'Bearer ' + user.jwt }; + } else { + return {}; + } +} + +export const PostLogin = (formValues) => { + // const { setLoading, setUser } = useContext(AuthContext); + // setLoading(true) + return axios.post(process.env.REACT_APP_API_URL + "login", formValues) + .then((response) => { + if (response.data.token) { + let expandedUser = jwt(response.data.token) + let user = { + jwt: response.data.token, + uuid: expandedUser.sub, + exp: expandedUser.exp, + username: expandedUser.username, + } + + toast.success('Successfully logged in.'); + return user; + } else { + toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred'); + return null + } + }) + .catch(() => { + return Promise.resolve(); + }); +}; + +export const PostRegister = (formValues) => { + return axios.post(process.env.REACT_APP_API_URL + "register", formValues) + .then((response) => { + if (response.data.message) { + toast.success(response.data.message); + + return Promise.resolve(); + } else { + toast.error(response.data.error ? response.data.error: 'An Unknown Error has occurred'); + + return Promise.reject(); + } + }) + .catch(() => { + return Promise.resolve(); + }); +}; + +export const getStats = () => { + return axios.get(process.env.REACT_APP_API_URL + "stats").then( + (data) => { + data.isLoading = false; + return data.data; + } + ); +}; + +export const getRecentScrobbles = (id) => { + return axios.get(process.env.REACT_APP_API_URL + "user/" + id + "/scrobbles", { headers: getHeaders() }) + .then((data) => { + return data.data; + }); +}; diff --git a/web/src/App.js b/web/src/App.js index 02c1c903..7c440fec 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -3,47 +3,36 @@ import Home from './Pages/Home'; import About from './Pages/About'; import Dashboard from './Pages/Dashboard'; -import Admin from './Pages/Admin'; import Profile from './Pages/Profile'; import Login from './Pages/Login'; import Settings from './Pages/Settings'; import Register from './Pages/Register'; import Navigation from './Components/Navigation'; -// import { logout } from './Actions/auth'; import { Route, Switch, withRouter } from 'react-router-dom'; -import { Component } from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; -class App extends Component { - constructor(props) { - super(props); - this.state = { - true: true, - }; - } +const App = () => { + let boolTrue = true - render() { return (
{element.time} | {element.track} | @@ -37,7 +28,6 @@ class ScrobbleTable extends React.Component {