diff --git a/src/renderer/components/Login/InstanceForm.vue b/src/renderer/components/Login/InstanceForm.vue
deleted file mode 100644
index 6b3c54e5..00000000
--- a/src/renderer/components/Login/InstanceForm.vue
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
- Search
-
-
-
-
-
-
-
-
diff --git a/src/renderer/components/Login/LoginForm.vue b/src/renderer/components/Login/LoginForm.vue
index 72c7304a..47f9a66f 100644
--- a/src/renderer/components/Login/LoginForm.vue
+++ b/src/renderer/components/Login/LoginForm.vue
@@ -1,7 +1,7 @@
-
-
-
+
+
+
@@ -9,7 +9,7 @@
@@ -32,19 +32,32 @@ import { mapState } from 'vuex'
export default {
name: 'login-form',
+ data () {
+ return {
+ form: {
+ domainName: ''
+ },
+ rules: {
+ domainName: [
+ {
+ type: 'string',
+ required: true,
+ message: 'Domain name is required'
+ },
+ {
+ pattern: /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/,
+ trigger: 'change',
+ message: 'Please write only domain name'
+ }
+ ]
+ }
+ }
+ },
computed: {
...mapState({
selectedInstance: state => state.Login.selectedInstance,
searching: state => state.Login.searching
- }),
- domainName: {
- get () {
- return this.$store.state.Login.domainName
- },
- set (value) {
- this.$store.dispatch('Login/updateDomainName', value)
- }
- }
+ })
},
methods: {
login () {
@@ -68,20 +81,30 @@ export default {
})
})
},
- confirm () {
- this.$store.dispatch('Login/confirmInstance', this.domainName)
- .then(() => {
+ confirm (formName) {
+ this.$refs[formName].validate((valid) => {
+ if (valid) {
+ this.$store.dispatch('Login/confirmInstance', this.form.domainName)
+ .then(() => {
+ this.$message({
+ message: `${this.form.domainName} is confirmed, please login`,
+ type: 'success'
+ })
+ })
+ .catch(() => {
+ this.$message({
+ message: `${this.form.domainName} does not exist`,
+ type: 'error'
+ })
+ })
+ } else {
this.$message({
- message: `${this.domainName} is confirmed, please login`,
- type: 'success'
- })
- })
- .catch(() => {
- this.$message({
- message: `${this.domainName} does not exist`,
+ message: 'Please write only domain name',
type: 'error'
})
- })
+ return false
+ }
+ })
}
}
}
diff --git a/src/renderer/store/Login.js b/src/renderer/store/Login.js
index 04b63ed1..fa4e71bf 100644
--- a/src/renderer/store/Login.js
+++ b/src/renderer/store/Login.js
@@ -5,50 +5,18 @@ const Login = {
namespaced: true,
state: {
instances: [],
- domainName: '',
selectedInstance: null,
- page: 2,
searching: false
},
mutations: {
- updateInstances (state, instances) {
- state.instances = instances
- },
changeInstance (state, instance) {
state.selectedInstance = instance
},
- changePage (state, page) {
- // Invalidate page changer until implement instance search form
- // state.page = page
- },
- updateDomainName (state, domain) {
- state.domainName = domain
- },
changeSearching (state, value) {
state.searching = value
}
},
actions: {
- searchInstance ({ commit }, domain) {
- return new Promise((resolve, reject) => {
- ipcRenderer.send('get-social-token', 'get')
- ipcRenderer.once('error-get-social-token', (event, err) => {
- ipcRenderer.removeAllListeners('response-get-social-token')
- reject(err)
- })
- ipcRenderer.once('response-get-social-token', (event, token) => {
- ipcRenderer.removeAllListeners('error-get-social-token')
- axios
- .get(`https://instances.social/api/1.0/instances/search?q=${domain}`, {
- 'headers': { 'Authorization': `Bearer ${token}` }
- })
- .then((res) => {
- commit('updateInstances', res.data.instances)
- resolve(res)
- })
- })
- })
- },
fetchLogin ({ commit }, instance) {
return new Promise((resolve, reject) => {
ipcRenderer.send('get-auth-url', instance)
@@ -62,14 +30,8 @@ const Login = {
})
})
},
- changeInstance ({ commit }, instance) {
- commit('changeInstance', instance)
- },
pageBack ({ commit }) {
- commit('changePage', 1)
- commit('updateInstances', [])
commit('changeInstance', null)
- commit('updateDomainName', '')
},
confirmInstance ({ commit }, domain) {
return new Promise((resolve, reject) => {
@@ -77,19 +39,13 @@ const Login = {
axios
.get(`https://${domain}/api/v1/instance`)
.then((res) => {
- commit('changeSearching', false)
commit('changeInstance', domain)
resolve(res)
})
- .catch((err) => {
+ .finally(() => {
commit('changeSearching', false)
- reject(err)
})
})
- },
- updateDomainName ({ commit }, domain) {
- commit('updateDomainName', domain)
- commit('changeInstance', null)
}
}
}