2018-01-13 20:12:17 +00:00
|
|
|
<:Head>
|
|
|
|
<title>{{params.instanceName}}</title>
|
|
|
|
</:Head>
|
|
|
|
|
|
|
|
<Layout page='settings'>
|
|
|
|
<SettingsLayout page='settings/instances/{{params.instanceName}}' label="{{params.instanceName}}">
|
2018-01-20 23:37:40 +00:00
|
|
|
<h1 class="instance-name-h1">{{params.instanceName}}</h1>
|
2018-01-13 22:19:51 +00:00
|
|
|
|
2018-01-22 01:18:56 +00:00
|
|
|
{{#if verifyCredentials}}
|
2018-01-14 02:59:49 +00:00
|
|
|
<h2>Logged in as:</h2>
|
2018-01-14 19:34:53 +00:00
|
|
|
<div class="acct-current-user">
|
2018-01-22 01:18:56 +00:00
|
|
|
<img alt="Profile picture for {{'@' + verifyCredentials.acct}}"
|
|
|
|
class="acct-avatar" src="{{verifyCredentials.avatar}}" />
|
2018-01-14 19:34:53 +00:00
|
|
|
<a class="acct-handle" rel="noopener" target="_blank"
|
2018-01-22 01:18:56 +00:00
|
|
|
href="{{verifyCredentials.url}}">{{'@' + verifyCredentials.acct}}</a>
|
|
|
|
<span class="acct-display-name">{{verifyCredentials.display_name}}</span>
|
2018-01-14 02:59:49 +00:00
|
|
|
</div>
|
|
|
|
<h2>Theme:</h2>
|
2018-01-19 07:37:43 +00:00
|
|
|
<form class="theme-chooser" aria-label="Choose a theme">
|
2018-01-14 02:59:49 +00:00
|
|
|
{{#each themes as theme}}
|
|
|
|
<div class="theme-group">
|
|
|
|
<input type="radio" id="choice-theme-{{theme.name}}"
|
|
|
|
value="{{theme.name}}" checked="$currentTheme === theme.name"
|
|
|
|
bind:group="selectedTheme" on:change="onThemeChange()">
|
|
|
|
<label for="choice-theme-{{theme.name}}">{{theme.label}}</label>
|
|
|
|
</div>
|
|
|
|
{{/each}}
|
|
|
|
</form>
|
|
|
|
|
2018-01-19 07:37:43 +00:00
|
|
|
<form class="instance-actions" aria-label="Switch to or log out of this instance">
|
2018-01-22 02:48:21 +00:00
|
|
|
{{#if $loggedInInstancesInOrder.length > 1 && $currentInstance !== params.instanceName}}
|
|
|
|
<button class="primary"
|
2018-01-22 02:36:40 +00:00
|
|
|
on:click="onSwitchToThisInstance(event)">
|
2018-01-22 02:48:21 +00:00
|
|
|
Switch to this instance
|
2018-01-14 20:00:22 +00:00
|
|
|
</button>
|
|
|
|
{{/if}}
|
2018-01-22 02:36:40 +00:00
|
|
|
<button on:click="onLogOut(event)">Log out</button>
|
2018-01-14 02:59:49 +00:00
|
|
|
</form>
|
2018-01-13 22:19:51 +00:00
|
|
|
{{/if}}
|
2018-01-13 20:12:17 +00:00
|
|
|
</SettingsLayout>
|
|
|
|
</Layout>
|
2018-01-13 22:19:51 +00:00
|
|
|
<style>
|
2018-01-14 19:34:53 +00:00
|
|
|
.acct-current-user {
|
2018-01-14 20:00:22 +00:00
|
|
|
background: var(--form-bg);
|
|
|
|
border: 1px solid var(--main-border);
|
|
|
|
border-radius: 4px;
|
2018-01-13 22:19:51 +00:00
|
|
|
padding: 20px;
|
2018-01-14 19:34:53 +00:00
|
|
|
display: grid;
|
2018-01-13 22:19:51 +00:00
|
|
|
align-items: center;
|
|
|
|
font-size: 1.3em;
|
2018-01-14 19:34:53 +00:00
|
|
|
grid-template-areas:
|
|
|
|
"avatar handle"
|
|
|
|
"avatar display-name";
|
|
|
|
grid-gap: 20px;
|
2018-01-13 22:19:51 +00:00
|
|
|
}
|
2018-01-14 19:34:53 +00:00
|
|
|
.acct-avatar {
|
2018-01-13 22:19:51 +00:00
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
border-radius: 4px;
|
2018-01-14 19:34:53 +00:00
|
|
|
grid-area: avatar;
|
2018-01-13 22:19:51 +00:00
|
|
|
}
|
2018-01-14 19:34:53 +00:00
|
|
|
.acct-handle {
|
|
|
|
grid-area: handle;
|
2018-01-13 22:19:51 +00:00
|
|
|
}
|
|
|
|
.theme-chooser {
|
2018-01-14 20:00:22 +00:00
|
|
|
background: var(--form-bg);
|
|
|
|
border: 1px solid var(--main-border);
|
|
|
|
border-radius: 4px;
|
2018-01-13 22:19:51 +00:00
|
|
|
display: block;
|
|
|
|
padding: 20px;
|
|
|
|
line-height: 2em;
|
|
|
|
}
|
|
|
|
.theme-group {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
.theme-chooser label {
|
|
|
|
margin: 2px 10px 0;
|
|
|
|
}
|
2018-01-14 02:59:49 +00:00
|
|
|
.instance-actions {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: right;
|
2018-01-14 20:00:22 +00:00
|
|
|
margin: 20px 0;
|
2018-01-14 02:59:49 +00:00
|
|
|
}
|
|
|
|
.instance-actions button {
|
2018-01-14 19:22:57 +00:00
|
|
|
margin: 0 5px;
|
2018-01-14 02:59:49 +00:00
|
|
|
flex-basis: 100%;
|
|
|
|
}
|
2018-01-20 23:37:40 +00:00
|
|
|
.instance-name-h1 {
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
2018-01-13 22:19:51 +00:00
|
|
|
</style>
|
2018-01-13 20:12:17 +00:00
|
|
|
<script>
|
|
|
|
import { store } from '../../_utils/store'
|
|
|
|
import Layout from '../../_components/Layout.html'
|
|
|
|
import SettingsLayout from '../_components/SettingsLayout.html'
|
2018-01-22 01:18:56 +00:00
|
|
|
import { getVerifyCredentials } from '../../_utils/mastodon/user'
|
|
|
|
import { database } from '../../_utils/database/database'
|
2018-01-14 01:41:15 +00:00
|
|
|
import { themes } from '../../_static/themes'
|
2018-01-14 02:59:49 +00:00
|
|
|
import { switchToTheme } from '../../_utils/themeEngine'
|
2018-01-14 20:00:22 +00:00
|
|
|
import { goto } from 'sapper/runtime.js'
|
2018-01-15 07:36:44 +00:00
|
|
|
import { toast } from '../../_utils/toast'
|
2018-01-13 20:12:17 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Layout,
|
|
|
|
SettingsLayout
|
|
|
|
},
|
2018-01-13 22:19:51 +00:00
|
|
|
store: () => store,
|
2018-01-14 01:41:15 +00:00
|
|
|
data: () => ({
|
|
|
|
themes: themes
|
|
|
|
}),
|
2018-01-13 22:19:51 +00:00
|
|
|
oncreate: async function () {
|
2018-01-14 04:07:11 +00:00
|
|
|
let instanceName = this.get('params').instanceName
|
|
|
|
let loggedInInstances = this.store.get('loggedInInstances')
|
|
|
|
let instanceThemes = this.store.get('instanceThemes')
|
|
|
|
let instanceData = loggedInInstances[instanceName]
|
2018-01-22 01:18:56 +00:00
|
|
|
let verifyCredentials = await database.getInstanceVerifyCredentials(instanceName)
|
2018-01-23 06:00:17 +00:00
|
|
|
if (verifyCredentials) { // update in background
|
2018-01-22 01:18:56 +00:00
|
|
|
getVerifyCredentials(instanceName, instanceData.access_token).then(verifyCredentials => {
|
|
|
|
database.setInstanceVerifyCredentials(instanceName, verifyCredentials)
|
|
|
|
})
|
2018-01-23 06:00:17 +00:00
|
|
|
} else { // go to network
|
2018-01-22 01:18:56 +00:00
|
|
|
verifyCredentials = await getVerifyCredentials(instanceName, instanceData.access_token)
|
|
|
|
database.setInstanceVerifyCredentials(instanceName, verifyCredentials)
|
|
|
|
}
|
2018-01-14 01:41:15 +00:00
|
|
|
this.set({
|
2018-01-22 01:18:56 +00:00
|
|
|
verifyCredentials: verifyCredentials,
|
2018-01-14 04:07:11 +00:00
|
|
|
selectedTheme: instanceThemes[instanceName]
|
2018-01-14 01:41:15 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
2018-01-14 04:07:11 +00:00
|
|
|
onThemeChange() {
|
2018-01-14 01:41:15 +00:00
|
|
|
let newTheme = this.get('selectedTheme')
|
2018-01-14 04:07:11 +00:00
|
|
|
let instanceName = this.get('params').instanceName
|
2018-01-14 01:41:15 +00:00
|
|
|
let instanceThemes = this.store.get('instanceThemes')
|
|
|
|
instanceThemes[instanceName] = newTheme
|
|
|
|
this.store.set({instanceThemes: instanceThemes})
|
|
|
|
this.store.save()
|
2018-01-14 02:59:49 +00:00
|
|
|
if (this.get('params').instanceName === this.store.get('currentInstance')) {
|
|
|
|
switchToTheme(newTheme)
|
|
|
|
}
|
2018-01-14 04:07:11 +00:00
|
|
|
},
|
2018-01-22 02:36:40 +00:00
|
|
|
onSwitchToThisInstance(e) {
|
|
|
|
e.preventDefault()
|
2018-01-14 04:07:11 +00:00
|
|
|
let instanceName = this.get('params').instanceName
|
|
|
|
let instanceThemes = this.store.get('instanceThemes')
|
|
|
|
this.store.set({
|
|
|
|
currentInstance: instanceName
|
|
|
|
})
|
|
|
|
this.store.save()
|
|
|
|
switchToTheme(instanceThemes[instanceName])
|
2018-01-14 20:00:22 +00:00
|
|
|
},
|
2018-01-22 02:36:40 +00:00
|
|
|
onLogOut(e) {
|
|
|
|
e.preventDefault()
|
2018-01-14 20:00:22 +00:00
|
|
|
let loggedInInstances = this.store.get('loggedInInstances')
|
|
|
|
let instanceThemes = this.store.get('instanceThemes')
|
|
|
|
let loggedInInstancesInOrder = this.store.get('loggedInInstancesInOrder')
|
|
|
|
let instanceName = this.get('params').instanceName
|
|
|
|
let currentInstance = this.store.get('currentInstance')
|
|
|
|
loggedInInstancesInOrder.splice(loggedInInstancesInOrder.indexOf(instanceName), 1)
|
|
|
|
let newInstance = instanceName === currentInstance ?
|
|
|
|
loggedInInstancesInOrder[0] :
|
|
|
|
currentInstance
|
|
|
|
delete loggedInInstances[instanceName]
|
|
|
|
delete instanceThemes[instanceName]
|
|
|
|
this.store.set({
|
|
|
|
loggedInInstances: loggedInInstances,
|
|
|
|
instanceThemes: instanceThemes,
|
|
|
|
loggedInInstancesInOrder: loggedInInstancesInOrder,
|
|
|
|
currentInstance: newInstance
|
|
|
|
})
|
|
|
|
this.store.save()
|
2018-01-23 17:03:31 +00:00
|
|
|
database.clearDatabaseForInstance(instanceName)
|
2018-01-14 20:00:22 +00:00
|
|
|
switchToTheme(instanceThemes[newInstance] || 'default')
|
2018-01-15 07:36:44 +00:00
|
|
|
toast.say(`Logged out of ${instanceName}`)
|
2018-01-14 20:00:22 +00:00
|
|
|
goto('/settings/instances')
|
2018-01-14 01:41:15 +00:00
|
|
|
}
|
2018-01-13 22:19:51 +00:00
|
|
|
}
|
2018-01-13 20:12:17 +00:00
|
|
|
}
|
|
|
|
</script>
|