-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Webpack, website that queries backend
- Loading branch information
1 parent
cf0e13f
commit a9fd001
Showing
20 changed files
with
404 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .git | ||
| *Dockerfile* | ||
| *docker-compose* | ||
| node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,6 @@ __pycache__/ | |
| build/ | ||
| libraries/ | ||
| .swp | ||
| node_modules/ | ||
| package-lock.json | ||
| deploy/secret_env_vars.sh | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| #!/bin/sh | ||
| gcloud endpoints services deploy ../word_service_proto/api_descriptor.pb api_config.yaml | ||
| gcloud container clusters get-credentials word-service --zone us-central1-c | ||
| gcloud endpoints services deploy ../../word_service/word_service_proto/api_descriptor.pb api_config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| gcloud container clusters get-credentials word-service --zone us-central1-c | ||
| kubectl apply -f grpc-wordservice.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export PYTHONPATH=.: | ||
| adev runserver website --root website --port 8001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "website", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "private": true, | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "build": "webpack", | ||
| "watch": "webpack -d --watch" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "@babel/core": "^7.9.6", | ||
| "@babel/preset-env": "^7.9.6", | ||
| "babel-loader": "^8.1.0", | ||
| "mini-css-extract-plugin": "^0.9.0", | ||
| "webpack": "^4.43.0", | ||
| "webpack-cli": "^3.3.11" | ||
| }, | ||
| "dependencies": { | ||
| "css-loader": "^3.5.3", | ||
| "lodash": "^4.17.15", | ||
| "optimize-css-assets-webpack-plugin": "^5.0.3", | ||
| "whatwg-fetch": "^3.0.0" | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import 'whatwg-fetch' | ||
|
|
||
| function syncToWord(word) { | ||
| let posEl = document.getElementById("definition-pos"); | ||
| let wordEl = document.getElementById("definition-word"); | ||
| let syllablesEl = document.getElementById("definition-syllables"); | ||
| let definitionEl = document.getElementById("definition-definition"); | ||
| let exampleEl = document.getElementById("definition-example"); | ||
|
|
||
| posEl.innerHTML = word.pos; | ||
| if (!posEl.innerHTML.endsWith("]")) { | ||
| posEl.innerHTML += "."; | ||
| } | ||
|
|
||
| wordEl.innerHTML = word.word; | ||
| definitionEl.innerHTML = word.definition; | ||
| if (word.examples && word.examples.length > 0) { | ||
| exampleEl.innerHTML = word.examples[0]; | ||
| } else { | ||
| exampleEl.innerHTML = ""; | ||
| } | ||
|
|
||
| if (word.syllables && word.syllables.length > 1) { | ||
| syllablesEl.innerHTML = word.syllables.join("<span class='syllable-separator'>·</span>"); | ||
| } else { | ||
| syllablesEl.innerHTML = ""; | ||
| } | ||
| } | ||
|
|
||
| window.onload = () => { | ||
| let definitionEl = document.getElementById("definition-zone"); | ||
| let writeYourOwnEl = document.getElementById("write-your-own"); | ||
| let wordEntry = document.getElementById("word-entry"); | ||
| let writeButton = document.getElementById("write-button"); | ||
| let hintText = document.getElementById("hint-text"); | ||
| let loadingText = document.getElementById("word-loading"); | ||
| let wordEntryForm = document.getElementById("word-entry-form"); | ||
| let cancelButton = document.getElementById("word-entry-cancel") | ||
| let hintTextValue = document.getElementById("hint-text-value"); | ||
| let defaultHintText = hintTextValue.innerHTML; | ||
| var errorText = "something went wrong, try again?" | ||
|
|
||
| document.addEventListener('click', event => { | ||
| if (event.target == writeButton) { | ||
| event.preventDefault(); | ||
|
|
||
| errorText = "something went wrong, try again?" | ||
| definitionEl.style.display = "none"; | ||
| writeYourOwnEl.style.display = ""; | ||
| hintTextValue.innerHTML = defaultHintText; | ||
| wordEntry.value = ""; | ||
| wordEntry.disabled = false; | ||
| wordEntry.focus(); | ||
| } else if (event.target == cancelButton) { | ||
| event.preventDefault(); | ||
|
|
||
| definitionEl.style.display = ""; | ||
| writeYourOwnEl.style.display = "none"; | ||
| wordEntry.blur(); | ||
| } | ||
| }, false); | ||
|
|
||
|
|
||
| wordEntryForm.addEventListener("submit", e => { | ||
| e.preventDefault(); | ||
| wordEntry.disabled = true; | ||
| let word = wordEntry.value; | ||
| hintText.style.display = "none"; | ||
| hintTextValue.innerHTML = defaultHintText; | ||
| loadingText.style.display = ""; | ||
| document.activeElement.blur() | ||
| window.fetch(`/define_word?word=${encodeURIComponent(word)}`) | ||
| .then(res => res.json()) | ||
| .then(json => { | ||
| console.log(json); | ||
| if (!json.word) { | ||
| errorText = "we couldn't define that word" | ||
| throw new Error("couldn't define word"); | ||
| } | ||
|
|
||
| syncToWord(json.word); | ||
| definitionEl.style.display = ""; | ||
| writeYourOwnEl.style.display = "none"; | ||
| hintText.style.display = ""; | ||
| loadingText.style.display = "none"; | ||
| }) | ||
| .catch((error) => { | ||
| hintTextValue.innerHTML = errorText; | ||
| hintText.style.display = ""; | ||
| loadingText.style.display = "none"; | ||
| wordEntry.disabled = false; | ||
| wordEntry.focus(); | ||
| }); | ||
| }, false); | ||
| }; |
Oops, something went wrong.