implemented sharing of bookmarks
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
import Editor from '../../Components/MarkdownEditor.svelte';
|
||||
import Users from '../../Components/UserSelector.svelte';
|
||||
import Tags from '../tags/TagList.svelte';
|
||||
import Template from './Template.svelte';
|
||||
|
||||
@@ -15,20 +16,36 @@
|
||||
rendered:null
|
||||
},
|
||||
tags:[],
|
||||
url:null
|
||||
url:null,
|
||||
users:{}
|
||||
});
|
||||
let error = $state(null);
|
||||
|
||||
async function getCandidates(text){
|
||||
const url = api('user/search');
|
||||
const resp = await fetch(url,{
|
||||
credentials : 'include',
|
||||
method : 'POST',
|
||||
body : text
|
||||
});
|
||||
if (resp.ok){
|
||||
error = null;
|
||||
const input = await resp.json();
|
||||
return Object.fromEntries(
|
||||
Object.entries(input).map(([key, value]) => [key, value.name])
|
||||
);
|
||||
} else {
|
||||
error = await resp.text();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function loadBookmarks(){
|
||||
const url = api('bookmark/list');
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
const raw = await resp.json();
|
||||
bookmarks = Object.values(raw)
|
||||
.sort(
|
||||
(a, b) => new Date(b.timestamp) - new Date(a.timestamp)
|
||||
);
|
||||
|
||||
bookmarks = Object.values(raw).sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));
|
||||
error = false;
|
||||
} else {
|
||||
error = await resp.html();
|
||||
@@ -37,12 +54,14 @@
|
||||
|
||||
async function onclick(ev){
|
||||
delete new_bookmark.comment.rendered;
|
||||
const url = api('bookmark/save');
|
||||
const url = api('bookmark');
|
||||
const data = {
|
||||
comment : new_bookmark.comment.source,
|
||||
url : new_bookmark.url,
|
||||
tags : new_bookmark.tags
|
||||
}
|
||||
const share = Object.keys(new_bookmark.users).map(id => +id);
|
||||
if (share.length>0) data.share = share;
|
||||
const resp = await fetch(url,{
|
||||
credentials : 'include',
|
||||
method : 'POST',
|
||||
@@ -66,17 +85,21 @@
|
||||
{/if}
|
||||
<label>
|
||||
{t('URL')}
|
||||
<input bind:value={new_bookmark.url} />
|
||||
<input bind:value={new_bookmark.url} autofocus />
|
||||
</label>
|
||||
<label>
|
||||
{t('Comment')}
|
||||
<Editor simple={true} bind:value={new_bookmark.comment} />
|
||||
</label>
|
||||
<label>
|
||||
{t('share_with')}
|
||||
<Users {getCandidates} users={new_bookmark.users} />
|
||||
</label>
|
||||
<Tags module="bookmark" bind:tags={new_bookmark.tags} />
|
||||
<button {onclick}>{t('save')}</button>
|
||||
{#if bookmarks}
|
||||
{#each bookmarks as bookmark}
|
||||
<Template {bookmark} />
|
||||
<Template {bookmark} />
|
||||
{/each}
|
||||
{/if}
|
||||
</fieldset>
|
||||
@@ -101,7 +101,7 @@
|
||||
|
||||
<div class="taglist">
|
||||
<span class="tag editor">
|
||||
<input type="text" bind:value={newTag} onkeyup={typed} autofocus />
|
||||
<input type="text" bind:value={newTag} onkeyup={typed} />
|
||||
</span>
|
||||
{#each tags as tag,idx}
|
||||
<span class="tag">
|
||||
@@ -109,4 +109,4 @@
|
||||
<button onclick={() => drop(tag)} class="symbol"></button>
|
||||
</span>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user