+
+
+
+
+
+ );
+ }
+
+ render() {
+ const { classes } = this.props;
+ return (
+
+
+
+
+
+ {
+ this.state.authority?
+ this.showAuthority():
+ this.state.wantsToLogin?
+ this.showLoginAuth():
+ this.showLanding()
+ }
+
+
+
+ © 2019 Hyperspace developers. All rights reserved.
+
+
+ GitHub | License | File an Issue
+
+
+
+ );
+ }
+}
+
+export default withStyles(styles)(WelcomePage);
\ No newline at end of file
diff --git a/src/pages/WelcomePage.styles.tsx b/src/pages/WelcomePage.styles.tsx
new file mode 100644
index 0000000..b6bff9b
--- /dev/null
+++ b/src/pages/WelcomePage.styles.tsx
@@ -0,0 +1,50 @@
+import { Theme, createStyles } from '@material-ui/core';
+
+export const styles = (theme: Theme) => createStyles({
+ root: {
+ width: '100%',
+ height: '100%',
+ backgroundPosition: 'center',
+ backgroundRepeat: 'no-repeat',
+ backgroundSize: 'cover',
+ top: 0,
+ left: 0,
+ position: "absolute",
+ [theme.breakpoints.up('sm')]: {
+ paddingTop: theme.spacing.unit * 4,
+ paddingLeft: '25%',
+ paddingRight: '25%',
+ },
+ [theme.breakpoints.up('lg')]: {
+ paddingTop: theme.spacing.unit * 12,
+ paddingLeft: '35%',
+ paddingRight: '35%',
+ }
+ },
+ paper: {
+ height: '100%',
+ [theme.breakpoints.up('sm')]: {
+ height: 'auto',
+ paddingLeft: theme.spacing.unit * 8,
+ paddingRight: theme.spacing.unit * 8,
+ paddingTop: theme.spacing.unit * 6,
+ },
+ paddingTop: theme.spacing.unit * 12,
+ paddingLeft: theme.spacing.unit * 4,
+ paddingRight: theme.spacing.unit * 4,
+ paddingBottom: theme.spacing.unit * 6,
+ textAlign: 'center'
+ },
+ flexGrow: {
+ flexGrow: 1
+ },
+ middlePadding: {
+ height: theme.spacing.unit * 6
+ },
+ logo: {
+ [theme.breakpoints.up('sm')]: {
+ height: 64,
+ width: "auto"
+ },
+ }
+});
\ No newline at end of file
diff --git a/src/types/Config.tsx b/src/types/Config.tsx
new file mode 100644
index 0000000..5b8b341
--- /dev/null
+++ b/src/types/Config.tsx
@@ -0,0 +1,15 @@
+export type Config = {
+ branding?: {
+ name?: string;
+ logo?: string;
+ background?: string;
+ };
+ federated?: string;
+ registration?: {
+ defaultInstance?: string;
+ };
+ admin?: {
+ name?: string;
+ account?: string;
+ };
+}
\ No newline at end of file
diff --git a/src/types/SessionData.tsx b/src/types/SessionData.tsx
new file mode 100644
index 0000000..d096664
--- /dev/null
+++ b/src/types/SessionData.tsx
@@ -0,0 +1,5 @@
+export type SaveClientSession = {
+ clientId: string;
+ clientSecret: string;
+ authUrl: string;
+}
\ No newline at end of file
diff --git a/src/utilities/accounts.tsx b/src/utilities/accounts.tsx
index 91aaa73..f51bfcc 100644
--- a/src/utilities/accounts.tsx
+++ b/src/utilities/accounts.tsx
@@ -1,9 +1,18 @@
import Mastodon from "megalodon";
+export function userLoggedIn(): boolean {
+ if (localStorage.getItem('baseurl') && localStorage.getItem('access_token')) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
export function refreshUserAccountData() {
- let client = new Mastodon(localStorage.getItem('access_token') as string, localStorage.getItem('baseurl') as string + "/api/v1/");
+ let client = new Mastodon(localStorage.getItem('access_token') as string, localStorage.getItem('baseurl') as string + "/api/v1");
client.get('/accounts/verify_credentials').then((resp: any) => {
- if (JSON.stringify(resp.data) !== localStorage.getItem('account'))
- localStorage.setItem('account', JSON.stringify(resp.data));
+ localStorage.setItem('account', JSON.stringify(resp.data));
+ }).catch((err: Error) => {
+ console.error(err.message);
});
}
\ No newline at end of file
diff --git a/src/utilities/login.tsx b/src/utilities/login.tsx
new file mode 100644
index 0000000..18346be
--- /dev/null
+++ b/src/utilities/login.tsx
@@ -0,0 +1,23 @@
+import Mastodon from 'megalodon';
+
+/**
+ * Creates the Hyperspace app with the appropriate Redirect URI
+ * @param scopes The scopes that the app needs
+ * @param baseurl The base URL of the instance
+ * @param redirect_uri The URL to redirect to when authorizing
+ */
+export function createHyperspaceApp(scopes: string, baseurl: string, redirect_uri: string) {
+ return Mastodon.createApp("Hyperspace", {
+ scopes: scopes,
+ redirect_uris: redirect_uri,
+ website: 'https://hyperspace.marquiskurt.net'
+ }).then(appData => {
+ return Mastodon.generateAuthUrl(appData.clientId, appData.clientSecret, {
+ redirect_uri: redirect_uri,
+ scope: scopes
+ }, baseurl).then(url => {
+ appData.url = url;
+ return appData;
+ })
+ })
+}
\ No newline at end of file