pinafore/routes/settings/instances/[instanceName].html

144 lines
4.1 KiB
HTML

<:Head>
<title>{{params.instanceName}}</title>
</:Head>
<Layout page='settings'>
<SettingsLayout page='settings/instances/{{params.instanceName}}' label="{{params.instanceName}}">
<h1 class="instance-name-h1">{{params.instanceName}}</h1>
{{#if verifyCredentials}}
<h2>Logged in as:</h2>
<div class="acct-current-user">
<img alt="Profile picture for {{'@' + verifyCredentials.acct}}"
class="acct-avatar" src="{{verifyCredentials.avatar}}" />
<a class="acct-handle" rel="noopener" target="_blank"
href="{{verifyCredentials.url}}">{{'@' + verifyCredentials.acct}}</a>
<span class="acct-display-name">{{verifyCredentials.display_name}}</span>
</div>
<h2>Theme:</h2>
<form class="theme-chooser" aria-label="Choose a theme">
{{#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>
<form class="instance-actions" aria-label="Switch to or log out of this instance">
{{#if $loggedInInstancesInOrder.length > 1 && $currentInstance !== params.instanceName}}
<button class="primary"
on:click="onSwitchToThisInstance(event)">
Switch to this instance
</button>
{{/if}}
<button on:click="onLogOut(event)">Log out</button>
</form>
{{/if}}
</SettingsLayout>
</Layout>
<style>
.acct-current-user {
background: var(--form-bg);
border: 1px solid var(--main-border);
border-radius: 4px;
padding: 20px;
display: grid;
align-items: center;
font-size: 1.3em;
grid-template-areas:
"avatar handle"
"avatar display-name";
grid-gap: 20px;
}
.acct-avatar {
width: 64px;
height: 64px;
border-radius: 4px;
grid-area: avatar;
}
.acct-handle {
grid-area: handle;
}
.theme-chooser {
background: var(--form-bg);
border: 1px solid var(--main-border);
border-radius: 4px;
display: block;
padding: 20px;
line-height: 2em;
}
.theme-group {
display: flex;
align-items: center;
}
.theme-chooser label {
margin: 2px 10px 0;
}
.instance-actions {
width: 100%;
display: flex;
justify-content: right;
margin: 20px 0;
}
.instance-actions button {
margin: 0 5px;
flex-basis: 100%;
}
.instance-name-h1 {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<script>
import { store } from '../../_utils/store'
import Layout from '../../_components/Layout.html'
import SettingsLayout from '../_components/SettingsLayout.html'
import {
changeTheme,
switchToInstance,
logOutOfInstance,
updateVerifyCredentialsForInstance
} from './_actions/[instanceName]'
import { themes } from '../../_static/themes'
export default {
components: {
Layout,
SettingsLayout
},
store: () => store,
data: () => ({
themes: themes,
}),
async oncreate() {
let instanceName = this.get('instanceName')
await updateVerifyCredentialsForInstance(instanceName)
},
computed: {
instanceName: (params) => params.instanceName,
selectedTheme: ($instanceThemes, instanceName) => $instanceThemes[instanceName],
verifyCredentials: ($verifyCredentials, instanceName) => $verifyCredentials && $verifyCredentials[instanceName]
},
methods: {
onThemeChange() {
let newTheme = this.get('selectedTheme')
let instanceName = this.get('instanceName')
changeTheme(instanceName, newTheme)
},
onSwitchToThisInstance(e) {
e.preventDefault()
let instanceName = this.get('instanceName')
switchToInstance(instanceName)
},
onLogOut(e) {
e.preventDefault()
let instanceName = this.get('instanceName')
logOutOfInstance(instanceName)
}
}
}
</script>