This commit is contained in:
2023-01-29 14:30:01 +01:00
parent 08b71d12c9
commit 6ca6b5aa7d
10 changed files with 238 additions and 42 deletions

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/little_people_firebase.iml" filepath="$PROJECT_DIR$/.idea/little_people_firebase.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

24
package-lock.json generated Normal file
View File

@@ -0,0 +1,24 @@
{
"name": "little_people_firebase",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"typescript": "^4.9.4"
}
},
"node_modules/typescript": {
"version": "4.9.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz",
"integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
}
}
}
}

8
package.json Normal file
View File

@@ -0,0 +1,8 @@
{
"dependencies": {
"typescript": "^4.9.4"
},
"scripts": {
"build": "tsc --build"
}
}

BIN
public/avatars/example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

54
public/css/main.css Normal file
View File

@@ -0,0 +1,54 @@
body {
padding: 2em;
}
.header {
font-size: 4em;
}
.card {margin-bottom: 7em;
width: 80%;
overflow: hidden; /* will contain if #first is longer than #second */
border: 1px;
border-style: outset;
padding: .3em;
}
.pfp {width: 40%; max-width: 45%; float:left; height: 20em;margin: 2em;}
.person {max-width: 45%;overflow: hidden; max-height: 29em;margin: 2em;}
.bio {padding: .3em; margin: .5em}
.name {
font-size: 2em;
}
.picture {
max-width: 80%;
}
.bio-item {
font-size: 1.3em;
}
.item-content {
font-size: 1em;
}
@media only screen and (max-width: 600px) {
.header {
text-align: center;
}
.card {
padding: 0em;
width: 90%;
}
.pfp {
width: 100%;
max-width: 100%;
margin: 0;
height: auto;
float: none;
}
.picture {
max-width: 100%;
}
.person {
max-width: 90%;
width: 90%;
margin: 0;
padding: 1em;
float: none;
}
}

View File

@@ -17,56 +17,20 @@
<script defer src="/__/firebase/init.js?useEmulator=true"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<style>
body {
padding: 2em;
}
</style>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<h1>Fake People</h1>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<h1 class="header">Fake People</h1>
<div class="container" style="padding-top: 1em; padding-left: 3em" id="people">
</div>
<script>
var statusItem = document.querySelector("p#status");
var peopleList = document.querySelector("#people");
document.addEventListener('DOMContentLoaded', function() {
try {
let app = firebase.app();
let features = [
'database',
'storage'
].filter(feature => typeof app[feature] === 'function');
<script src="js/main.js">
} catch (e) {
console.error(e);
}
var database = firebase.database();
var rootRef = database.ref('/');
console.log(peopleList)
rootRef.once('value', function(snapshot){
snapshot.forEach(function(d) {
var v = d.val();
peopleList.innerHTML += `<div style="margin-bottom: 7em">
<h3 class="card-header">${v.firstName} ${v.lastName}</h3>
<h4>Gender:</h4>
<p>${v.gender}</p>
<h4>Age:</h4>
<p>${v.age}</p>
<h4>Current Country of Residence:</h4>
<p>${v.country}</p>
<h4>Job:</h4>
<p>${v.job}</p>
<h4>Bio:</h4>
<p>${v.bio}</p>
</div>`;
console.log(d.val());
});
});
});
</script>
</body>
</html>

69
ts/main.js Normal file
View File

@@ -0,0 +1,69 @@
var statusItem = document.querySelector("p#status");
var peopleList = document.querySelector("#people");
var pageSize = 100
var pageNum = (1 *pageSize) -1;
document.addEventListener('DOMContentLoaded', function() {
try {
let app = firebase.app();
let features = [
'database',
'storage'
].filter(feature => typeof app[feature] === 'function');
} catch (e) {
console.error(e);
}
var database = firebase.database();
var rootRef = database.ref('/').orderByChild("lastName").startAt(pageNum).limitToFirst(pageSize);
//const people = []
//console.log(peopleList)
rootRef.once('value', function(snapshot){
console.log(snapshot)
snapshot.forEach(function(d) {
console.log(d)
var v = d.val();
console.log(v)
peopleList.innerHTML += `<div class="card">
<div class="pfp">
<img class="picture" alt="not yet" src="avatars/example.png"></img>
</div>
<div class="person">
<h3 class="name">${v.firstName} ${v.lastName}</h3>
<h4 class="bio-item">Gender:</h4>
<p class="item-content">${v.gender}</p>
<h4 class="bio-item">Age:</h4>
<p class="item-content">${v.age}</p>
<h4 class="bio-item">Current Country of Residence:</h4>
<p class="item-content">${v.country}</p>
<h4 class="bio-item">Job:</h4>
<p class="item-content">${v.job}</p>
</div>
<div class="bio">
<h4 class="bio-item">Bio:</h4>
<p class="item-content">${v.bio}</p>
</div>
</div>`;
})
});
//console.log(people)
});
//console.log(people)
// snapshot.forEach(function(d) {
// var v = d.val();
// peopleList.innerHTML += `<div style="margin-bottom: 7em">
// <h3 class="card-header">${v.firstName} ${v.lastName}</h3>
// <h4>Gender:</h4>
// <p>${v.gender}</p>
// <h4>Age:</h4>
// <p>${v.age}</p>
// <h4>Current Country of Residence:</h4>
// <p>${v.country}</p>
// <h4>Job:</h4>
// <p>${v.job}</p>
// <h4>Bio:</h4>
// <p>${v.bio}</p>
// </div>`;
// console.log(d.val());
// });

47
ts/main.ts Normal file
View File

@@ -0,0 +1,47 @@
let peopleListDiv: HTMLElement = document.querySelector("#people")!;
var pageSize: number = 100;
var pageNum: number = (1 * pageSize) - 1;
document.addEventListener('DOMContentLoaded', function() {
try {
// @ts-ignore
let firebaseApp= firebase.app();
} catch (e) {
console.error(e);
}
// @ts-ignore
const firebaseDb = firebase.database();
var rootDatabaseReference = firebaseDb.ref('/').orderByChild("lastName").startAt(pageNum).limitToFirst(pageSize);
rootDatabaseReference.once('value', function(databaseSnapshot: any[]) {
console.debug(databaseSnapshot)
databaseSnapshot.forEach(function(snapshotEntry) {
console.debug(snapshotEntry)
var snapshotEntryValue = snapshotEntry.val();
console.debug(snapshotEntryValue)
peopleListDiv.innerHTML += `<div class="card">
<div class="pfp">
<img class="picture" alt="not yet" src="avatars/example.png"></img>
</div>
<div class="person">
<h3 class="name">${snapshotEntryValue.firstName} ${snapshotEntryValue.lastName}</h3>
<h4 class="bio-item">Gender:</h4>
<p class="item-content">${snapshotEntryValue.gender}</p>
<h4 class="bio-item">Age:</h4>
<p class="item-content">${snapshotEntryValue.age}</p>
<h4 class="bio-item">Current Country of Residence:</h4>
<p class="item-content">${snapshotEntryValue.country}</p>
<h4 class="bio-item">Job:</h4>
<p class="item-content">${snapshotEntryValue.job}</p>
</div>
<div class="bio">
<h4 class="bio-item">Bio:</h4>
<p class="item-content">${snapshotEntryValue.bio}</p>
</div>
</div>`;
})
})
})

16
tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "public/js",
"sourceMap": true,
"strict": true,
"target": "esnext",
"watch": true
},
"compileOnSave": true,
"include": [
"ts"
]
}