Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redux aa1 to improve basics aa3 #87

Merged
merged 43 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
27705e4
Upgrade to redux
schettn Jul 2, 2020
bd269f8
Enhance Redux
schettn Jul 2, 2020
1c6a968
Improve user fetching
schettn Jul 2, 2020
6b0ca3f
Upgrade registration component with redux
schettn Jul 2, 2020
6455e6c
Login after regisration
schettn Jul 2, 2020
4548fd0
Update package.json
pinterid Jul 2, 2020
cf9f25d
Add profile picture modal
pinterid Jul 2, 2020
63d488c
Update modal export/imports
pinterid Jul 2, 2020
3fdfaeb
Add settings page
pinterid Jul 2, 2020
1c7d15b
Implement settings page
pinterid Jul 2, 2020
11ce7b8
Update navbar settings
pinterid Jul 2, 2020
8b65ce7
Update settings action
pinterid Jul 2, 2020
42f6728
Improve settings page accesability
schettn Jul 2, 2020
4d9268d
Improve user menu
schettn Jul 2, 2020
0332ee5
Remove legacy code
schettn Jul 2, 2020
04a17b3
Merge branch 'improve-settings-aa1' into add-redux-aa1
schettn Jul 2, 2020
3765de6
Improve Redux DevTools integration
schettn Jul 2, 2020
b316569
Fix syntax error of previous merge
schettn Jul 2, 2020
d29918f
Conditional Rendering of Talk Interaction Buttons
schettn Jul 2, 2020
d8bf12d
Remove init blank
pinterid Jul 2, 2020
46cfbd8
Add input value check
pinterid Jul 2, 2020
2f14735
Merge remote-tracking branch 'origin/improve-settings-aa2' into add-r…
schettn Jul 2, 2020
7b1c67a
Add Language chart
Aichnerc Jul 2, 2020
9442410
Improve projects
Aichnerc Jul 2, 2020
475eea3
Improve profile info
Aichnerc Jul 2, 2020
3fb02d6
Disable pinned
Aichnerc Jul 2, 2020
950f632
Merge branch 'improve-design-ba1' into add-redux-aa1
schettn Jul 2, 2020
808753e
Update autch actions
pinterid Jul 2, 2020
245eecf
Update login form errors
pinterid Jul 2, 2020
8348757
Merge branch 'add-notifications-aa1' into add-redux-aa1
schettn Jul 2, 2020
971d3ae
Add Default Project Avatar
schettn Jul 4, 2020
31ac934
Improve Default Major Language Name
schettn Jul 4, 2020
cc4b97b
Add Todo To LanguageChart Component
schettn Jul 4, 2020
f81b03d
Merge branch 'improve-design-ba2' into add-redux-aa1
schettn Jul 4, 2020
bc8c9f8
Update SignIn Error Message
schettn Jul 6, 2020
b8a022c
Add Redirect to Homepage in Settings page for unlogged users
schettn Jul 6, 2020
ac82913
Fix Codacy
pinterid Jul 6, 2020
1707c85
Fix Codacy
pinterid Jul 6, 2020
0506258
Fix Codacy
pinterid Jul 6, 2020
17db562
Move Changeable Content to User Section
schettn Jul 6, 2020
52b81f9
Add Optional Chaining to Login Result
schettn Jul 6, 2020
d80c715
Fix Redirect to Homepage in Settings Page
schettn Jul 6, 2020
72aeebe
Remove Workaround
schettn Jul 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
"mdbreact": "mdbreact-4.26.1.tgz",
"node-sass": "^4.12.0",
"obelisk.js": "^1.2.2",
"react-avatar-editor": "^11.0.9",
"react-chartjs-2": "^2.9.0",
"react-dropzone": "^11.0.1",
"react-redux": "^7.2.0",
"react-redux-loading-bar": "^4.6.0",
"react-router-dom": "^5.0.1",
"react-text-loop": "^2.3.0",
"react-typed": "^1.2.0",
"reactjs-oauth": "file:reactjs-oauth-0.1.0.tgz",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"serialize-error": "^7.0.1",
"snek-intel": "^0.1.1",
"tippy.js": "^6.2.3"
},
Expand Down
283 changes: 15 additions & 268 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
//#region > Imports
//> React
// Contains all the functionality necessary to define React components
import React from "react";
import React, { useEffect } from "react";
// DOM bindings for React Router
import { withRouter } from "react-router-dom";
//> Additional
// SHA Hashing algorithm
import sha256 from "js-sha256";
//> MDB
// "Material Design for Bootstrap" is a great UI design framework
import { MDBProgress } from "mdbreact";
//> Redux
import { useDispatch } from "react-redux";

//> Components
/**
Expand All @@ -21,287 +17,38 @@ import { Footer, Navbar } from "./components/molecules";
import { ScrollToTop } from "./components/atoms";
//> Routes
import Routes from "./Routes";
//> Core
import { ferryIntel } from "./actions";
//> Actions
import {
login,
logout,
fetchGitLabServers,
appendSourceObjects,
getAllPageUrls,
getData,
saveSettings,
register,
readCache,
updateCache,
writeCache,
getAllTalks,
getTalk,
uploadTalk,
deleteTalk,
} from "./actions/intel";
import { loginAction } from "./store/actions/authActions";
//#endregion

//#region > Components
/**
* @class Root component which loads all other components
*/
class App extends React.Component {
state = {
loggedUser: undefined,
fetchedUser: undefined,
loading: true,
caching: false,
};
function App() {
const dispatch = useDispatch();

globalFunctions = {
//> Authentication
login: async (username, password) =>
this.handleLoginSession({ username, password: sha256(password) }),
logout: async () => this.handleLogout(),
//> General
fetchGitLabServers: async () => ferryIntel(fetchGitLabServers()),
appendSourceObjects: async (sourceList) =>
ferryIntel(appendSourceObjects(sourceList)),
users: async () => ferryIntel(getAllPageUrls()),
saveSettings: async (nextSettings) => this.handleSaveSettings(nextSettings),
//> User
updateCache: async (fetchedUser) => this.handleCacheRenewal(fetchedUser),
writeCache: async (platformData) => ferryIntel(writeCache(platformData)),
registerUser: async (registrationData) =>
this.handleRegistration(registrationData),
fetchCacheData: async (username) => this.handleProfileFetching(username),
//> Talk
deleteTalk: async (talk) => this.handleTalkDeletion(talk),
uploadTalk: async (file, talkInfo) => this.handleTalkUpload(file, talkInfo),
getTalk: (uid, username) => ferryIntel(getTalk(uid, username)),
//> State checking
refetchRequired: (username) => this.refetchRequired(username),
usernameMatchesFetchedUsername: (username) =>
this.usernameMatchesFetchedUsername(username),
};
useEffect(() => {
dispatch(loginAction());
}, []);

componentDidMount = () => {
// Start a session as anonymous user
this.handleLoginSession();
};

/**
* Handle login session.
*
* @param user A user to login with
* @description Handles states for login
*/
handleLoginSession = async (user) => {
return ferryIntel(login(user)).then((loggedUser) => {
if (loggedUser) {
this.setState({
loggedUser,
loading: false,
});
} else {
if (this.state.loggedUser !== null) {
this.setState({
loggedUser: null,
loading: false,
});
}
}
});
};

/**
* Handle logout.
*
* @description Handles states for logout
*/
handleLogout = () => {
this.setState(
{
loggedUser: undefined,
fetchedUser: undefined,
loading: false,
caching: false,
},
() => ferryIntel(logout()).then(() => this.handleLoginSession())
);
};

/**
* Handle registration
*
* @param registrationData Data to register a user
* @description Handles states for registration
*/
handleRegistration = (registrationData) => {
ferryIntel(register(registrationData)).then((res) => {
this.globalFunctions.login(res.username, res.password).then(() => {
this.globalFunctions.writeCache(registrationData.platform_data);
this.setState({ caching: true, loading: false });
});
});
};

/**
* Handle cache renewal.
*
* @param fetchedUser A fetched user object
* @description Handles states for cache renewal
*/
handleCacheRenewal = async (fetchedUser) => {
if (
!this.state.caching &&
this.state.loggedUser?.username === fetchedUser?.username
) {
// Renew cache
const fetchedUser = await ferryIntel(updateCache(fetchedUser));

this.setState({
fetchedUser,
caching: true,
});
}
};

/**
* Handle profile fetching.
*
* @param username A username to read the cache from
* @description Handles states for profile fetching
*/
handleProfileFetching = async (username) => {
const fetchedUser = await ferryIntel(readCache(username));
// Update visible data
this.setState({
fetchedUser: fetchedUser ? fetchedUser : false,
loading: false,
});
};

/**
* Handle talk upload.
*
* @param file A file to be uploaded
* @param talkInfo Additional information to add to the talk
* @description Handles states for talk uploading
*/
handleTalkUpload = async (file, talkInfo) => {
ferryIntel(uploadTalk(file, talkInfo), {
currentCache: this.state.fetchedUser.platformData,
}).then((platformData) => {
this.setState({
fetchedUser: {
...this.state.fetchedUser,
platformData,
},
});
});
};

/**
* Handle talk deletion.
*
* @param talk A talk that should be deleted
* @description Handles states for talk deleting
*/
handleTalkDeletion = async (talk) => {
ferryIntel(deleteTalk(talk), {
currentCache: this.state.fetchedUser.platformData,
}).then((platformData) => {
this.setState({
fetchedUser: {
...this.state.fetchedUser,
platformData,
},
});
});
};

/**
* Handle save settings.
*
* @param nextSettings A settings object that should be applied
* @description Handles states for saving settings
*/
handleSaveSettings = async (nextSettings) => {
ferryIntel(saveSettings(nextSettings), {
currentCache: this.state.fetchedUser.platformData,
}).then((platformData) => {
this.setState({
fetchedUser: {
...this.state.fetchedUser,
platformData,
},
});
});
};

//#region > Refetch Checking
/**
* Check for refetch for a specific username.
*
* @param {string} username The username associated with a profile page
* @returns {boolean} True if a refetch is required otherwise False
*/
refetchRequired = (username) => {
const loading = this.state.loading;
const fetchedUser = this.state.fetchedUser;

if (!loading) {
if (!fetchedUser && fetchedUser !== false) {
return true;
} else if (
fetchedUser &&
!this.usernameMatchesFetchedUsername(username)
) {
return true;
}
return false;
}
};

/**
* Check if the provided username matches with the current fetched user.
*
* @param {string} username The username associated with a profile page
* @returns {boolean} True if the usernames matches otherwise False
*/
usernameMatchesFetchedUsername = (username) => {
return username === this.state.fetchedUser?.username;
};
//#endregion

render() {
return (
return (
<>
<ScrollToTop>
<div className="flyout">
{!this.state.caching &&
this.state.fetchedUser &&
this.state.loggedUser?.username ===
this.state.fetchedUser.username && (
<MDBProgress material preloader className="caching-loader" />
)}
<Navbar
globalState={this.state}
globalFunctions={this.globalFunctions}
/>
<Navbar />
<main>
<Routes
globalState={this.state}
globalFunctions={this.globalFunctions}
/>
<Routes />
</main>
<Footer />
</div>
</ScrollToTop>
);
}
</>
);
}
//#endregion

//#region > Exports
//> Default Class
export default withRouter(App);
//#endregion

Expand Down
Loading