Skip to content

Commit

Permalink
🐛 Fix networking and styling issues in home page
Browse files Browse the repository at this point in the history
  • Loading branch information
toridoriv committed Oct 18, 2023
1 parent 34ff406 commit 2aa13c0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
6 changes: 5 additions & 1 deletion components/fanfiction-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export function FanfictionCard({ fanfiction, ...props }: FanfictionCardProps) {
"card-text translation text-secondary-emphasis text-opacity-75",
},
})}
{tags.map(TagButton)}
</div>
<div class="card-footer">
<p style="text-align:center;">
{tags.map(TagButton)}
</p>
</div>
</article>
);
Expand Down
31 changes: 16 additions & 15 deletions routes/api/fanfiction-attributes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ListQuerySchema = z.object({
order: z.enum(["ASCENDING", "DESCENDING"]).default("ASCENDING"),
});

export const handler: Handlers<FanfictionAttributesOutput | null> = {
export const handler: Required<Pick<Handlers, "GET">> = {
async GET(req, _ctx) {
const url = new URL(req.url);
const query = ListQuerySchema.parse(
Expand All @@ -19,20 +19,21 @@ export const handler: Handlers<FanfictionAttributesOutput | null> = {
? { $expr: { $gt: ["$updated_at", "$created_at"] } }
: {};

const fanfictions = await client.fanfictions.find(dbQuery, {
projection: {
_id: 0,
created_at: 0,
updated_at: 0,
kind: 0,
chapters: 0,
},
limit: query.limit,
skip: query.skip,
sort: {
[query.sort]: SortOrder[query.order],
},
})
const fanfictions = await client.fanfictions
.find(dbQuery, {
projection: {
_id: 0,
created_at: 0,
updated_at: 0,
kind: 0,
chapters: 0,
},
limit: query.limit,
skip: query.skip,
sort: {
[query.sort]: SortOrder[query.order],
},
})
.toArray();

return new Response(JSON.stringify(fanfictions), {
Expand Down
32 changes: 21 additions & 11 deletions routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { FanfictionCard } from "@components/fanfiction-card.tsx";
import { FanfictionAttributesOutput } from "@modules/fanfiction/mod.ts";
import { logger } from "@utils/mod.ts";
import { handler as FanfictionAttributesHandler } from "./api/fanfiction-attributes/index.ts";

interface HomeState {
type HomeState = {
subtitle: string;
}
};

interface HomeData {
recentlyAdded: FanfictionAttributesOutput[];
Expand All @@ -15,18 +15,28 @@ interface HomeData {
export const handler: Handlers<HomeData, HomeState> = {
async GET(req, ctx) {
const baseUrl = new URL(req.url);
const recentlyAddedUrl = new URL(
"/api/fanfiction-attributes?limit=3&sort=created_at&order=DESCENDING",
baseUrl.origin,
const recentlyAddedRequest = new Request(
new URL(
"/api/fanfiction-attributes?limit=3&sort=created_at&order=DESCENDING",
baseUrl.origin,
),
);
const recentlyAddedResponse = await FanfictionAttributesHandler.GET(
recentlyAddedRequest,
ctx,
);
const recentlyAddedResponse = await fetch(recentlyAddedUrl);
const recentlyAdded = await recentlyAddedResponse.json();

const recentlyUpdatedUrl = new URL(
"/api/fanfiction-attributes?limit=3&sort=updated_at&order=DESCENDING",
baseUrl.origin,
const recentlyUpdatedRequest = new Request(
new URL(
"/api/fanfiction-attributes?limit=3&sort=updated_at&order=DESCENDING",
baseUrl.origin,
),
);
const recentlyUpdatedResponse = await FanfictionAttributesHandler.GET(
recentlyUpdatedRequest,
ctx,
);
const recentlyUpdatedResponse = await fetch(recentlyUpdatedUrl);
const recentlyUpdated = await recentlyUpdatedResponse.json();

ctx.state.subtitle = "Home";
Expand Down
4 changes: 3 additions & 1 deletion static/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ article.card {
font-family: "Victor Mono", Monaco, Lucida, monospace;
font-size: smaller;
margin-right: 0.6em;
margin-bottom: 0.2em;
margin-top: 0.2em;
}

.btn.tag.counter {
Expand All @@ -47,4 +49,4 @@ article.card {

span[lang] {
margin-right: 0.6em;
}
}
6 changes: 4 additions & 2 deletions utils/helpers/fanfiction-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function getRelationshipTag(
): FanfictionTag {
return getTag(
FanfictionTagName.Relationship,
relationship.replaceAll("/", ","),
relationship,
total,
);
}
Expand All @@ -97,5 +97,7 @@ export function getAuthorTag(authorName: string, total?: number) {
}

function getTagHref(name: FanfictionTagName, value: string) {
return `/catalog?${QUERY_BY_TAG_NAME[name]}${value.replaceAll(" ", "%20")}`;
return `/catalog?${QUERY_BY_TAG_NAME[name]}${
value.replaceAll("/", ",").replaceAll(" ", "%20")
}`;
}

0 comments on commit 2aa13c0

Please sign in to comment.