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,130 +127,128 @@
|
|||
}
|
||||
</style>
|
||||
|
||||
<div id="forum" class="tab">
|
||||
<input
|
||||
type="radio"
|
||||
name="top-level-tabs"
|
||||
id="forum-tab-input"
|
||||
class="tab-switch"
|
||||
data-view="forum"
|
||||
/>
|
||||
<label for="forum-tab-input" class="tab-label"
|
||||
><div class="icon forum"></div>
|
||||
<div class="label">Forum</div></label
|
||||
<input
|
||||
type="radio"
|
||||
name="top-level-tabs"
|
||||
id="forum-tab-input"
|
||||
class="tabswitch"
|
||||
data-view="forum"
|
||||
/>
|
||||
<label for="forum-tab-input" class="tablabel"
|
||||
><div class="icon forum"></div>
|
||||
<div class="label">Forum</div></label
|
||||
>
|
||||
<div class="panel forum-container">
|
||||
<!-- #include "./README.md" -->
|
||||
|
||||
<div
|
||||
id="posts-list"
|
||||
data-feed
|
||||
data-precheck="!!document.body.dataset.user && document.body.dataset.user.indexOf( 'events.read.post' ) !== -1"
|
||||
data-source="/api/events?type=post,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"
|
||||
>
|
||||
<div class="tab-content forum-container">
|
||||
<!-- #include "./README.md" -->
|
||||
<script>
|
||||
{
|
||||
const feed = document.currentScript.closest("[data-feed]");
|
||||
|
||||
<div
|
||||
id="posts-list"
|
||||
data-feed
|
||||
data-precheck="!!document.body.dataset.user && document.body.dataset.user.indexOf( 'events.read.post' ) !== -1"
|
||||
data-source="/api/events?type=post,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) => {
|
||||
let target = feed;
|
||||
switch (item.type) {
|
||||
case "reaction":
|
||||
target = document.querySelector(
|
||||
`.post-container[data-event_id='${item.parent_id}'] > .reactions-container`,
|
||||
);
|
||||
break;
|
||||
case "chat":
|
||||
default:
|
||||
target =
|
||||
document.querySelector(
|
||||
`.post-container[data-event_id='${item.parent_id}'] > .replies-container`,
|
||||
) ?? feed;
|
||||
break;
|
||||
}
|
||||
|
||||
feed.__target_element = (item) => {
|
||||
let target = feed;
|
||||
switch (item.type) {
|
||||
case "reaction":
|
||||
target = document.querySelector(
|
||||
`.post-container[data-event_id='${item.parent_id}'] > .reactions-container`,
|
||||
);
|
||||
break;
|
||||
case "chat":
|
||||
default:
|
||||
target =
|
||||
document.querySelector(
|
||||
`.post-container[data-event_id='${item.parent_id}'] > .replies-container`,
|
||||
) ?? feed;
|
||||
break;
|
||||
}
|
||||
return target;
|
||||
};
|
||||
|
||||
return target;
|
||||
feed.__context = async (item) => {
|
||||
const post_datetime = datetime_to_local(item.timestamps.created);
|
||||
|
||||
return {
|
||||
event: item,
|
||||
post: item,
|
||||
creator: await APP.USERS.get(item.creator_id),
|
||||
post_datetime,
|
||||
};
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<template data-for_type="post">
|
||||
<div
|
||||
id="${context.post.id}"
|
||||
class="post-container"
|
||||
data-event_id="${context.post.id}"
|
||||
data-creator_id="${context.creator.id}"
|
||||
data-post_id="${context.post.id}"
|
||||
>
|
||||
<div class="expand-toggle-container">
|
||||
<label>
|
||||
<input type="checkbox" name="expanded" /><i class="icon plus"></i
|
||||
><i class="icon minus"></i>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
feed.__context = async (item) => {
|
||||
const post_datetime = datetime_to_local(item.timestamps.created);
|
||||
<div class="media-preview-container">
|
||||
<img
|
||||
src="/images/placeholders/${String((context.post_datetime.ms % 9) + 1).padStart(2, '0')}.svg"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
|
||||
return {
|
||||
event: item,
|
||||
post: item,
|
||||
creator: await APP.USERS.get(item.creator_id),
|
||||
post_datetime,
|
||||
};
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<template data-for_type="post">
|
||||
<div
|
||||
id="${context.post.id}"
|
||||
class="post-container"
|
||||
data-event_id="${context.post.id}"
|
||||
data-creator_id="${context.creator.id}"
|
||||
data-post_id="${context.post.id}"
|
||||
>
|
||||
<div class="expand-toggle-container">
|
||||
<label>
|
||||
<input type="checkbox" name="expanded" /><i class="icon plus"></i
|
||||
><i class="icon minus"></i>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="media-preview-container">
|
||||
<div class="info-container">
|
||||
<div class="avatar-container inline">
|
||||
<img
|
||||
src="/images/placeholders/${String((context.post_datetime.ms % 9) + 1).padStart(2, '0')}.svg"
|
||||
src="${context.creator.meta?.avatar ?? '/images/default_avatar.gif'}"
|
||||
alt="user avatar"
|
||||
loading="lazy"
|
||||
/>
|
||||
</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.post_datetime.long}</span>
|
||||
<span class="short">${context.post_datetime.short}</span>
|
||||
</div>
|
||||
<div class="username-container">
|
||||
<span class="username">${context.creator.username}</span>
|
||||
</div>
|
||||
<div class="subject-container">${context.post.data.subject}</div>
|
||||
<div class="content-container">
|
||||
${htmlify(md_to_html(context.post.data.content))}
|
||||
<div class="datetime-container">
|
||||
<span class="long">${context.post_datetime.long}</span>
|
||||
<span class="short">${context.post_datetime.short}</span>
|
||||
</div>
|
||||
<div class="reactions-container"></div>
|
||||
<button class="icon more" commandfor="eventactionspopover"></button>
|
||||
<!-- #include "./new_post.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 class="subject-container">${context.post.data.subject}</div>
|
||||
<div class="content-container">
|
||||
${htmlify(md_to_html(context.post.data.content))}
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- #include "./new_post.html" -->
|
||||
<div class="reactions-container"></div>
|
||||
<button class="icon more" commandfor="eventactionspopover"></button>
|
||||
<!-- #include "./new_post.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>
|
||||
|
||||
<!-- #include "./new_post.html" -->
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue