From 1e6773deb5be3dd625d6efefed914736f6bdd5ae Mon Sep 17 00:00:00 2001 From: Liyas Thomas Date: Fri, 11 Dec 2020 05:59:29 +0530 Subject: [PATCH] Refactor: Modularize home page (#1372) * Move HTTP headers section to component * Move import cURL modal to component * Move Notes, OAuth token modal to seperate components * Fix deepcode analysis * Move parameters section to seperate component * Move codegen modal to component * ES6 --- assets/js/regex.worker.js | 10 +- .../collections/import-export-collections.vue | 8 +- components/collections/save-request-as.vue | 1 - .../import-export-environment.vue | 8 +- components/http/codegen-modal.vue | 118 ++++ components/http/http-headers.vue | 101 +++ components/http/http-parameters.vue | 108 ++++ components/http/import-curl.vue | 54 ++ components/http/notes.vue | 30 + components/http/token-list.vue | 95 +++ components/realtime/mqtt.vue | 8 +- components/realtime/socketio.vue | 4 +- components/realtime/sse.vue | 4 +- components/realtime/websocket.vue | 4 +- helpers/postwomanTesting.js | 4 +- lang/en-US.json | 1 - nuxt.config.js | 6 +- pages/doc.vue | 4 +- pages/index.vue | 592 ++++-------------- 19 files changed, 660 insertions(+), 500 deletions(-) create mode 100644 components/http/codegen-modal.vue create mode 100644 components/http/http-headers.vue create mode 100644 components/http/http-parameters.vue create mode 100644 components/http/import-curl.vue create mode 100644 components/http/notes.vue create mode 100644 components/http/token-list.vue diff --git a/assets/js/regex.worker.js b/assets/js/regex.worker.js index c6f69036a..ab1024653 100644 --- a/assets/js/regex.worker.js +++ b/assets/js/regex.worker.js @@ -16,16 +16,14 @@ const regex = { ws, sse, socketio } // type = ws/sse/socketio async function validator(type, url) { - console.time("validator " + url) + console.time(`validator ${url}`) const [res1, res2] = await Promise.all([regex[type][0].test(url), regex[type][1].test(url)]) - console.timeEnd("validator " + url) + console.timeEnd(`validator ${url}`) return res1 || res2 } -onmessage = async function (event) { - var { type, url } = event.data - +onmessage = async ({ data }) => { + const { type, url } = data const result = await validator(type, url) - postMessage({ type, url, result }) } diff --git a/components/collections/import-export-collections.vue b/components/collections/import-export-collections.vue index 10e924f34..4eee1af0d 100644 --- a/components/collections/import-export-collections.vue +++ b/components/collections/import-export-collections.vue @@ -149,11 +149,11 @@ export default { }, } ) - .then((response) => { + .then(({ html_url }) => { this.$toast.success(this.$t("gist_created"), { icon: "done", }) - window.open(response.html_url) + window.open(html_url) }) .catch((error) => { this.$toast.error(this.$t("something_went_wrong"), { @@ -171,8 +171,8 @@ export default { Accept: "application/vnd.github.v3+json", }, }) - .then((response) => { - let collections = JSON.parse(Object.values(response.files)[0].content) + .then(({ files }) => { + let collections = JSON.parse(Object.values(files)[0].content) this.$store.commit("postwoman/replaceCollections", collections) this.fileImported() this.syncToFBCollections() diff --git a/components/collections/save-request-as.vue b/components/collections/save-request-as.vue index 300800879..3b48abc84 100644 --- a/components/collections/save-request-as.vue +++ b/components/collections/save-request-as.vue @@ -188,7 +188,6 @@ export default { }, hideModal() { this.$emit("hide-modal") - this.$emit("hide-model") // for backward compatibility // TODO: use fixed event }, }, } diff --git a/components/environments/import-export-environment.vue b/components/environments/import-export-environment.vue index a88ac0de7..fcf9262c0 100644 --- a/components/environments/import-export-environment.vue +++ b/components/environments/import-export-environment.vue @@ -149,11 +149,11 @@ export default { }, } ) - .then((response) => { + .then(({ html_url }) => { this.$toast.success(this.$t("gist_created"), { icon: "done", }) - window.open(response.html_url) + window.open(html_url) }) .catch((error) => { this.$toast.error(this.$t("something_went_wrong"), { @@ -171,8 +171,8 @@ export default { Accept: "application/vnd.github.v3+json", }, }) - .then((response) => { - let environments = JSON.parse(Object.values(response.files)[0].content) + .then(({ files }) => { + let environments = JSON.parse(Object.values(files)[0].content) this.$store.commit("postwoman/replaceEnvironments", environments) this.fileImported() this.syncToFBEnvironments() diff --git a/components/http/codegen-modal.vue b/components/http/codegen-modal.vue new file mode 100644 index 000000000..af5301275 --- /dev/null +++ b/components/http/codegen-modal.vue @@ -0,0 +1,118 @@ + + + diff --git a/components/http/http-headers.vue b/components/http/http-headers.vue new file mode 100644 index 000000000..060332a25 --- /dev/null +++ b/components/http/http-headers.vue @@ -0,0 +1,101 @@ + + + diff --git a/components/http/http-parameters.vue b/components/http/http-parameters.vue new file mode 100644 index 000000000..be50f4a70 --- /dev/null +++ b/components/http/http-parameters.vue @@ -0,0 +1,108 @@ + + + diff --git a/components/http/import-curl.vue b/components/http/import-curl.vue new file mode 100644 index 000000000..6a7227fb3 --- /dev/null +++ b/components/http/import-curl.vue @@ -0,0 +1,54 @@ + + + diff --git a/components/http/notes.vue b/components/http/notes.vue new file mode 100644 index 000000000..d83c43114 --- /dev/null +++ b/components/http/notes.vue @@ -0,0 +1,30 @@ + + + diff --git a/components/http/token-list.vue b/components/http/token-list.vue new file mode 100644 index 000000000..b8bdea37b --- /dev/null +++ b/components/http/token-list.vue @@ -0,0 +1,95 @@ + + + diff --git a/components/realtime/mqtt.vue b/components/realtime/mqtt.vue index dfd14ae64..fbf3e9ea3 100644 --- a/components/realtime/mqtt.vue +++ b/components/realtime/mqtt.vue @@ -116,8 +116,8 @@ export default { debouncer: debounce(function () { this.worker.postMessage({ type: "ws", url: this.url }) }, 1000), - workerResponseHandler(message) { - if (message.data.url === this.url) this.isUrlValid = message.data.result + workerResponseHandler({ data }) { + if (data.url === this.url) this.isUrlValid = data.result }, connect() { this.log = [ @@ -163,9 +163,9 @@ export default { icon: "sync", }) }, - onMessageArrived(message) { + onMessageArrived({ payloadString, destinationName }) { this.log.push({ - payload: `Message: ${message.payloadString} arrived on topic: ${message.destinationName}`, + payload: `Message: ${payloadString} arrived on topic: ${destinationName}`, source: "info", color: "var(--ac-color)", ts: new Date().toLocaleTimeString(), diff --git a/components/realtime/socketio.vue b/components/realtime/socketio.vue index eafd3b558..5dd8891fb 100644 --- a/components/realtime/socketio.vue +++ b/components/realtime/socketio.vue @@ -147,8 +147,8 @@ export default { debouncer: debounce(function () { this.worker.postMessage({ type: "socketio", url: this.url }) }, 1000), - workerResponseHandler(message) { - if (message.data.url === this.url) this.isUrlValid = message.data.result + workerResponseHandler({ data }) { + if (data.url === this.url) this.isUrlValid = data.result }, removeCommunicationInput({ index }) { this.$delete(this.communication.inputs, index) diff --git a/components/realtime/sse.vue b/components/realtime/sse.vue index e2a3e661d..788618d06 100644 --- a/components/realtime/sse.vue +++ b/components/realtime/sse.vue @@ -78,8 +78,8 @@ export default { debouncer: debounce(function () { this.worker.postMessage({ type: "sse", url: this.server }) }, 1000), - workerResponseHandler(message) { - if (message.data.url === this.url) this.isUrlValid = message.data.result + workerResponseHandler({ data }) { + if (data.url === this.url) this.isUrlValid = data.result }, toggleSSEConnection() { // If it is connecting: diff --git a/components/realtime/websocket.vue b/components/realtime/websocket.vue index 570233b3b..ba00dd0e8 100644 --- a/components/realtime/websocket.vue +++ b/components/realtime/websocket.vue @@ -105,8 +105,8 @@ export default { debouncer: debounce(function () { this.worker.postMessage({ type: "ws", url: this.url }) }, 1000), - workerResponseHandler(message) { - if (message.data.url === this.url) this.isUrlValid = message.data.result + workerResponseHandler({ data }) { + if (data.url === this.url) this.isUrlValid = data.result }, toggleConnection() { // If it is connecting: diff --git a/helpers/postwomanTesting.js b/helpers/postwomanTesting.js index d21247a78..b53b19276 100644 --- a/helpers/postwomanTesting.js +++ b/helpers/postwomanTesting.js @@ -157,7 +157,7 @@ class Expectation { toBeType(expectedType) { const actualType = typeof this.expectValue if ( - [ + ![ "string", "boolean", "number", @@ -166,7 +166,7 @@ class Expectation { "bigint", "symbol", "function", - ].indexOf(expectedType) < 0 + ].includes(expectedType) ) { return this._fail( this._fmtNot( diff --git a/lang/en-US.json b/lang/en-US.json index aa64102c6..8088decfc 100644 --- a/lang/en-US.json +++ b/lang/en-US.json @@ -31,7 +31,6 @@ "parameter_list": "Parameter List", "raw_request_body": "Raw Request Body", "show_code": "Show Code", - "hide_code": "Hide Code", "show_prerequest_script": "Show Pre-Request Script", "hide_prerequest_script": "Hide Pre-Request Script", "authentication": "Authentication", diff --git a/nuxt.config.js b/nuxt.config.js index 446c960ef..1e389f6e9 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -306,16 +306,16 @@ export default { // Build Configuration (https://go.nuxtjs.dev/config-build) build: { // You can extend webpack config here - extend(config, ctx) { + extend(config, { isDev, isClient }) { // Sets webpack's mode to development if `isDev` is true. - if (ctx.isDev) { + if (isDev) { config.mode = "development" } config.node = { fs: "empty", } - if (ctx.isClient) { + if (isClient) { config.module.rules.unshift({ test: /\.worker\.(c|m)?js$/i, use: { loader: "worker-loader" }, diff --git a/pages/doc.vue b/pages/doc.vue index b93af4b52..942078af3 100644 --- a/pages/doc.vue +++ b/pages/doc.vue @@ -384,11 +384,11 @@ export default { }, } ) - .then((response) => { + .then(({ html_url }) => { this.$toast.success(this.$t("gist_created"), { icon: "done", }) - window.open(response.html_url) + window.open(html_url) }) .catch((error) => { this.$toast.error(this.$t("something_went_wrong"), { diff --git a/pages/index.vue b/pages/index.vue index 84793bbbc..7cc91d042 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -252,7 +252,7 @@ @@ -312,93 +310,12 @@ " :selected="true" > - - - - - + @@ -462,7 +379,7 @@ - - - - -
    -
  • - -
  • -
  • - -
  • -
    -
  • - -
  • -
    -
-
    -
  • - -
  • -
- +
@@ -832,314 +686,127 @@ - -
- - -
-
-
    -
  • - -

    - -

    -
  • -
-
-
+
+ - + - -
-
    -
  • -
    -

    {{ $t("import_curl") }}

    -
    - -
    -
    -
  • -
-
-
-
    -
  • - -
  • -
-
-
-
- - - - - -
-
-
+ - -
-
    -
  • -
    -

    {{ $t("generate_code") }}

    -
    - -
    -
    -
  • -
-
-
-
    -
  • - - - -
    {{
    -                    codegens.find((x) => x.id === requestType).name
    -                  }}
    - - -
    -
    -
  • -
-
    -
  • -
    - -
    - -
    -
    - -
  • -
-
-
+ - -
-
    -
  • -
    -

    {{ $t("manage_token") }}

    -
    - -
    -
    -
  • -
-
-
-
    -
  • -
    - -
    - -
    -
    -
  • -
-
    -
  • - -
  • -
  • - -
  • + + + +
    +
      +
    • -
    • +

      {{ $t("manage_token_req") }}

      +
      + +
      +
    + +
+
+
+
    +
  • +
    + +
    -
  • -
  • -
  • +
- -

- {{ $t("empty") }} -

- -
- - -
-
    -
  • -
    -

    {{ $t("manage_token_req") }}

    -
    - -
    -
    -
  • -
-
-
-
    -
  • -
    - -
    - - -
    -
    - - - -
  • -
-
    -
  • - - -
  • -
-
    -
  • - - -
  • -
-
-
-
- - - + + -
+ + +
    +
  • + + +
  • +
+
    +
  • + + +
  • +
+
+
+
+ + + +
- -
+ +