Skip to content

Commit fcf5a33

Browse files
wiring up some core/event binding stuff. rename pages -> boards. i love the pages idea, but its a bit premature. we should get the new ui out and THEN rearchitect everything ffs.
1 parent 425b9fa commit fcf5a33

File tree

10 files changed

+37
-32
lines changed

10 files changed

+37
-32
lines changed

src/App.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import darkmode from './models/darkmode';
1212
import { procerr } from './util/error';
1313
import Emitter from './util/event';
14+
import log from './util/log';
1415
import { init as i18n_init, loc } from './util/i18n';
1516
import * as shortcuts from './util/shortcuts';
1617
import { onMount } from 'svelte';
@@ -71,6 +72,9 @@
7172
}
7273
};
7374
core.events.on('connected', check_connected);
75+
core.events.on('error', (ev) => {
76+
log.error(`core error`, ev.err);
77+
});
7478
check_connected();
7579
});
7680
</script>

src/components/util/Loading.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
export let logs = [];
88
9-
const dot = `<img class="w-6 h-6 mx-1" src="${logo}" alt="${loc('logo')}">`;
9+
const dot = `<img class="w-8 h-8 md:w-12 md:h-12 mx-1" src="${logo}" alt="${loc('logo')}">`;
1010
let dots = dot;
1111
let i = 0;
1212
let dot_interval = setInterval(() => {

src/core-adapters/mock.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
import * as core from '../models/turtl/core';
2+
import delay from '../util/delay';
23
import Emitter from '../util/event';
34
import log from '../util/log';
45

56
const CoreAdapter = ((events) => {
6-
function event(data, error) {
7-
setTimeout(() => {
8-
const res_event = {
9-
d: data,
10-
e: error,
11-
};
12-
events.emit('message', JSON.stringify(res_event));
13-
});
14-
}
15-
167
const state = {
178
user: {
189
id: '01626b759c146c6f6b696da1b7e38fd92ff72c531689872a9da4e1b4cb7697b0636b15616a0f0017',
@@ -69,7 +60,7 @@ const CoreAdapter = ((events) => {
6960
color: '#408080',
7061
body: 'eyJXT1cgTVVIQyBTRUNVRVIiKQ==',
7162
}],
72-
pages: [{
63+
boards: [{
7364
id: '013e4c7a04286c8cf3cf96d4d489d14095b5937cbde319f57adabbc0ab24f3209bb63a3de800a9ce',
7465
space_id: '01626b759c146c6f634b027b1b69e1242d40d53e312b3b4ac7710f55be81f289b549446ef6778bee',
7566
user_id: '01626b759c146c6f6b696da1b7e38fd92ff72c531689872a9da4e1b4cb7697b0636b15616a0f0017',
@@ -78,17 +69,17 @@ const CoreAdapter = ((events) => {
7869
invites: [],
7970
};
8071

81-
function event(eventdata, error) {
72+
function event(name, eventdata) {
8273
const res_msg = {
83-
d: JSON.parse(JSON.stringify(eventdata)),
84-
e: !!error,
74+
e: name,
75+
d: typeof(eventdata) === 'undefined' ? eventdata : JSON.parse(JSON.stringify(eventdata)),
8576
};
8677
log.debug('CoreAdapter::mock::event() -- event: ', res_msg);
8778

8879
events.emit('message', JSON.stringify(res_msg));
8980
}
9081

91-
function send(msg) {
82+
async function send(msg) {
9283
const parsed = JSON.parse(msg);
9384
const [msg_id, cmd, ...args] = parsed;
9485
if(!cmd) {
@@ -119,6 +110,10 @@ const CoreAdapter = ((events) => {
119110
}
120111
break;
121112
case 'profile:load':
113+
await delay(1000);
114+
event('profile:loaded');
115+
await delay(2000);
116+
event('profile:indexed');
122117
response = state;
123118
break;
124119
case 'sync:start':
@@ -143,10 +138,8 @@ const CoreAdapter = ((events) => {
143138
events.emit('connected', true);
144139
});
145140

146-
return {
147-
...events,
148-
send,
149-
};
141+
events.send = send;
142+
return events;
150143
});
151144

152145
core.init(CoreAdapter(Emitter()));

src/locales/en_us.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const translation = {
1111
excellent: 'Excellent',
1212
good: 'Good',
1313
great: 'Great',
14+
indexing_notes: 'Indexing notes',
1415
loading_profile: 'Loading profile',
1516
login: 'Login',
1617
login_existing: 'Login to an existing account',

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import "./css/app.scss";
22
import App from "./App.svelte";
33
import user from './models/turtl/user';
44
import spaces from './models/turtl/spaces';
5-
import pages from './models/turtl/pages';
5+
import boards from './models/turtl/boards';
66
import invites from './models/turtl/invites';
77

88
// give us a window into the app
9-
window.turtl = { user, spaces, pages, invites };
9+
window.turtl = { user, spaces, boards, invites };
1010

1111
const app = new App({
1212
target: document.getElementById("app"),

src/models/turtl/boards.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { writable } from 'svelte/store';
2+
3+
const boards = writable([]);
4+
5+
export default boards;
6+

src/models/turtl/core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function init(core_adapter, options) {
5252
events.emit('error', {core: true, err: 'missing_handler', id});
5353
}
5454
} else {
55-
log.info(`core::event`);
55+
log.info(`core::event`, msg.e);
5656
events.emit('event', msg.e, msg.d);
5757
}
5858
});
@@ -79,7 +79,8 @@ export async function invoke(call, ...args) {
7979
}
8080
message_map[id] = {resolve, reject};
8181
log.info(`core::send(${call}) -- msg ${msg_id}`);
82-
adapter.send(JSON.stringify([id.toString(), call, ...args]));
82+
adapter.send(JSON.stringify([id.toString(), call, ...args]))
83+
.catch((err) => reject(err));
8384
});
8485
}
8586

src/models/turtl/pages.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/models/turtl/profile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { invoke } from './core';
22
import { config } from './config';
33
import user from './user';
44
import spaces from './spaces';
5-
import pages from './pages';
5+
import boards from './boards';
66
import invites from './invites';
77

88
export async function load_profile() {
99
await invoke('sync:start');
1010
const profile = await invoke('profile:load');
1111
spaces.set(profile.spaces);
12-
pages.set(profile.pages);
12+
boards.set(profile.boards);
1313
invites.set(profile.invites);
1414
}
1515

src/pages/Main.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import spaces from '../models/turtl/spaces';
66
import { procerr } from '../util/error';
77
import { loc } from '../util/i18n';
8+
import * as core from '../models/turtl/core';
89
910
set_meta(loc('loading_profile'));
1011
@@ -14,7 +15,12 @@
1415
async function load() {
1516
loading = true;
1617
push_log(loc('loading_profile'));
18+
const unbind = core.events.on('event', (ev) => {
19+
(ev === 'profile:loaded') && push_log(loc('indexing_notes'));
20+
});
1721
await load_profile();
22+
unbind();
23+
loading = false;
1824
}
1925
load();
2026
</script>

0 commit comments

Comments
 (0)