diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..849f9d151 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +dist/ +.vscode/ +node_modules/ \ No newline at end of file diff --git a/package.json b/package.json index 8a298435a..643d42f2a 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,10 @@ "route-cache": "0.4.3", "serve-favicon": "^2.4.5", "vue": "^2.5.22", + "vue-client-only": "^2.0.0", "vue-router": "^3.0.1", "vue-server-renderer": "^2.5.22", + "vue-star-rating": "^1.6.1", "vuex": "^3.0.1", "vuex-router-sync": "^5.0.0" }, @@ -55,4 +57,4 @@ "webpack-merge": "^4.2.1", "webpack-node-externals": "^1.7.2" } -} \ No newline at end of file +} diff --git a/src/api/index.js b/src/api/index.js index c5122f0e8..45188b05b 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -16,12 +16,12 @@ if (api.onServer) { warmCache() } -function warmCache () { +function warmCache() { fetchItems((api.cachedIds.top || []).slice(0, 30)) setTimeout(warmCache, 1000 * 60 * 15) } -function fetch (child) { +function fetch(child) { logRequests && console.log(`fetching ${child}...`) const cache = api.cachedItems if (cache && cache.has(child)) { @@ -41,25 +41,25 @@ function fetch (child) { } } -export function fetchIdsByType (type) { +export function fetchIdsByType(type) { return api.cachedIds && api.cachedIds[type] ? Promise.resolve(api.cachedIds[type]) : fetch(`${type}stories`) } -export function fetchItem (id) { +export function fetchItem(id) { return fetch(`item/${id}`) } -export function fetchItems (ids) { +export function fetchItems(ids) { return Promise.all(ids.map(id => fetchItem(id))) } -export function fetchUser (id) { +export function fetchUser(id) { return fetch(`user/${id}`) } -export function watchList (type, cb) { +export function watchList(type, cb) { let first = true const ref = api.child(`${type}stories`) const handler = snapshot => { @@ -87,3 +87,26 @@ export function fetchSimilar(queries) { .then(resp => resp.json()) .then(json => json.rankings.map(i => i.entries)); } + +function uuidv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); + return v.toString(16); + }); +} + +export default function sendFeedBack(query, result, rating) { + if (document.sessionId === undefined) { + document.sessionId = uuidv4() + } + return fetchData('https://textsimilarity.research.peltarion.com/feedback', { + method: 'POST', + body: JSON.stringify({ + query: query, + result: result, + rating: rating, + dataset: 'hn-sbert', + sessionId: document.sessionId + }) + }) +} diff --git a/src/components/Similar.vue b/src/components/Similar.vue index 2e82f8537..92d8377bf 100644 --- a/src/components/Similar.vue +++ b/src/components/Similar.vue @@ -1,66 +1,105 @@