-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- by parsing them in enrichStatus - implementing a tag page to show their timeline resolves #345
- Loading branch information
1 parent
a97dbfa
commit a606e76
Showing
7 changed files
with
209 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
import { $, component$, Slot } from '@builder.io/qwik' | ||
import { useNavigate } from '@builder.io/qwik-city' | ||
|
||
export default component$<{ withBackButton?: boolean }>(({ withBackButton }) => { | ||
const nav = useNavigate() | ||
export default component$<{ withBackButton?: boolean; backButtonPlacement?: 'start' | 'end' }>( | ||
({ withBackButton, backButtonPlacement = 'start' }) => { | ||
const nav = useNavigate() | ||
|
||
const goBack = $(() => { | ||
if (window.history.length > 1) { | ||
window.history.back() | ||
} else { | ||
nav('/explore') | ||
} | ||
}) | ||
const goBack = $(() => { | ||
if (window.history.length > 1) { | ||
window.history.back() | ||
} else { | ||
nav('/explore') | ||
} | ||
}) | ||
|
||
return ( | ||
<header class="bg-wildebeest-900 sticky top-[3.9rem] xl:top-0 xl:pt-2.5 z-10"> | ||
<div class="flex bg-wildebeest-700 xl:rounded-t overflow-hidden"> | ||
{!!withBackButton && ( | ||
<div class="flex justify-between items-center bg-wildebeest-700"> | ||
<button class="text-semi no-underline text-wildebeest-vibrant-400 bg-transparent p-4" onClick$={goBack}> | ||
<i class="fa fa-chevron-left mr-2 w-3 inline-block" /> | ||
<span class="hover:underline">Back</span> | ||
</button> | ||
</div> | ||
)} | ||
<Slot /> | ||
const backButton = !withBackButton ? ( | ||
// eslint-disable-next-line qwik/single-jsx-root | ||
<></> | ||
) : ( | ||
<div class="flex justify-between items-center bg-wildebeest-700"> | ||
<button class="text-semi no-underline text-wildebeest-vibrant-400 bg-transparent p-4" onClick$={goBack}> | ||
<i class="fa fa-chevron-left mr-2 w-3 inline-block" /> | ||
<span class="hover:underline">Back</span> | ||
</button> | ||
</div> | ||
</header> | ||
) | ||
}) | ||
) | ||
return ( | ||
<header class="bg-wildebeest-900 sticky top-[3.9rem] xl:top-0 xl:pt-2.5 z-10"> | ||
<div class="flex bg-wildebeest-700 xl:rounded-t overflow-hidden"> | ||
{backButtonPlacement === 'start' && backButton} | ||
<Slot /> | ||
{backButtonPlacement === 'end' && <div class="ml-auto">{backButton}</div>} | ||
</div> | ||
</header> | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { $, component$ } from '@builder.io/qwik' | ||
import { DocumentHead, loader$ } from '@builder.io/qwik-city' | ||
import { getDatabase } from 'wildebeest/backend/src/database' | ||
import { getDomain } from 'wildebeest/backend/src/utils/getDomain' | ||
import { handleRequest } from 'wildebeest/functions/api/v1/timelines/tag/[tag]' | ||
import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel' | ||
import StickyHeader from '~/components/StickyHeader/StickyHeader' | ||
import { MastodonStatus } from '~/types' | ||
import { getDocumentHead } from '~/utils/getDocumentHead' | ||
|
||
export const loader = loader$<Promise<{ tag: string; statuses: MastodonStatus[] }>, { DATABASE: D1Database }>( | ||
async ({ request, platform, params }) => { | ||
const tag = params.tag | ||
const response = await handleRequest(await getDatabase(platform), request, getDomain(request.url), tag) | ||
const results = await response.text() | ||
const statuses: MastodonStatus[] = JSON.parse(results) | ||
return { tag, statuses } | ||
} | ||
) | ||
|
||
export default component$(() => { | ||
const loaderData = loader() | ||
|
||
return ( | ||
<> | ||
<div class="flex flex-col flex-1"> | ||
<StickyHeader withBackButton backButtonPlacement="end"> | ||
<h2 class="text-reg text-md m-0 p-4 flex bg-wildebeest-700"> | ||
<i class="fa fa-hashtag fa-fw mr-3 w-5 leading-tight inline-block" /> | ||
<span>{loaderData.value.tag}</span> | ||
</h2> | ||
</StickyHeader> | ||
<StatusesPanel | ||
initialStatuses={loaderData.value.statuses} | ||
fetchMoreStatuses={$(async (numOfCurrentStatuses: number) => { | ||
let statuses: MastodonStatus[] = [] | ||
try { | ||
const response = await fetch( | ||
`/api/v1/timelines/tags/${loaderData.value.tag}/?offset=${numOfCurrentStatuses}` | ||
) | ||
if (response.ok) { | ||
const results = await response.text() | ||
statuses = JSON.parse(results) | ||
} | ||
} catch { | ||
/* empty */ | ||
} | ||
return statuses | ||
})} | ||
/> | ||
</div> | ||
</> | ||
) | ||
}) | ||
|
||
export const requestUrlLoader = loader$(async ({ request }) => request.url) | ||
|
||
export const head: DocumentHead = ({ resolveValue }) => { | ||
const { tag } = resolveValue(loader) | ||
const url = resolveValue(requestUrlLoader) | ||
|
||
return getDocumentHead({ | ||
title: `#${tag} - Wildebeest`, | ||
description: `#${tag} tag page - Wildebeest`, | ||
og: { | ||
url, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters