forked from andyburke/autonomous.contact
refactor: switch how tabs work in an effort to make downstream stuff
easier
This commit is contained in:
parent
7c4649924e
commit
873773bc91
14 changed files with 846 additions and 947 deletions
|
|
@ -127,122 +127,120 @@
|
|||
}
|
||||
</style>
|
||||
|
||||
<div id="blurbs" class="tab">
|
||||
<input
|
||||
type="radio"
|
||||
name="top-level-tabs"
|
||||
id="blurb-tab-input"
|
||||
class="tab-switch"
|
||||
data-view="blurbs"
|
||||
/>
|
||||
<label for="blurb-tab-input" class="tab-label"
|
||||
><div class="icon blurb"></div>
|
||||
<div class="label">Blurbs</div>
|
||||
</label>
|
||||
<div class="tab-content">
|
||||
<div id="blurbs-container" class="container">
|
||||
<!-- #include "./README.md" -->
|
||||
<input
|
||||
type="radio"
|
||||
name="top-level-tabs"
|
||||
id="blurb-tab-input"
|
||||
class="tabswitch"
|
||||
data-view="blurbs"
|
||||
/>
|
||||
<label for="blurb-tab-input" class="tablabel"
|
||||
><div class="icon blurb"></div>
|
||||
<div class="label">Blurbs</div>
|
||||
</label>
|
||||
<div class="panel">
|
||||
<div id="blurbs-container" class="container">
|
||||
<!-- #include "./README.md" -->
|
||||
|
||||
<!-- #include "./new_blurb.html" -->
|
||||
<!-- #include "./new_blurb.html" -->
|
||||
|
||||
<div
|
||||
id="blurbs-list"
|
||||
data-feed
|
||||
data-precheck="!!document.body.dataset.user && document.body.dataset.user.indexOf( 'events.read.blurb' ) !== -1"
|
||||
data-source="/api/events?type=blurb,reaction&limit=100&sort=newest&wait=true&after_id=${ feed.__newest_id ?? 'able-able-able-able-able-able-able-able-able-able' }"
|
||||
data-longpolling="true"
|
||||
data-reverse="true"
|
||||
data-insert="prepend"
|
||||
data-autoscroll="true"
|
||||
>
|
||||
<script>
|
||||
{
|
||||
const feed = document.currentScript.closest("[data-feed]");
|
||||
<div
|
||||
id="blurbs-list"
|
||||
data-feed
|
||||
data-precheck="!!document.body.dataset.user && document.body.dataset.user.indexOf( 'events.read.blurb' ) !== -1"
|
||||
data-source="/api/events?type=blurb,reaction&limit=100&sort=newest&wait=true&after_id=${ feed.__newest_id ?? 'able-able-able-able-able-able-able-able-able-able' }"
|
||||
data-longpolling="true"
|
||||
data-reverse="true"
|
||||
data-insert="prepend"
|
||||
data-autoscroll="true"
|
||||
>
|
||||
<script>
|
||||
{
|
||||
const feed = document.currentScript.closest("[data-feed]");
|
||||
|
||||
APP.on("user_logged_in", () => { feed.__reset && feed.__reset(); });
|
||||
APP.on("user_logged_in", () => { feed.__reset && feed.__reset(); });
|
||||
|
||||
feed.__target_element = (item) => {
|
||||
return (
|
||||
document.querySelector(
|
||||
`.blurb-container[data-blurb_id='${item.parent_id}'] > .replies-container`,
|
||||
) ?? feed
|
||||
);
|
||||
feed.__target_element = (item) => {
|
||||
return (
|
||||
document.querySelector(
|
||||
`.blurb-container[data-blurb_id='${item.parent_id}'] > .replies-container`,
|
||||
) ?? feed
|
||||
);
|
||||
};
|
||||
feed.__target_element = (item) => {
|
||||
let target = feed;
|
||||
switch (item.type) {
|
||||
case "reaction":
|
||||
target = document.querySelector(
|
||||
`.blurb-container[data-event_id='${item.parent_id}'] > .reactions-container`,
|
||||
);
|
||||
break;
|
||||
case "blurb":
|
||||
default:
|
||||
target =
|
||||
document.querySelector(
|
||||
`.blurb-container[data-event_id='${item.parent_id}'] > .replies-container`,
|
||||
) ?? feed;
|
||||
break;
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
feed.__context = async (item) => {
|
||||
const blurb_datetime = datetime_to_local(item.timestamps.created);
|
||||
|
||||
return {
|
||||
event: item,
|
||||
blurb: item,
|
||||
creator: await APP.USERS.get(item.creator_id),
|
||||
blurb_datetime
|
||||
};
|
||||
feed.__target_element = (item) => {
|
||||
let target = feed;
|
||||
switch (item.type) {
|
||||
case "reaction":
|
||||
target = document.querySelector(
|
||||
`.blurb-container[data-event_id='${item.parent_id}'] > .reactions-container`,
|
||||
);
|
||||
break;
|
||||
case "blurb":
|
||||
default:
|
||||
target =
|
||||
document.querySelector(
|
||||
`.blurb-container[data-event_id='${item.parent_id}'] > .replies-container`,
|
||||
) ?? feed;
|
||||
break;
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
feed.__context = async (item) => {
|
||||
const blurb_datetime = datetime_to_local(item.timestamps.created);
|
||||
|
||||
return {
|
||||
event: item,
|
||||
blurb: item,
|
||||
creator: await APP.USERS.get(item.creator_id),
|
||||
blurb_datetime
|
||||
};
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<template data-for_type="blurb">
|
||||
<div
|
||||
id="${ context.blurb.id }"
|
||||
class="blurb-container"
|
||||
data-event_id="${context.blurb.id}"
|
||||
data-creator_id="${context.creator.id}"
|
||||
data-blurb_id="${context.blurb.id}"
|
||||
data-temp_id="${context.blurb.meta?.temp_id ?? ""}">
|
||||
<div class="media-preview-container">
|
||||
${context.blurb.data?.media?.length ? context.blurb.data.media.map(function(url) { return url ? `<img src='${url}' loading="lazy"/>` : ''; }).join('\n') : ''}
|
||||
</div>
|
||||
|
||||
<div class="info-container">
|
||||
<div class="avatar-container inline">
|
||||
<img src="${context.creator.meta?.avatar ?? '/images/default_avatar.gif'}" alt="user avatar" loading="lazy" />
|
||||
</div>
|
||||
<div class="username-container">
|
||||
<span class="username">${context.creator.username}</span>
|
||||
</div>
|
||||
<div class="datetime-container">
|
||||
<span class="long">${context.blurb_datetime.long}</span>
|
||||
<span class="short">${context.blurb_datetime.short}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-container">${htmlify(md_to_html(context.blurb.data.blurb))}</div>
|
||||
<div class="reactions-container"></div>
|
||||
<button class="icon more" commandfor="eventactionspopover"></button>
|
||||
<!-- #include "./new_blurb.html" -->
|
||||
<div class="replies-container"></div>
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<template data-for_type="blurb">
|
||||
<div
|
||||
id="${ context.blurb.id }"
|
||||
class="blurb-container"
|
||||
data-event_id="${context.blurb.id}"
|
||||
data-creator_id="${context.creator.id}"
|
||||
data-blurb_id="${context.blurb.id}"
|
||||
data-temp_id="${context.blurb.meta?.temp_id ?? ""}">
|
||||
<div class="media-preview-container">
|
||||
${context.blurb.data?.media?.length ? context.blurb.data.media.map(function(url) { return url ? `<img src='${url}' loading="lazy"/>` : ''; }).join('\n') : ''}
|
||||
</div>
|
||||
</template>
|
||||
<template data-for_type="reaction">
|
||||
<div
|
||||
id="${context.event.id}"
|
||||
class="reaction-container"
|
||||
data-event_id="${context.event.id}"
|
||||
data-creator_id="${context.creator.id}"
|
||||
data-temp_id="${context.event.meta?.temp_id ?? ''}"
|
||||
>
|
||||
<span class="reaction">${ context.event.data.reaction }</span>
|
||||
|
||||
<div class="info-container">
|
||||
<div class="avatar-container inline">
|
||||
<img src="${context.creator.meta?.avatar ?? '/images/default_avatar.gif'}" alt="user avatar" loading="lazy" />
|
||||
</div>
|
||||
<div class="username-container">
|
||||
<span class="username">${context.creator.username}</span>
|
||||
</div>
|
||||
<div class="datetime-container">
|
||||
<span class="long">${context.blurb_datetime.long}</span>
|
||||
<span class="short">${context.blurb_datetime.short}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="content-container">${htmlify(md_to_html(context.blurb.data.blurb))}</div>
|
||||
<div class="reactions-container"></div>
|
||||
<button class="icon more" commandfor="eventactionspopover"></button>
|
||||
<!-- #include "./new_blurb.html" -->
|
||||
<div class="replies-container"></div>
|
||||
</div>
|
||||
</template>
|
||||
<template data-for_type="reaction">
|
||||
<div
|
||||
id="${context.event.id}"
|
||||
class="reaction-container"
|
||||
data-event_id="${context.event.id}"
|
||||
data-creator_id="${context.creator.id}"
|
||||
data-temp_id="${context.event.meta?.temp_id ?? ''}"
|
||||
>
|
||||
<span class="reaction">${ context.event.data.reaction }</span>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue