diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..3cdc6ae --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..4daf1b2 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..61c67dd --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,458 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/copy.sh b/copy.sh index 333a0dd..c2e9680 100755 --- a/copy.sh +++ b/copy.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # rm -rf /home/martin/dev/menuserver/dist/* -cp -r /home/martin/dev/svelte-jobs/public/* /home/martin/dev/jobscraper/dist +cp -r /home/martin/dev/svelte-jobs/public/* /home/martin/dev/jobscraper/server/dist diff --git a/package-lock.json b/package-lock.json index 6ed8ce7..acb8c18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,6 +58,14 @@ } } }, + "@rollup/plugin-json": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.0.3.tgz", + "integrity": "sha512-QMUT0HZNf4CX17LMdwaslzlYHUKTYGuuk34yYIgZrNdu+pMEfqMS55gck7HEeHBKXHM4cz5Dg1OVwythDdbbuQ==", + "requires": { + "@rollup/pluginutils": "^3.0.8" + } + }, "@rollup/plugin-node-resolve": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz", @@ -75,7 +83,6 @@ "version": "3.0.10", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.0.10.tgz", "integrity": "sha512-d44M7t+PjmMrASHbhgpSbVgtL6EFyX7J4mYxwQ/c5eoaE6N2VgCgEcWVzNnwycIloti+/MpwFr8qfw+nRw00sw==", - "dev": true, "requires": { "@types/estree": "0.0.39", "estree-walker": "^1.0.1", @@ -85,8 +92,7 @@ "estree-walker": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==" } } }, @@ -99,8 +105,7 @@ "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", - "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", - "dev": true + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" }, "@types/node": { "version": "14.0.1", @@ -791,6 +796,14 @@ "sha.js": "^2.4.8" } }, + "cron": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/cron/-/cron-1.8.2.tgz", + "integrity": "sha512-Gk2c4y6xKEO8FSAUTklqtfSr7oTq0CiPQeLBG5Fl0qoXpZyMcj1SG59YL+hqq04bu6/IuEA7lMkYDAplQNKkyg==", + "requires": { + "moment-timezone": "^0.5.x" + } + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -2305,6 +2318,19 @@ "minimist": "^1.2.5" } }, + "moment": { + "version": "2.25.3", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.25.3.tgz", + "integrity": "sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg==" + }, + "moment-timezone": { + "version": "0.5.31", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz", + "integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==", + "requires": { + "moment": ">= 2.9.0" + } + }, "mri": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/mri/-/mri-1.1.5.tgz", @@ -2313,8 +2339,7 @@ "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "mute-stream": { "version": "0.0.8", @@ -2688,8 +2713,7 @@ "picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", - "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==", - "dev": true + "integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==" }, "pify": { "version": "2.3.0", diff --git a/package.json b/package.json index df9954b..ca1faa2 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,10 @@ "svelte-preprocess": "^3.7.1" }, "dependencies": { + "@rollup/plugin-json": "^4.0.3", "autoprefixer": "^9.7.6", + "cron": "^1.8.2", + "ms": "^2.1.2", "node-sass": "^4.14.1", "redaxios": "^0.2.0", "rollup-plugin-replace": "^2.2.0", diff --git a/public/gfx/star.svg b/public/gfx/star.svg new file mode 100644 index 0000000..66c36c2 --- /dev/null +++ b/public/gfx/star.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/index.html b/public/index.html index 5da7ed3..e744409 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,7 @@ - Svelte app + Jobs Server diff --git a/rollup.config.js b/rollup.config.js index b3b9379..127b769 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -7,6 +7,7 @@ import { terser } from 'rollup-plugin-terser'; import sveltePreprocess from 'svelte-preprocess'; import builtins from 'rollup-plugin-node-builtins'; import globals from 'rollup-plugin-node-globals'; +import json from '@rollup/plugin-json'; const production = !process.env.ROLLUP_WATCH; @@ -30,6 +31,7 @@ export default { 'plugins': [ globals(), builtins(), + json(), svelte({ // enable run-time checks when not in production 'dev': !production, diff --git a/src/App.svelte b/src/App.svelte index 4e657e2..a7caf73 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2,6 +2,7 @@ import Menu from "./components/Menu.svelte"; import Lister from "./components/Lister.svelte"; import Detail from "./components/Detail.svelte"; + import Header from "./components/Header.svelte"; - -
- -
-
- -
-
- - -
-
+ + diff --git a/src/components/Detail.svelte b/src/components/Detail.svelte index e1db1e6..c6134dc 100644 --- a/src/components/Detail.svelte +++ b/src/components/Detail.svelte @@ -4,18 +4,52 @@ let jobDetail = {}; let visible = false; + let applied = false; + let jobtype = 0; + + $: { + if (!isEmpty($JobDetails)) { + applied = typeof ($JobDetails.data.applied) === "number" && $JobDetails.data.applied === 1; + jobtype = $JobDetails.data.jobtype; + } + } JobDetails.subscribe((v) => { visible = !isEmpty(v); + console.log(v); + }) function isEmpty(obj) { - for(const key in obj) - if(obj.hasOwnProperty(key)) return false; + for (const key in obj) + if (obj.hasOwnProperty(key)) return false; return true; } + + function handleClick() { + actions.appliedJob($JobDetails._id); + } + + function kill(w) { + console.log('>>kill',w); + } + + function upvote() { + + console.log('Upvote', $JobDetails._id); + + actions.upVote($JobDetails._id); + } + + function downvote() { + console.log('Downvote', $JobDetails._id); + + actions.downVote($JobDetails._id); + } + + {#if visible} -
-
-
-
- {$JobDetails.title} +
+
+
+
+ {$JobDetails.title} + +
+ + {#if jobtype === 1} + Contract + {:else if jobtype === 2} + Permanent + {/if} +
+
+
+ Company: {$JobDetails.company} +
+
+ Location: {$JobDetails.location} +
+
+ Applied: + {#if !$JobDetails.a} + + {:else} + Applied! + {/if} + +
+ +
+ +
+
+ Salary: {$JobDetails.salary} +
+
+ Scraped: {$JobDetails.date} +
+
+ Site: {$JobDetails.site} +
+ +
+ +
+
+ {#each $JobDetails.data.autoclass.words as word, _wid} + {#if $JobDetails.data.autoclass.good.indexOf(word) !== -1} + {word} + {:else if $JobDetails.data.autoclass.bad.indexOf(word) !== -1} + {word} + {:else } + {word} + {/if} + {/each} + +
+
+ +
+
+ +
+ +
+
-
-
- Company: {$JobDetails.company} -
-
- Location: {$JobDetails.location} -
-
- -
-
- Salary: {$JobDetails.salary} -
-
- Scraped: {$JobDetails.date} -
-
- Site: {$JobDetails.site} -
- -
- - +
+ {@html $JobDetails.summary} +
-
- {$JobDetails.summary} -
-
{/if} diff --git a/src/components/Header.svelte b/src/components/Header.svelte new file mode 100644 index 0000000..d83647b --- /dev/null +++ b/src/components/Header.svelte @@ -0,0 +1,34 @@ + + + + + diff --git a/src/components/Lister.svelte b/src/components/Lister.svelte index be4cfa6..14b31d1 100644 --- a/src/components/Lister.svelte +++ b/src/components/Lister.svelte @@ -2,9 +2,32 @@ import {JobList, actions} from '../state/state'; + let prevRow; + const handleClick = id => { actions.loadJobDetail(id); }; + + function clickEvent(event) { + const parent = event.target.parentElement; + const id = parent.dataset.id; + actions.loadJobDetail(id); + actions.touchJob(id); + } + + function ellipses(instr) { + return (instr.length <= 40) ? instr : `${instr.slice(0, 40)}…` + + } + + function haveRead(inval) { + return (inval.read !== 0) ? 'read' : ''; + } + + function haveApplied(inval) { + return (inval.applied !== 0) ? 'applied' : ''; + } + @@ -40,10 +99,22 @@ {#each $JobList as item, _id} - - {item.title} + + + + {item.title} + + {item.site} - {item.company} + {ellipses(item.company)} {item.date} {/each} diff --git a/src/components/Menu.svelte b/src/components/Menu.svelte index 7267b2e..379f411 100644 --- a/src/components/Menu.svelte +++ b/src/components/Menu.svelte @@ -1,23 +1,27 @@ - + +
diff --git a/src/css/global.scss b/src/css/global.scss index 947fa92..1ae1acf 100644 --- a/src/css/global.scss +++ b/src/css/global.scss @@ -3,7 +3,6 @@ /* Global Styles */ - :root { --primary-color: #607D8B; --dark-color: #294c5d; @@ -28,7 +27,7 @@ body { line-height: 1.6; background-color: #fff; color: #333; - padding:0; + padding: 0; } a { @@ -40,7 +39,7 @@ a:hover { color: #666; } -a.active{ +a.active { color: var(--highlight-color); } @@ -64,6 +63,11 @@ img { padding: 0 2rem; } +.fullWidth { + max-width: 100vw; + padding: 0 0; +} + /* Text Styles*/ .x-large { font-size: 4rem; @@ -195,24 +199,31 @@ img { .p { padding: 0.5rem; } + .p-1 { padding: 1rem; } + .p-2 { padding: 2rem; } + .p-3 { padding: 3rem; } + .py { padding: 0.5rem 0; } + .py-1 { padding: 1rem 0; } + .py-2 { padding: 2rem 0; } + .py-3 { padding: 3rem 0; } @@ -221,6 +232,7 @@ img { .m { margin: 0.5rem; } + .m-1 { margin: 1rem; } @@ -274,15 +286,19 @@ img { .m-3 { margin: 3rem; } + .my { margin: 0.5rem 0; } + .my-1 { margin: 1rem 0; } + .my-2 { margin: 2rem 0; } + .my-3 { margin: 3rem 0; } @@ -343,16 +359,19 @@ img { padding-right: 15px; }*/ - .column, - .columns { - margin-left: 4%; } - .column:first-child, - .columns:first-child { - margin-left: 0; } +.column, +.columns { + margin-left: 4%; +} - .col-1 { - width: 8.33333%; - } +.column:first-child, +.columns:first-child { + margin-left: 0; +} + +.col-1 { + width: 8.33333%; +} .col-2 { width: 16.66667%; @@ -469,7 +488,6 @@ img { } - .btn { display: inline-block; background: var(--light-color); @@ -624,16 +642,19 @@ label, legend { display: block; margin-bottom: .1rem; - font-weight: 600; } + font-weight: 600; +} input[type="checkbox"], input[type="radio"] { - display: inline; } + display: inline; +} + label > .label-body { display: inline-block; margin-left: .5rem; font-weight: normal; -background-color: #dcc894; + background-color: #dcc894; } @@ -649,7 +670,7 @@ table th { /* Navbar */ .navbar { - position:fixed; + position: fixed; display: flex; justify-content: space-between; align-items: center; @@ -757,7 +778,7 @@ table th { .cardV2 { border-radius: 4px; background-color: #fff; - box-shadow: 0 0 4px 0 rgba(0,0,0,.14), 0 3px 4px 0 rgba(0,0,0,.12), 0 1px 5px 0 rgba(0,0,0,.2); + box-shadow: 0 0 4px 0 rgba(0, 0, 0, .14), 0 3px 4px 0 rgba(0, 0, 0, .12), 0 1px 5px 0 rgba(0, 0, 0, .2); /*display: flex; flex-direction: column;*/ min-width: 0; @@ -777,8 +798,8 @@ tr { border-top: 1px solid #ccc; } -tbody tr:nth-of-type(odd){ - background-color: rgba(0,0,0,0.04); +tbody tr:nth-of-type(odd) { + background-color: rgba(0, 0, 0, 0.04); } tbody td { @@ -789,8 +810,8 @@ hr { margin-top: 2.2rem; margin-bottom: 2rem; border-width: 0; - border-top: 1px solid var(--dark-color); } - + border-top: 1px solid var(--dark-color); +} .modalWindow { @@ -799,16 +820,18 @@ hr { right: 0; bottom: 0; left: 0; - background: rgba(0,0,0,0.2); + background: rgba(0, 0, 0, 0.2); z-index: 99999; - opacity:0; + opacity: 0; pointer-events: none; - text-align:center; + text-align: center; } + .modalWindow:target { - opacity:1; + opacity: 1; pointer-events: auto; } + .modalWindow > div { width: 500px; position: relative; @@ -818,8 +841,9 @@ hr { header + div.container { position: relative; - top:var(--navbar-height); + top: var(--navbar-height); min-height: calc(100vh - var(--navbar-height)); + max-height: calc(100vh - var(--navbar-height)); } @@ -920,42 +944,149 @@ header + div.container { // Mouse pointers -.alias {cursor: alias;} -.all-scroll {cursor: all-scroll;} -.auto {cursor: auto;} -.cell {cursor: cell;} -.context-menu {cursor: context-menu;} -.col-resize {cursor: col-resize;} -.copy {cursor: copy;} -.crosshair {cursor: crosshair;} -.default {cursor: default;} -.e-resize {cursor: e-resize;} -.ew-resize {cursor: ew-resize;} -.grab {cursor: grab;} -.grabbing {cursor: grabbing;} -.help {cursor: help;} -.move {cursor: move;} -.n-resize {cursor: n-resize;} -.ne-resize {cursor: ne-resize;} -.nesw-resize {cursor: nesw-resize;} -.ns-resize {cursor: ns-resize;} -.nw-resize {cursor: nw-resize;} -.nwse-resize {cursor: nwse-resize;} -.no-drop {cursor: no-drop;} -.none {cursor: none;} -.not-allowed {cursor: not-allowed;} -.pointer {cursor: pointer;} -.progress {cursor: progress;} -.row-resize {cursor: row-resize;} -.s-resize {cursor: s-resize;} -.se-resize {cursor: se-resize;} -.sw-resize {cursor: sw-resize;} -.text {cursor: text;} -.url {cursor: url(myBall.cur),auto;} -.w-resize {cursor: w-resize;} -.wait {cursor: wait;} -.zoom-in {cursor: zoom-in;} -.zoom-out {cursor: zoom-out;} +.alias { + cursor: alias; +} + +.all-scroll { + cursor: all-scroll; +} + +.auto { + cursor: auto; +} + +.cell { + cursor: cell; +} + +.context-menu { + cursor: context-menu; +} + +.col-resize { + cursor: col-resize; +} + +.copy { + cursor: copy; +} + +.crosshair { + cursor: crosshair; +} + +.default { + cursor: default; +} + +.e-resize { + cursor: e-resize; +} + +.ew-resize { + cursor: ew-resize; +} + +.grab { + cursor: grab; +} + +.grabbing { + cursor: grabbing; +} + +.help { + cursor: help; +} + +.move { + cursor: move; +} + +.n-resize { + cursor: n-resize; +} + +.ne-resize { + cursor: ne-resize; +} + +.nesw-resize { + cursor: nesw-resize; +} + +.ns-resize { + cursor: ns-resize; +} + +.nw-resize { + cursor: nw-resize; +} + +.nwse-resize { + cursor: nwse-resize; +} + +.no-drop { + cursor: no-drop; +} + +.none { + cursor: none; +} + +.not-allowed { + cursor: not-allowed; +} + +.pointer { + cursor: pointer; +} + +.progress { + cursor: progress; +} + +.row-resize { + cursor: row-resize; +} + +.s-resize { + cursor: s-resize; +} + +.se-resize { + cursor: se-resize; +} + +.sw-resize { + cursor: sw-resize; +} + +.text { + cursor: text; +} + +.url { + cursor: url(myBall.cur), auto; +} + +.w-resize { + cursor: w-resize; +} + +.wait { + cursor: wait; +} + +.zoom-in { + cursor: zoom-in; +} + +.zoom-out { + cursor: zoom-out; +} /* @@ -966,3 +1097,116 @@ header + div.container { display: table; clear: both; } */ + + +.hour27 { + border-left: 10px solid rgb(80, 181, 221) +} + +.hour26 { + border-left: 10px solid rgb(78, 178, 206) +} + +.hour25 { + border-left: 10px solid rgb(76, 176, 190) +} + +.hour24 { + border-left: 10px solid rgb(73, 173, 175) +} + +.hour23 { + border-left: 10px solid rgb(72, 171, 159) +} + +.hour22 { + border-left: 10px solid rgb(70, 168, 142) +} + +.hour21 { + border-left: 10px solid rgb(68, 166, 125) +} + +.hour20 { + border-left: 10px solid rgb(66, 164, 108) +} + +.hour19 { + border-left: 10px solid rgb(102, 173, 94) +} + +.hour18 { + border-left: 10px solid rgb(135, 190, 64) +} + +.hour17 { + border-left: 10px solid rgb(179, 204, 26) +} + +.hour16 { + border-left: 10px solid rgb(214, 213, 28) +} + +.hour15 { + border-left: 10px solid rgb(249, 202, 3) +} + +.hour14 { + border-left: 10px solid rgb(246, 181, 3) +} + +.hour13 { + border-left: 10px solid rgb(244, 150, 26) +} + +.hour12 { + border-left: 10px solid rgb(236, 110, 5) +} + +.hour11 { + border-left: 10px solid #ea5a24; +} + +.hour10 { + border-left: 10px solid #e4572b; +} + +.hour09 { + border-left: 10px solid #e14a29; +} + +.hour08 { + border-left: 10px solid #e04127; +} + +.hour07 { + border-left: 10px solid #d9372b; +} + +.hour06 { + border-left: 10px solid #d63129; +} + +.hour05 { + border-left: 10px solid #d12b2b; +} + +.hour04 { + border-left: 10px solid #cd282f; +} + +.hour03 { + border-left: 10px solid #c82432; +} + +.hour02 { + border-left: 10px solid #c32334; +} + +.hour01 { + border-left: 10px solid #be2138; +} + +.hour00 { + border-left: 10px solid #b9203b; +} diff --git a/src/main.js b/src/main.js index e13d6b7..0824b78 100644 --- a/src/main.js +++ b/src/main.js @@ -1,11 +1,32 @@ import App from './App.svelte'; +import ms from 'ms'; import { actions } from './state/state'; +let timerID = 0; + const app = new App({ 'target': document.body }); -actions.getJobList(); +function toHour(extra = 0) { + const now = new Date(); + + return (3600000 - (now.getTime() % 3600000)) + extra; +} + +function update() { + actions.getJobList(); + + const delay = toHour() + ms('10m'); + + console.log('Next:', delay); + + timerID = setTimeout(() => { + update(); + }, delay); +} + +update(); export default app; diff --git a/src/oldapp.txt b/src/oldapp.txt new file mode 100644 index 0000000..4e657e2 --- /dev/null +++ b/src/oldapp.txt @@ -0,0 +1,34 @@ + + + + + +
+ +
+
+ +
+
+ + +
+
+
diff --git a/src/state/state.js b/src/state/state.js index 45bd473..7d57a12 100644 --- a/src/state/state.js +++ b/src/state/state.js @@ -9,10 +9,15 @@ import { writable, get } from 'svelte/store'; import axios from 'redaxios'; -// const baseUrl = (__ENV__ === 'production') ? (`${location.protocol }//${ location.hostname}`) : 'http://localhost:3000'; -const baseUrl = 'http://localhost:3000'; +const baseUrl = (__ENV__ === 'production') ? (`${location.protocol }//${ location.hostname}`) : 'http://localhost:3000'; +// const baseUrl = 'http://localhost:3000'; const urls = { - 'jobs': baseUrl.concat('/jobs') + 'jobs': baseUrl.concat('/jobs'), + 'apply': baseUrl.concat('/apply'), + 'readall' : baseUrl.concat('/readall'), + 'kill' : baseUrl.concat('/kill'), + 'upvote' : baseUrl.concat('/vote/up'), + 'downvote' : baseUrl.concat('/vote/down') }; const JobList = writable([]); @@ -42,8 +47,123 @@ const actions = { console.error('loadJobDetail', err); }); } + }, + + async touchJob(id) { + console.log(`touchJob: ${id}`); + if (id) { + const u = `${urls.jobs}/${id}`; + await axios.put(u).then((d) => { + if (d.status !== 200) + console.error(d); + }).catch((err) => { + console.error('touchJob', err); + }); + + JobList.update((data) => { + data.map((v) => { + if (v._id === id) { + v.read = new Date().getTime(); + + return v; + } + }); + + return data; + }); + } + }, + + async appliedJob(id) { + console.log(`touchJob: ${id}`); + + const now = new Date().getTime(); + + // JobDetails + + if (id) { + console.log('Applying..'); + const u = `${urls.apply}/${id}`; + await axios.put(u).then((d) => { + if (d.status !== 200) + console.error(d); + }).catch((err) => { + console.error('appliedJob', err); + }); + + const _id = parseInt(id, 10); + + JobList.update((data) => { + data.map((v) => { + if (v._id === _id) { + v.a = now; + + return v; + } + }); + + return data; + }); + + JobDetails.update((v) => { + v.a = now; + + return v; + }); + } + }, + + async markAllRead() { + console.log('>> markAllRead'); + + const u = `${urls.readall}`; + await axios.put(u).then((d) => { + if (d.status !== 200) + console.error(d); + }).catch((err) => { + console.error('markAllRead', err); + }); + + this.getJobList(); + }, + + killWord(word) { + console.log(`>> killword:${word}`); + + const u = `${urls.kill}/${word}`; + axios.put(u).then((d) => { + if (d.status !== 200) + console.error(d); + }).catch((err) => { + console.error('killword', err); + }); + }, + + upVote(id) { + console.log(`>> upvote:${id}`); + + const u = `${urls.upvote}/${id}`; + axios.put(u).then((d) => { + if (d.status !== 200) + console.error(d); + }).catch((err) => { + console.error('upvote', err); + }); + }, + + downVote(id) { + console.log(`>> downvote:${id}`); + + const u = `${urls.downvote}/${id}`; + axios.put(u).then((d) => { + if (d.status !== 200) + console.error(d); + }).catch((err) => { + console.error('downvote', err); + }); } + }; export { JobList, JobDetails, actions };