-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
0 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
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,18 @@ | ||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
module Swarm.Web.Worldview where | ||
|
||
import Data.Aeson (ToJSON) | ||
import Data.Map (Map) | ||
import Data.Text (Text) | ||
import GHC.Generics (Generic) | ||
import Servant.Docs qualified as SD | ||
|
||
data CellGrid = CellGrid | ||
{ coords :: [[Int]] | ||
, colors :: Map Int Text | ||
} | ||
deriving (Generic, ToJSON) | ||
|
||
instance SD.ToSample CellGrid where | ||
toSamples _ = SD.noSamples |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,26 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Web frontend</title> | ||
<script src="https://pixijs.download/release/pixi.js"></script> | ||
|
||
<script src="script/display.js"></script> | ||
<script src="script/fetch.js"></script> | ||
|
||
<script> | ||
window.onload=()=>{ | ||
|
||
setupGraphics(); | ||
|
||
const myList = document.querySelector("ul"); | ||
doFetch(myList); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<ul> | ||
<li>apple</li> | ||
<li>banana</li> | ||
</ul> | ||
</body> | ||
</html> |
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,21 @@ | ||
function setupGraphics() { | ||
|
||
// Create the application helper and add its render target to the page | ||
let app = new PIXI.Application({ | ||
width: 640, | ||
height: 360, | ||
backgroundColor: 0xFFFFFF | ||
}); | ||
document.body.appendChild(app.view); | ||
|
||
// Create the sprite and add it to the stage | ||
let sprite = PIXI.Sprite.from('handwritten-logo.png'); | ||
app.stage.addChild(sprite); | ||
|
||
// Add a ticker callback to move the sprite back and forth | ||
let elapsed = 0.0; | ||
app.ticker.add((delta) => { | ||
elapsed += delta; | ||
sprite.x = 100.0 + Math.cos(elapsed/50.0) * 100.0; | ||
}); | ||
} |
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,29 @@ | ||
function doFetch(myList) { | ||
|
||
fetch("hello") | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error, status = ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
for (const [key, color] of Object.entries(data.colors)) { | ||
const listItem = document.createElement("li"); | ||
|
||
const priceElement = document.createElement("strong"); | ||
priceElement.textContent = color; | ||
|
||
listItem.append( | ||
key + ": ", | ||
priceElement, | ||
); | ||
myList.appendChild(listItem); | ||
} | ||
}) | ||
.catch((error) => { | ||
const p = document.createElement("p"); | ||
p.appendChild(document.createTextNode(`Error: ${error.message}`)); | ||
document.body.insertBefore(p, myList); | ||
}); | ||
} |