From 269d0b1953b72ce7bc115e21534736d7c1a22e79 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 13 Jan 2018 20:07:11 -0800 Subject: [PATCH] flesh out settings menu --- routes/_utils/mastodon/user.js | 2 +- .../_components/SettingsListItem.html | 31 ++++++++++++++-- routes/settings/instances/[instanceName].html | 37 +++++++++++++------ routes/settings/instances/add.html | 5 ++- routes/settings/instances/index.html | 5 ++- scss/themes/_base.scss | 1 + 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/routes/_utils/mastodon/user.js b/routes/_utils/mastodon/user.js index 3d528fc1..8818d682 100644 --- a/routes/_utils/mastodon/user.js +++ b/routes/_utils/mastodon/user.js @@ -1,6 +1,6 @@ import { get } from '../ajax' -export function getCurrentUser(instanceName, accessToken) { +export function getThisUserAccount(instanceName, accessToken) { let url = `https://${instanceName}/api/v1/accounts/verify_credentials` return get(url, { 'Authorization': `Bearer ${accessToken}` diff --git a/routes/settings/_components/SettingsListItem.html b/routes/settings/_components/SettingsListItem.html index f322fee0..596ffb8a 100644 --- a/routes/settings/_components/SettingsListItem.html +++ b/routes/settings/_components/SettingsListItem.html @@ -1,4 +1,15 @@ -
  • {{label}}
  • +
  • + + {{#if icon}} + + + + {{/if}} + + {{label}} + + +
  • \ No newline at end of file diff --git a/routes/settings/instances/[instanceName].html b/routes/settings/instances/[instanceName].html index d6f918b3..64379ae4 100644 --- a/routes/settings/instances/[instanceName].html +++ b/routes/settings/instances/[instanceName].html @@ -6,12 +6,12 @@

    {{params.instanceName}}

    - {{#if currentUser}} + {{#if instanceUserAccount}}

    Logged in as:

    - - @{{currentUser.acct}} - {{currentUser.display_name}} + + @{{instanceUserAccount.acct}} + {{instanceUserAccount.display_name}}

    Theme:

    @@ -26,7 +26,8 @@
    - @@ -75,7 +76,7 @@ import { store } from '../../_utils/store' import Layout from '../../_components/Layout.html' import SettingsLayout from '../_components/SettingsLayout.html' - import { getCurrentUser } from '../../_utils/mastodon/user' + import { getThisUserAccount } from '../../_utils/mastodon/user' import { themes } from '../../_static/themes' import { switchToTheme } from '../../_utils/themeEngine' @@ -89,17 +90,20 @@ themes: themes }), oncreate: async function () { - let currentInstanceData = this.store.get('currentInstanceData') - let currentUser = await getCurrentUser(currentInstanceData.name, currentInstanceData.access_token) + let instanceName = this.get('params').instanceName + let loggedInInstances = this.store.get('loggedInInstances') + let instanceThemes = this.store.get('instanceThemes') + let instanceData = loggedInInstances[instanceName] + let instanceUserAccount = await getThisUserAccount(instanceName, instanceData.access_token) this.set({ - currentUser: currentUser, - selectedTheme: this.store.get('currentTheme') + instanceUserAccount: instanceUserAccount, + selectedTheme: instanceThemes[instanceName] }) }, methods: { - onThemeChange () { + onThemeChange() { let newTheme = this.get('selectedTheme') - let instanceName = this.store.get('currentInstance') + let instanceName = this.get('params').instanceName let instanceThemes = this.store.get('instanceThemes') instanceThemes[instanceName] = newTheme this.store.set({instanceThemes: instanceThemes}) @@ -107,6 +111,15 @@ if (this.get('params').instanceName === this.store.get('currentInstance')) { switchToTheme(newTheme) } + }, + onSwitchToThisInstance() { + let instanceName = this.get('params').instanceName + let instanceThemes = this.store.get('instanceThemes') + this.store.set({ + currentInstance: instanceName + }) + this.store.save() + switchToTheme(instanceThemes[instanceName]) } } } diff --git a/routes/settings/instances/add.html b/routes/settings/instances/add.html index 92ca4fca..8f53cc19 100644 --- a/routes/settings/instances/add.html +++ b/routes/settings/instances/add.html @@ -105,6 +105,8 @@ // TODO: handle error let loggedInInstances = this.store.get('loggedInInstances') let loggedInInstancesInOrder = this.store.get('loggedInInstancesInOrder') + let instanceThemes = this.store.get('instanceThemes') + instanceThemes[currentRegisteredInstanceName] = 'default' loggedInInstances[currentRegisteredInstanceName] = instanceData if (!loggedInInstancesInOrder.includes(currentRegisteredInstanceName)) { loggedInInstancesInOrder.push(currentRegisteredInstanceName) @@ -115,7 +117,8 @@ currentRegisteredInstance: null, loggedInInstances: loggedInInstances, currentInstance: currentRegisteredInstanceName, - loggedInInstancesInOrder: loggedInInstancesInOrder + loggedInInstancesInOrder: loggedInInstancesInOrder, + instanceThemes: instanceThemes }) this.store.save() goto('/') diff --git a/routes/settings/instances/index.html b/routes/settings/instances/index.html index 9168a56f..ad0add1a 100644 --- a/routes/settings/instances/index.html +++ b/routes/settings/instances/index.html @@ -10,7 +10,10 @@

    Instances you've connected to:

    {{#each $loggedInInstancesAsList as instance}} - + {{/each}}

    Add another instance

    diff --git a/scss/themes/_base.scss b/scss/themes/_base.scss index 4eca521a..1b2035dd 100644 --- a/scss/themes/_base.scss +++ b/scss/themes/_base.scss @@ -17,6 +17,7 @@ --body-bg: $body-bg-color; --body-text-color: $main-text-color; --main-border: $border-color; + --svg-fill: $main-theme-color; --form-bg: darken($main-bg-color, 3%); --form-border: darken($border-color, 10%);