2018-04-03 18:01:22 -07:00
|
|
|
<SettingsLayout page='settings/instances/add' label="Add instance">
|
|
|
|
<h1 id="add-an-instance-h1">Add instance</h1>
|
2018-03-13 17:14:57 -07:00
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
<div class="add-new-instance">
|
|
|
|
<form on:submit='onSubmitInstance(event)' aria-labelledby="add-an-instance-h1">
|
2018-03-13 17:14:57 -07:00
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
{#if !hasIndexedDB || !hasLocalStorage}
|
|
|
|
<div class="form-error form-error-user-error" role="alert">
|
|
|
|
It seems Pinafore cannot store data locally. Is your browser in private mode
|
|
|
|
or blocking cookies? Pinafore stores all data locally, and requires LocalStorage and
|
|
|
|
IndexedDB to work correctly.
|
|
|
|
</div>
|
|
|
|
{/if}
|
2018-12-05 21:34:30 -08:00
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
{#if $logInToInstanceError && $logInToInstanceErrorForText === $instanceNameInSearch}
|
|
|
|
<div class="form-error form-error-user-error" role="alert">
|
|
|
|
Error: {$logInToInstanceError}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2018-03-13 17:14:57 -07:00
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
<noscript>
|
|
|
|
<div class="form-error" role="alert">
|
|
|
|
You must enable JavaScript to log in.
|
|
|
|
</div>
|
|
|
|
</noscript>
|
2018-03-13 17:14:57 -07:00
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
<label for="instanceInput">Instance:</label>
|
|
|
|
<input type="text" inputmode="url" id="instanceInput"
|
|
|
|
bind:value='$instanceNameInSearch' placeholder="Enter instance name" required
|
|
|
|
>
|
|
|
|
<button class="primary" type="submit" id="submitButton"
|
|
|
|
disabled={!$instanceNameInSearch || $logInToInstanceLoading}>
|
|
|
|
Log in
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
{#if $copyPasteMode }
|
|
|
|
<form aria-label="Enter code" on:submit="onSubmitOauth(event)">
|
|
|
|
<label for="oauthCodeInput">Code:</label>
|
|
|
|
<input type="text" id="oauthCodeInput"
|
|
|
|
bind:value='oauthCode' placeholder="Enter code" required
|
|
|
|
>
|
|
|
|
<button class="primary" type="submit" id="submitOauthButton"
|
|
|
|
disabled={!oauthCode}>
|
|
|
|
Submit
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2018-03-13 17:14:57 -07:00
|
|
|
|
2018-05-01 17:05:36 -07:00
|
|
|
{#if !$isUserLoggedIn}
|
2019-09-26 05:28:52 -07:00
|
|
|
<p>
|
|
|
|
Don't have an
|
|
|
|
<Tooltip
|
|
|
|
text="instance"
|
|
|
|
tooltipText="An instance is your Mastodon home server, such as mastodon.social or cybre.space."
|
|
|
|
/>
|
|
|
|
?
|
|
|
|
<ExternalLink href="https://joinmastodon.org">Join Mastodon!</ExternalLink>
|
|
|
|
</p>
|
|
|
|
{/if}
|
2019-05-04 14:16:15 -07:00
|
|
|
<p>
|
2019-09-26 05:28:52 -07:00
|
|
|
{#if $copyPasteMode}
|
|
|
|
Switch back to
|
|
|
|
{:else}
|
|
|
|
Trouble logging in? Switch to
|
|
|
|
{/if}
|
|
|
|
<button on:click="onCopyPasteModeButtonClick()"
|
|
|
|
class="copy-paste-mode-button"
|
|
|
|
aria-pressed={$copyPasteMode}>
|
|
|
|
{$copyPasteMode ? 'regular' : 'basic'} login mode
|
|
|
|
</button>.
|
2019-05-04 14:16:15 -07:00
|
|
|
</p>
|
2019-09-26 05:28:52 -07:00
|
|
|
{#if $copyPasteMode}
|
|
|
|
<InfoAside className="add-new-instance-aside">
|
|
|
|
In basic login mode, click "log in" to open a new window. Then copy the code and paste it above.
|
|
|
|
</InfoAside>
|
2018-05-01 17:05:36 -07:00
|
|
|
{/if}
|
2018-03-13 17:14:57 -07:00
|
|
|
</SettingsLayout>
|
|
|
|
<style>
|
2019-09-26 05:28:52 -07:00
|
|
|
.add-new-instance {
|
|
|
|
background: var(--form-bg);
|
|
|
|
padding: 5px 10px 15px;
|
|
|
|
margin: 20px auto;
|
|
|
|
border: 1px solid var(--form-border);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
2018-03-13 17:14:57 -07:00
|
|
|
.form-error {
|
|
|
|
border: 2px solid red;
|
|
|
|
border-radius: 2px;
|
|
|
|
padding: 10px;
|
|
|
|
font-size: 1.3em;
|
|
|
|
margin: 5px;
|
|
|
|
background-color: var(--main-bg);
|
|
|
|
}
|
2019-09-26 05:28:52 -07:00
|
|
|
input {
|
2018-08-16 22:15:22 -07:00
|
|
|
min-width: 70%;
|
2018-03-13 17:14:57 -07:00
|
|
|
max-width: 100%;
|
2018-12-04 07:25:22 -08:00
|
|
|
background-color: var(--input-bg);
|
2018-03-13 17:14:57 -07:00
|
|
|
}
|
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
label, input, button, :global(.add-new-instance-aside) {
|
2018-03-13 17:14:57 -07:00
|
|
|
display: block;
|
|
|
|
margin: 20px 5px;
|
|
|
|
}
|
2018-08-16 22:15:22 -07:00
|
|
|
|
2019-09-26 05:28:52 -07:00
|
|
|
button.copy-paste-mode-button {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
display: inline-block;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
font-size: 1em;
|
|
|
|
color: var(--anchor-text);
|
|
|
|
}
|
|
|
|
|
|
|
|
button.copy-paste-mode-button:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
|
2018-08-16 22:15:22 -07:00
|
|
|
@media (max-width: 767px) {
|
2019-09-26 05:28:52 -07:00
|
|
|
input {
|
2018-08-16 22:15:22 -07:00
|
|
|
min-width: 95%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 17:14:57 -07:00
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import SettingsLayout from '../../../_components/settings/SettingsLayout.html'
|
|
|
|
import { store } from '../../../_store/store'
|
2019-09-26 05:28:52 -07:00
|
|
|
import { logInToInstance, handleOauthCode, handleCopyPasteOauthCode } from '../../../_actions/addInstance'
|
2018-03-13 17:14:57 -07:00
|
|
|
import ExternalLink from '../../../_components/ExternalLink.html'
|
2018-12-11 22:07:01 -08:00
|
|
|
import { testHasIndexedDB, testHasLocalStorage } from '../../../_utils/testStorage'
|
2019-05-04 14:16:15 -07:00
|
|
|
import Tooltip from '../../../_components/Tooltip.html'
|
2019-09-26 05:28:52 -07:00
|
|
|
import InfoAside from '../../../_components/InfoAside.html'
|
2018-03-13 17:14:57 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
async oncreate () {
|
2019-08-03 13:49:37 -07:00
|
|
|
const codeMatch = location.search.match(/code=([^&]+)/)
|
2018-03-13 17:14:57 -07:00
|
|
|
if (codeMatch) {
|
2018-12-05 21:34:30 -08:00
|
|
|
return handleOauthCode(codeMatch[1])
|
2018-03-13 17:14:57 -07:00
|
|
|
}
|
2018-12-11 22:07:01 -08:00
|
|
|
this.set({
|
|
|
|
hasIndexedDB: await testHasIndexedDB(),
|
|
|
|
hasLocalStorage: testHasLocalStorage()
|
|
|
|
})
|
2018-03-13 17:14:57 -07:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
SettingsLayout,
|
2019-05-04 14:16:15 -07:00
|
|
|
ExternalLink,
|
2019-09-26 05:28:52 -07:00
|
|
|
Tooltip,
|
|
|
|
InfoAside
|
2018-03-13 17:14:57 -07:00
|
|
|
},
|
|
|
|
store: () => store,
|
2018-12-05 21:34:30 -08:00
|
|
|
data: () => ({
|
2018-12-11 22:07:01 -08:00
|
|
|
hasIndexedDB: true,
|
2019-09-26 05:28:52 -07:00
|
|
|
hasLocalStorage: true,
|
|
|
|
oauthCode: ''
|
2018-12-05 21:34:30 -08:00
|
|
|
}),
|
2018-03-13 17:14:57 -07:00
|
|
|
methods: {
|
2019-09-26 05:28:52 -07:00
|
|
|
onSubmitInstance (event) {
|
2018-03-13 17:14:57 -07:00
|
|
|
event.preventDefault()
|
2019-07-08 19:26:44 -07:00
|
|
|
event.stopPropagation()
|
2018-03-13 17:14:57 -07:00
|
|
|
logInToInstance()
|
2019-09-26 05:28:52 -07:00
|
|
|
},
|
|
|
|
onSubmitOauth (event) {
|
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
handleCopyPasteOauthCode(this.get().oauthCode)
|
|
|
|
},
|
|
|
|
onCopyPasteModeButtonClick () {
|
|
|
|
const { copyPasteMode } = this.store.get()
|
|
|
|
console.log('copyPasteMode', copyPasteMode)
|
|
|
|
this.store.set({ copyPasteMode: !copyPasteMode })
|
2018-03-13 17:14:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 07:25:22 -08:00
|
|
|
</script>
|