Skip to content
Snippets Groups Projects
Commit 11eb29c6 authored by Trirst's avatar Trirst
Browse files

Implement hot updating image list

parent 7323b71d
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"@vue/cli-plugin-router": "~4.5.0", "@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0", "@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0", "@vue/cli-service": "~4.5.0",
"axios": "^0.21.1",
"vue-template-compiler": "^2.6.11" "vue-template-compiler": "^2.6.11"
} }
}, },
...@@ -2924,6 +2925,15 @@ ...@@ -2924,6 +2925,15 @@
"integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=", "integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=",
"dev": true "dev": true
}, },
"node_modules/axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"dev": true,
"dependencies": {
"follow-redirects": "^1.10.0"
}
},
"node_modules/babel-loader": { "node_modules/babel-loader": {
"version": "8.2.2", "version": "8.2.2",
"resolved": "https://registry.npm.taobao.org/babel-loader/download/babel-loader-8.2.2.tgz?cache=0&sync_timestamp=1606424979080&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-loader%2Fdownload%2Fbabel-loader-8.2.2.tgz", "resolved": "https://registry.npm.taobao.org/babel-loader/download/babel-loader-8.2.2.tgz?cache=0&sync_timestamp=1606424979080&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-loader%2Fdownload%2Fbabel-loader-8.2.2.tgz",
...@@ -15269,7 +15279,8 @@ ...@@ -15269,7 +15279,8 @@
"version": "4.5.13", "version": "4.5.13",
"resolved": "https://registry.nlark.com/@vue/cli-plugin-vuex/download/@vue/cli-plugin-vuex-4.5.13.tgz", "resolved": "https://registry.nlark.com/@vue/cli-plugin-vuex/download/@vue/cli-plugin-vuex-4.5.13.tgz",
"integrity": "sha1-mGRti8HmnPbGpsui/tPqzgNWw2A=", "integrity": "sha1-mGRti8HmnPbGpsui/tPqzgNWw2A=",
"dev": true "dev": true,
"requires": {}
}, },
"@vue/cli-service": { "@vue/cli-service": {
"version": "4.5.13", "version": "4.5.13",
...@@ -15423,7 +15434,8 @@ ...@@ -15423,7 +15434,8 @@
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npm.taobao.org/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz?cache=0&sync_timestamp=1613215080607&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fpreload-webpack-plugin%2Fdownload%2F%40vue%2Fpreload-webpack-plugin-1.1.2.tgz", "resolved": "https://registry.npm.taobao.org/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz?cache=0&sync_timestamp=1613215080607&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fpreload-webpack-plugin%2Fdownload%2F%40vue%2Fpreload-webpack-plugin-1.1.2.tgz",
"integrity": "sha1-zrkktOyzucQ4ccekKaAvhCPmIas=", "integrity": "sha1-zrkktOyzucQ4ccekKaAvhCPmIas=",
"dev": true "dev": true,
"requires": {}
}, },
"@vue/web-component-wrapper": { "@vue/web-component-wrapper": {
"version": "1.3.0", "version": "1.3.0",
...@@ -15662,13 +15674,15 @@ ...@@ -15662,13 +15674,15 @@
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npm.taobao.org/ajv-errors/download/ajv-errors-1.0.1.tgz?cache=0&sync_timestamp=1616886450866&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv-errors%2Fdownload%2Fajv-errors-1.0.1.tgz", "resolved": "https://registry.npm.taobao.org/ajv-errors/download/ajv-errors-1.0.1.tgz?cache=0&sync_timestamp=1616886450866&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv-errors%2Fdownload%2Fajv-errors-1.0.1.tgz",
"integrity": "sha1-81mGrOuRr63sQQL72FAUlQzvpk0=", "integrity": "sha1-81mGrOuRr63sQQL72FAUlQzvpk0=",
"dev": true "dev": true,
"requires": {}
}, },
"ajv-keywords": { "ajv-keywords": {
"version": "3.5.2", "version": "3.5.2",
"resolved": "https://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-3.5.2.tgz", "resolved": "https://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-3.5.2.tgz",
"integrity": "sha1-MfKdpatuANHC0yms97WSlhTVAU0=", "integrity": "sha1-MfKdpatuANHC0yms97WSlhTVAU0=",
"dev": true "dev": true,
"requires": {}
}, },
"alphanum-sort": { "alphanum-sort": {
"version": "1.0.2", "version": "1.0.2",
...@@ -15913,6 +15927,15 @@ ...@@ -15913,6 +15927,15 @@
"integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=", "integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=",
"dev": true "dev": true
}, },
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"dev": true,
"requires": {
"follow-redirects": "^1.10.0"
}
},
"babel-loader": { "babel-loader": {
"version": "8.2.2", "version": "8.2.2",
"resolved": "https://registry.npm.taobao.org/babel-loader/download/babel-loader-8.2.2.tgz?cache=0&sync_timestamp=1606424979080&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-loader%2Fdownload%2Fbabel-loader-8.2.2.tgz", "resolved": "https://registry.npm.taobao.org/babel-loader/download/babel-loader-8.2.2.tgz?cache=0&sync_timestamp=1606424979080&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fbabel-loader%2Fdownload%2Fbabel-loader-8.2.2.tgz",
...@@ -24052,7 +24075,8 @@ ...@@ -24052,7 +24075,8 @@
"vuex": { "vuex": {
"version": "3.6.2", "version": "3.6.2",
"resolved": "https://registry.nlark.com/vuex/download/vuex-3.6.2.tgz", "resolved": "https://registry.nlark.com/vuex/download/vuex-3.6.2.tgz",
"integrity": "sha1-I2vAhqhww655lG8QfxbeWdWJXnE=" "integrity": "sha1-I2vAhqhww655lG8QfxbeWdWJXnE=",
"requires": {}
}, },
"watchpack": { "watchpack": {
"version": "1.7.5", "version": "1.7.5",
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang=""> <html lang="">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title> <title>
<%= htmlWebpackPlugin.options.title %>
</title>
</head> </head>
<body> <body>
<noscript> <noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
Please enable it to continue.</strong>
</noscript> </noscript>
<div id="app"></div> <div id="app"></div>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -5,24 +5,5 @@ ...@@ -5,24 +5,5 @@
</template> </template>
<style> <style>
/* #app { @import "./assets/css/normalize.css";
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
}
#nav a {
font-weight: bold;
color: #2c3e50;
}
#nav a.router-link-exact-active {
color: #42b983;
} */
</style> </style>
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}
\ No newline at end of file
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
export default { export default {
props: { props: {
hashArray: { hashArray: {
type: Array,
required: true, required: true,
}, },
}, },
......
...@@ -11,14 +11,18 @@ ...@@ -11,14 +11,18 @@
" "
multiple multiple
/> />
<button :disabled="notImage" @click="submitImages()">Submit</button> <button :disabled="notImage || noImage" @click="submitImages()">
Submit
</button>
</div>
<div v-if="notImage">
One or more files is possibly not image type. Please upload images only.
</div> </div>
<div v-if="notImage">One or more files is possibly not image type. Please upload images only.</div>
</div> </div>
</template> </template>
<script> <script>
// import { mapActions } from "vuex"; import { mapActions, mapState } from "vuex";
export default { export default {
data: () => { data: () => {
return { return {
...@@ -26,6 +30,12 @@ export default { ...@@ -26,6 +30,12 @@ export default {
notImage: false, notImage: false,
}; };
}, },
computed: {
noImage: function () {
return !this.imageList;
},
// ...mapState(["stateHashArray"]),
},
methods: { methods: {
updateImageList() { updateImageList() {
this.imageList = this.$refs.imageInput.files; this.imageList = this.$refs.imageInput.files;
...@@ -41,21 +51,23 @@ export default { ...@@ -41,21 +51,23 @@ export default {
}, },
submitImages() { submitImages() {
let formData = new FormData(); let formData = new FormData();
function postFile(fd) { for (let i = 0; i < this.imageList.length; i++) {
let options = {
method: "POST",
body: fd,
};
fetch("/api/image", options)
.then((response) => console.log(response))
.catch((error) => console.error(error));
}
for (var i = 0; i < this.imageList.length; i++) {
formData.set("image", this.imageList[i]); formData.set("image", this.imageList[i]);
postFile(formData); this.postImage(formData);
}
},
async postImage(fd) {
try {
const response = await fetch("api/image", { method: "POST", body: fd });
const data = await response.json();
console.log(data);
this.addStateHashArray(data.hash);
console.log("Hash added");
} catch {
(error) => console.error(error);
} }
}, },
// ...mapActions(["setHashArray"]), ...mapActions(["addStateHashArray"]),
}, },
}; };
</script> </script>
......
...@@ -8,14 +8,20 @@ export default new Vuex.Store({ ...@@ -8,14 +8,20 @@ export default new Vuex.Store({
stateHashArray: [], stateHashArray: [],
}, },
mutations: { mutations: {
setHashArray(state, array) { setStateHashArray(state, array) {
state.stateHashArray = array; state.stateHashArray = array;
},
addStateHashArray(state, hash) {
state.stateHashArray.push(hash);
} }
}, },
actions: { actions: {
setHashArray(context, payload) { setStateHashArray(context, payload) {
context.commit('setHashArray', payload) context.commit('setStateHashArray', payload)
}, },
addStateHashArray(context, payload) {
context.commit('addStateHashArray', payload)
}
}, },
modules: { modules: {
} }
......
<template> <template>
<div> <div id="home-container">
<section id="user-section"> <section id="user-section">
<TagCreation></TagCreation> <TagCreation></TagCreation>
<UploadImage></UploadImage> <ImageUpload @image-submitted="updateHashArray"></ImageUpload>
</section> </section>
<ImageList :hashArray="stateHashArray"></ImageList> <ImageList :hashArray="stateHashArray"></ImageList>
</div> </div>
...@@ -10,34 +10,32 @@ ...@@ -10,34 +10,32 @@
<script> <script>
import ImageList from "@/components/ImageList.vue"; import ImageList from "@/components/ImageList.vue";
import UploadImage from "@/components/UploadImage.vue"; import ImageUpload from "@/components/ImageUpload.vue";
import TagCreation from "@/components/TagCreation.vue"; import TagCreation from "@/components/TagCreation.vue";
import { mapState, mapActions } from "vuex"; import { mapState, mapActions } from "vuex";
export default { export default {
components: { components: {
ImageList, ImageList,
UploadImage, ImageUpload,
TagCreation, TagCreation,
}, },
computed: { computed: {
...mapState(["stateHashArray"]), ...mapState(["stateHashArray"]),
}, },
async created() { created() {
var hashArray = await this.getHashArray(); this.updateHashArray();
this.setHashArray(hashArray);
}, },
methods: { methods: {
async getHashArray() { async updateHashArray() {
try { const response = await fetch("api/image");
const response = await fetch("/api/image");
const data = await response.json(); const data = await response.json();
return data; if (data) {
} catch (error) { this.setStateHashArray(data);
console.error(error); console.log("Set State Hash Array");
} }
}, },
...mapActions(["setHashArray"]), ...mapActions(["setStateHashArray"]),
}, },
}; };
</script> </script>
...@@ -45,6 +43,11 @@ export default { ...@@ -45,6 +43,11 @@ export default {
<style scoped> <style scoped>
#user-section { #user-section {
display: flex; display: flex;
justify-content: space-around; flex-flow: column;
}
#home-container {
display: flex;
flex-flow: row;
} }
</style> </style>
\ No newline at end of file
module.exports = { module.exports = {
devServer: { devServer: {
proxy: 'http://localhost:7777/', proxy: 'http://localhost:7777/',
},
configureWebpack: {
devtool: 'source-map',
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment