note tab
This commit is contained in:
@@ -21,7 +21,7 @@ export function setCurrentLang(lang: string): void {
|
|||||||
localStorage.setItem('preferred-lang', lang)
|
localStorage.setItem('preferred-lang', lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderModeTabs(handle: string, activeTab: 'blog' | 'browser' | 'post' | 'chat' | 'link' | 'note' = 'blog', isLocalUser: boolean = false): string {
|
export function renderModeTabs(handle: string, activeTab: 'blog' | 'browser' | 'post' | 'chat' | 'link' | 'note' = 'blog', isLocalUser: boolean = false, hasNotes: boolean = false): string {
|
||||||
let tabs = `
|
let tabs = `
|
||||||
<a href="/" class="tab">/</a>
|
<a href="/" class="tab">/</a>
|
||||||
<a href="/@${handle}" class="tab ${activeTab === 'blog' ? 'active' : ''}">${handle}</a>
|
<a href="/@${handle}" class="tab ${activeTab === 'blog' ? 'active' : ''}">${handle}</a>
|
||||||
@@ -33,8 +33,8 @@ export function renderModeTabs(handle: string, activeTab: 'blog' | 'browser' | '
|
|||||||
tabs += `<a href="/@${handle}/at/chat" class="tab ${activeTab === 'chat' ? 'active' : ''}">chat</a>`
|
tabs += `<a href="/@${handle}/at/chat" class="tab ${activeTab === 'chat' ? 'active' : ''}">chat</a>`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note tab only for local user (admin)
|
// Note tab only for local user (admin) with note posts
|
||||||
if (isLocalUser) {
|
if (isLocalUser && hasNotes) {
|
||||||
tabs += `<a href="/@${handle}/at/note" class="tab ${activeTab === 'note' ? 'active' : ''}">note</a>`
|
tabs += `<a href="/@${handle}/at/note" class="tab ${activeTab === 'note' ? 'active' : ''}">note</a>`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,9 @@ async function render(route: Route): Promise<void> {
|
|||||||
route.type === 'link' ? 'link' :
|
route.type === 'link' ? 'link' :
|
||||||
(route.type === 'note' || route.type === 'note-detail') ? 'note' :
|
(route.type === 'note' || route.type === 'note-detail') ? 'note' :
|
||||||
(route.type === 'atbrowser' || route.type === 'service' || route.type === 'collection' || route.type === 'record' ? 'browser' : 'blog')
|
(route.type === 'atbrowser' || route.type === 'service' || route.type === 'collection' || route.type === 'record' ? 'browser' : 'blog')
|
||||||
html += renderModeTabs(handle, activeTab, localOnly)
|
const noteCollection = 'ai.syui.note.post'
|
||||||
|
const notePosts = localOnly ? await getPosts(did, noteCollection, true) : []
|
||||||
|
html += renderModeTabs(handle, activeTab, localOnly, notePosts.length > 0)
|
||||||
|
|
||||||
// Check if logged-in user owns this content
|
// Check if logged-in user owns this content
|
||||||
const loggedInDid = getLoggedInDid()
|
const loggedInDid = getLoggedInDid()
|
||||||
@@ -293,15 +295,12 @@ async function render(route: Route): Promise<void> {
|
|||||||
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
||||||
|
|
||||||
} else if (route.type === 'note') {
|
} else if (route.type === 'note') {
|
||||||
// Note list page
|
// Note list page (reuse notePosts from above)
|
||||||
const noteCollection = 'ai.syui.note.post'
|
|
||||||
const notePosts = await getPosts(did, noteCollection, localOnly)
|
|
||||||
html += `<div id="content">${renderNoteListPage(notePosts, handle)}</div>`
|
html += `<div id="content">${renderNoteListPage(notePosts, handle)}</div>`
|
||||||
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
html += `<nav class="back-nav"><a href="/@${handle}">${handle}</a></nav>`
|
||||||
|
|
||||||
} else if (route.type === 'note-detail' && route.rkey) {
|
} else if (route.type === 'note-detail' && route.rkey) {
|
||||||
// Note detail page
|
// Note detail page
|
||||||
const noteCollection = 'ai.syui.note.post'
|
|
||||||
const notePost = await getPost(did, noteCollection, route.rkey, localOnly)
|
const notePost = await getPost(did, noteCollection, route.rkey, localOnly)
|
||||||
if (notePost) {
|
if (notePost) {
|
||||||
html += `<div id="content">${renderNoteDetailPage(notePost, handle, localOnly)}</div>`
|
html += `<div id="content">${renderNoteDetailPage(notePost, handle, localOnly)}</div>`
|
||||||
@@ -486,7 +485,6 @@ async function render(route: Route): Promise<void> {
|
|||||||
|
|
||||||
// Setup note detail page
|
// Setup note detail page
|
||||||
if (route.type === 'note-detail' && route.rkey) {
|
if (route.type === 'note-detail' && route.rkey) {
|
||||||
const noteCollection = 'ai.syui.note.post'
|
|
||||||
const notePost = await getPost(did, noteCollection, route.rkey, localOnly)
|
const notePost = await getPost(did, noteCollection, route.rkey, localOnly)
|
||||||
if (notePost && localOnly) {
|
if (notePost && localOnly) {
|
||||||
setupNoteDetail(notePost)
|
setupNoteDetail(notePost)
|
||||||
|
|||||||
Reference in New Issue
Block a user