Assign all stock apps an emoji, show them in the app list, and let the editor set them.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4242 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-03-21 23:08:04 +00:00
parent 53692a1ea8
commit ec65faa12d
12 changed files with 49 additions and 18 deletions

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "🎛"
} }

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "📜"
} }

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "💻"
} }

View File

@ -1,18 +1,28 @@
async function fetch_info(apps) {
let result = {};
for (let [key, value] of Object.entries(apps)) {
let blob = await ssb.blobGet(value);
blob = blob ? utf8Decode(blob) : '{}';
result[key] = JSON.parse(blob);
}
return result;
}
async function main() { async function main() {
var apps = await core.apps(); var apps = await fetch_info(await core.apps());
var core_apps = await core.apps('core'); var core_apps = await fetch_info(await core.apps('core'));
var doc = `<!DOCTYPE html> var doc = `<!DOCTYPE html>
<html> <html>
<head> <head>
<style> <style>
.container { .container {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, 8em); grid-template-columns: repeat(auto-fill, 64px);
justify-content: space-around; justify-content: space-around;
} }
.app { .app {
height: 8em; height: 96px;
width: 8em; width: 64px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
@ -21,7 +31,7 @@ async function main() {
} }
.app > a { .app > a {
text-decoration: none; text-decoration: none;
max-width: 8em; max-width: 64px;
text-overflow: ellipsis ellipsis; text-overflow: ellipsis ellipsis;
overflow: hidden; overflow: hidden;
} }
@ -42,7 +52,7 @@ async function main() {
let icon_a = document.createElement('a'); let icon_a = document.createElement('a');
let icon = document.createElement('div'); let icon = document.createElement('div');
icon.appendChild(document.createTextNode('📦')); icon.appendChild(document.createTextNode(apps[app].emoji || '📦'));
icon.style.fontSize = 'xxx-large'; icon.style.fontSize = 'xxx-large';
icon_a.appendChild(icon); icon_a.appendChild(icon);
icon_a.href = '/~' + name + '/' + app + '/'; icon_a.href = '/~' + name + '/' + app + '/';
@ -63,4 +73,4 @@ async function main() {
app.setDocument(doc); app.setDocument(doc);
} }
main(); main();

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "💽"
} }

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "📚"
} }

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "➡️"
} }

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "🐌"
} }

View File

@ -79,7 +79,7 @@ class TfElement extends LitElement {
WHERE author = ? AND WHERE author = ? AND
rowid > ? AND rowid > ? AND
rowid <= ? AND rowid <= ? AND
json_extract(content, "$.type") = "contact" json_extract(content, '$.type') = 'contact'
ORDER BY sequence ORDER BY sequence
`, `,
[id, last_row_id, max_row_id]); [id, last_row_id, max_row_id]);

View File

@ -1,3 +1,4 @@
{ {
"type": "tildefriends-app" "type": "tildefriends-app",
"emoji": "☑️"
} }

View File

@ -4,7 +4,7 @@ let gPermissions;
let gCurrentFile; let gCurrentFile;
let gFiles = {}; let gFiles = {};
let gApp = {files: {}}; let gApp = {files: {}, emoji: '📦'};
let gEditor; let gEditor;
let gSplit; let gSplit;
let gGraphs = {}; let gGraphs = {};
@ -219,6 +219,8 @@ function load(path) {
document.getElementById("editPane").style.display = 'flex'; document.getElementById("editPane").style.display = 'flex';
} }
gApp = json; gApp = json;
gApp.emoji = gApp.emoji || '📦';
document.getElementById('icon').value = gApp.emoji;
} }
if (!isApp) { if (!isApp) {
document.getElementById("editPane").style.display = 'flex'; document.getElementById("editPane").style.display = 'flex';
@ -293,6 +295,7 @@ function save(save_to) {
let app = { let app = {
type: "tildefriends-app", type: "tildefriends-app",
files: Object.fromEntries(Object.keys(gFiles).map(x => [x, gFiles[x].id || gApp.files[x]])), files: Object.fromEntries(Object.keys(gFiles).map(x => [x, gFiles[x].id || gApp.files[x]])),
emoji: gApp.emoji || '📦',
}; };
Object.values(gFiles).forEach(function(file) { delete file.id; }); Object.values(gFiles).forEach(function(file) { delete file.id; });
gApp = JSON.parse(JSON.stringify(app)); gApp = JSON.parse(JSON.stringify(app));
@ -325,6 +328,14 @@ function save(save_to) {
}); });
} }
function changeIcon() {
let value = prompt('Enter a new app icon emoji:');
if (value !== undefined) {
gApp.emoji = value || '📦';
document.getElementById('icon').value = gApp.emoji;
}
}
function deleteApp() { function deleteApp() {
let name = document.getElementById("name"); let name = document.getElementById("name");
let path = name && name.value ? name.value : url(); let path = name && name.value ? name.value : url();
@ -965,6 +976,7 @@ window.addEventListener("load", function() {
document.getElementById('closeStats').addEventListener('click', () => closeStats()); document.getElementById('closeStats').addEventListener('click', () => closeStats());
document.getElementById('closeEditor').addEventListener('click', () => closeEditor()); document.getElementById('closeEditor').addEventListener('click', () => closeEditor());
document.getElementById('save').addEventListener('click', () => save()); document.getElementById('save').addEventListener('click', () => save());
document.getElementById('icon').addEventListener('click', () => changeIcon());
document.getElementById('delete').addEventListener('click', () => deleteApp()); document.getElementById('delete').addEventListener('click', () => deleteApp());
document.getElementById('trace_button').addEventListener('click', function(event) { document.getElementById('trace_button').addEventListener('click', function(event) {
event.preventDefault(); event.preventDefault();

View File

@ -30,6 +30,7 @@
<div class="navigation hbox"> <div class="navigation hbox">
<input type="button" id="closeEditor" name="closeEditor" value="Close"> <input type="button" id="closeEditor" name="closeEditor" value="Close">
<input type="button" id="save" name="save" value="Save"> <input type="button" id="save" name="save" value="Save">
<input type="button" id="icon" name="icon" value="📦">
<input type="text" id="name" name="name" style="flex: 1 1; min-width: 1em"></input> <input type="text" id="name" name="name" style="flex: 1 1; min-width: 1em"></input>
<input type="button" id="delete" name="delete" value="Delete"> <input type="button" id="delete" name="delete" value="Delete">
<input type="button" id="trace_button" value="Trace"> <input type="button" id="trace_button" value="Trace">