Skip to content

Commit d690c8a

Browse files
Big update
probably too much to itemize truly, but can't be bothered to track everything while i'm debuilding the foundations and crap. - adding `page_id` context to pages. allows child components to get the current page id, which is now required for `set_meta()` calls. before, set_meta() would modify the current page, but we cannot assume the current page is the one we're updating the title for. hence, page_id. - adding contexts to shortcuts. this lets us activate keyboard shortcuts in, well, certain contexts. the main one we're using is pages: each page creates its own context based off its id, which while components can now query, see above. this lets us only activate keyboard shortcuts when the page they are set up on is active. - adding Icon component, which lets us use named icons instead of the ugly  html entities. - adding more icons to icon font. - implementing Action component, floating action button. - implementing Space component that loads a note list and opens note editor. - updating turtl models and the way they're created. - ripping out logging libs and using hand-rolled one. ulog just wasn't listening and i got sick of it.
1 parent e865759 commit d690c8a

33 files changed

+681
-130
lines changed

package-lock.json

Lines changed: 11 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
"vite": "^3.0.7"
3434
},
3535
"dependencies": {
36-
"anylogger": "^1.0.11",
37-
"i18next": "^21.9.1",
38-
"ulog": "^2.0.0-beta.19"
36+
"i18next": "^21.9.1"
3937
}
4038
}

src/App.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
import Header from './components/Header.svelte';
3+
import Page from './components/util/Page.svelte';
34
import Main from './components/pages/Main.svelte';
45
import Login from './components/pages/Login.svelte';
56
import Err from './components/pages/Error.svelte';
@@ -10,7 +11,7 @@
1011
import config from './models/turtl/config';
1112
import darkmode from './models/darkmode';
1213
import { procerr } from './util/error';
13-
import log from './util/log';
14+
import { ui as log } from './util/log';
1415
import delay from './util/delay';
1516
import { init as i18n_init, loc } from './util/i18n';
1617
import * as shortcuts from './util/shortcuts';
@@ -84,9 +85,11 @@
8485
<main class="h-screen">
8586
<Header />
8687
<div class="absolute top-12 bottom-0 left-0 right-0">
87-
{#each $pages as {component, params, animate}}
88+
{#each $pages as {id, component, params, animate}}
8889
<div transition:page_animate="{{animate, x: 500, opacity: 0.1}}" class="page absolute left-0 right-0 top-0 bottom-0 overflow-auto p-8 bg-white dark:bg-black z-40">
89-
<svelte:component this={component} {...params}/>
90+
<Page page_id={id}>
91+
<svelte:component this={component} {...params}/>
92+
</Page>
9093
</div>
9194
{/each}
9295
</div>

src/adapters/core/mock.js

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from '@/models/turtl/core';
22
import delay from '@/util/delay';
33
import Emitter from '@/util/event';
4-
import log from '@/util/log';
4+
import { core as log } from '@/util/log';
55

66
const CoreAdapter = ((events) => {
77
const state = {
@@ -67,6 +67,17 @@ const CoreAdapter = ((events) => {
6767
title: 'Bookmarks',
6868
}],
6969
invites: [],
70+
notes: [{
71+
id: '01665e7122136f3cb9f271cb9a3596ab75f9ca3d3d90fd7188222222222222225d4efada9ac8f529',
72+
space_id: '01665e7122136f3cb9f271cb9a3596ab75f9ca3d3d90fd71882c89a06a244ec25d4efada9ac8f529',
73+
user_id: '01626b759c146c6f6b696da1b7e38fd92ff72c531689872a9da4e1b4cb7697b0636b15616a0f0017',
74+
has_file: false,
75+
mod: new Date('2014-08-13T00:45:12.000Z').getTime(),
76+
type: 'text',
77+
title: 'Business things',
78+
tags: ['business', 'company'],
79+
text: `# Meeting notes\n\n- Talked to Drew about getting 50% of the company. Sounds good.\n- Wrote a 50 page document nobody read.\n- Saw a mourning dove out the office window. It laid egg on the windowsill, but a jay at them. The dove blamed me.\n`,
80+
}],
7081
};
7182

7283
function event(name, eventdata) {
@@ -93,6 +104,89 @@ const CoreAdapter = ((events) => {
93104
response = {};
94105
break;
95106
}
107+
case 'profile:find-notes': {
108+
const search = args[0];
109+
const text = search.text;
110+
const note_ids = search.notes;
111+
const space_id = search.space_id;
112+
const board_ids = search.boards;
113+
const tags = search.tags;
114+
const exclude_tags = search.exclude_tags;
115+
const type = search.type;
116+
const url = search.url;
117+
const has_file = search.has_file;
118+
const sort = search.sort;
119+
const sort_direction = search.sort_direction;
120+
const page = search.page || 1;
121+
const per_page = search.per_page || 50;
122+
let notes = state.notes;
123+
if(text) {
124+
notes = notes.filter((note) => {
125+
note.title.substr(text) >= 0 ||
126+
note.text.substr(text) >= 0 ||
127+
note.tags.reduce((acc, t) => acc || t.substr(text) >= 0, false);
128+
});
129+
}
130+
if(note_ids) {
131+
notes = notes.filter((note) => note_ids.indexOf(note.id) >= 0);
132+
}
133+
if(space_id) {
134+
notes = notes.filter((note) => note.space_id === space_id);
135+
}
136+
if(board_ids) {
137+
notes = notes.filter((note) => board_ids.indexOf(note.board_id) >= 0);
138+
}
139+
if(tags) {
140+
notes = notes.filter((note) => {
141+
return tags.reduce((acc, t) => {
142+
return acc && note.tags.indexOf(t) >= 0;
143+
}, true);
144+
});
145+
}
146+
if(exclude_tags) {
147+
notes = notes.filter((note) => {
148+
return !exclude_tags.reduce((acc, x) => {
149+
return acc || note.tags.indexOf(x) >= 0;
150+
}, false);
151+
});
152+
}
153+
if(type) {
154+
notes = notes.filter((note) => note.type === type);
155+
}
156+
if(url) {
157+
notes = notes.filter((note) => note.url === url);
158+
}
159+
if(has_file) {
160+
notes = notes.filter((note) => note.has_file);
161+
}
162+
notes = notes.sort((a, b) => {
163+
const [x, y] = sort_direction.toLowerCase().trim() === 'desc' ?
164+
[b, a] :
165+
[a, b];
166+
if(typeof(a[sort]) === 'string') {
167+
return x[sort].localeCompare(y[sort]);
168+
} else {
169+
return x[sort] < y[sort];
170+
}
171+
});
172+
const offset = (Math.max(page, 0) - 1) * Math.max(per_page, 1);
173+
const total = notes.length;
174+
const tags_idx = notes.reduce((acc, x) => {
175+
x.tags.forEach((t) => {
176+
if(!acc[t]) acc[t] = 0;
177+
acc[t]++;
178+
});
179+
return acc;
180+
}, {});
181+
const note_tags = Object.keys(tags_idx).map((k) => [k, tags_idx[k]]);
182+
notes = notes.slice(offset, offset + per_page);
183+
response = {
184+
notes,
185+
tags: note_tags,
186+
total,
187+
};
188+
break;
189+
}
96190
case 'profile:load': {
97191
await delay(500);
98192
event('profile:loaded');
@@ -115,7 +209,7 @@ const CoreAdapter = ((events) => {
115209
break;
116210
}
117211
case 'user:login-from-saved': {
118-
const [user_id, key] = args;
212+
const [_user_id, key] = args;
119213
const decoded = JSON.parse(key);
120214
if(decoded.u === state.user.username && decoded.p === state.user.password) {
121215
state.user.loggedin = true;

src/assets/fonts/icons.woff2

2.28 KB
Binary file not shown.

src/components/Header.svelte

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import Menu from './util/Menu.svelte';
33
import { pages, pop_page } from '../models/pages';
44
import user from '../models/turtl/user';
5+
import Icon from './util/Icon.svelte';
56
67
function back(e) {
78
e.preventDefault();
@@ -20,22 +21,30 @@
2021
$: headerclass = opts.hide ?
2122
'bg-white dark:bg-black text-black dark:text-white' :
2223
'bg-slate-800 dark:bg-black text-white';
24+
$: space_shade = opts.space && opts.space.color.shade === 'light' ?
25+
'text-white' :
26+
'text-black';
2327
</script>
2428

2529
<header class="relative h-12 flex items-center justify-between px-3 {headerclass} z-50">
2630
{#if $pages.length > 1}
2731
<a href="#back" on:click={back} class="flex items-center">
28-
<icon class="text-primary">&#xE801;</icon>
32+
<Icon class="text-primary" name="arrow" />
2933
{#if !opts.hide}
3034
<h1 class="font-mono font-bold ml-4 mt-1">{curpage.title || '(untitled)'}</h1>
3135
{/if}
3236
</a>
3337
{:else}
3438
<a href="#sidebar" on:click={toggle_sidebar} class="flex items-center">
3539
{#if $user.loggedin}
36-
<icon class="text-primary text-xl relative">&#xF0C9;</icon>
40+
<Icon class="text-primary text-xl relative" name="hamburger" />
3741
{/if}
3842
{#if !opts.hide}
43+
{#if opts.space}
44+
<div class="px-2 py-0.5 ml-4 rounded-md {space_shade}" style="background-color: {opts.space.color.bg};">
45+
{opts.space.title}
46+
</div>
47+
{/if}
3948
<h1 class="font-mono font-bold ml-4 mt-1">{curpage.title || '(untitled)'}</h1>
4049
{/if}
4150
</a>

src/components/form/Button.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
import { createEventDispatcher } from 'svelte';
3+
import Icon from '../util/Icon.svelte';
34
export let label;
45
let klass = '';
56
export { klass as class };
@@ -32,7 +33,7 @@
3233
type={submit ? 'submit' : 'button'}
3334
tabindex={tabindex || null}>
3435
{#if icon}
35-
<icon class="text-xl pr-2 {icon_class || ''}">{icon}</icon>
36+
<Icon class="text-xl pr-2 {icon_class || ''}" name={icon} />
3637
{/if}
3738
<div class="relative">{label}</div>
3839
</button>

src/components/form/Input.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script>
22
import { createEventDispatcher } from 'svelte';
33
import { inc } from '@/models/counter';
4+
import Icon from '../util/Icon.svelte';
5+
46
export let name;
57
export let label;
68
export let type = 'text';
@@ -81,7 +83,7 @@
8183
<div class="relative {container_padding_class} bg-slate-200/50 dark:bg-slate-600/50">
8284
{#if icon}
8385
<div class="absolute z-0 top-0 bottom-0 left-0 ml-4 flex items-center {icon_class || ''}">
84-
<icon class="text-xl">{icon}</icon>
86+
<Icon class="text-xl" name={icon} />
8587
</div>
8688
{/if}
8789
<!-- lovely duplication here. again, https://github.com/sveltejs/svelte/issues/7566 -->
@@ -104,7 +106,7 @@
104106
</label>
105107
{#if icon_trailing}
106108
<div on:click={icon_trailing_click} class="absolute z-10 top-0 bottom-0 right-0 mr-4 flex items-center {icon_trailing_class || ''}">
107-
<icon class="text-xl">{icon_trailing}</icon>
109+
<Icon class="text-xl" name={icon_trailing} />
108110
</div>
109111
{/if}
110112
</div>

0 commit comments

Comments
 (0)