Skip to content

Commit

Permalink
pref: use slice instead of replace
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Oct 14, 2024
1 parent d4db563 commit 485d2d5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/renderer/src/constants/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const ROUTE_FEED_IN_INBOX = "inbox-"

export const DAILY_CLAIM_AMOUNT = "20"
export const INVITATION_PRICE = "100"

export const INBOX_PREFIX_ID = "inbox-"
5 changes: 4 additions & 1 deletion apps/renderer/src/lib/route-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function nestPaths(paths: string[]): NestedStructure {

paths.forEach((path) => {
// Remove the './pages' prefix and the '.tsx' suffix
const trimmedPath = path.replace("./pages/", "").replace(".tsx", "")
const prefix = "./pages/"
const suffix = ".tsx"
const trimmedPath = path.slice(prefix.length, -suffix.length)

const parts = trimmedPath.split("/")

let currentLevel = result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function ListItem({
const isSubscription =
withFollow && entry?.entries.url?.startsWith(UrlBuilder.shareFeed(entry.feedId))
const feedId = isSubscription
? entry?.entries.url?.replace(UrlBuilder.shareFeed(entry.feedId), "")
? entry?.entries.url?.slice(UrlBuilder.shareFeed(entry.feedId).length)
: undefined
const isFollowed = !!useSubscriptionStore((state) => feedId && state.data[feedId])
const { present } = useModalStack()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fragment } from "react"

import { INBOX_PREFIX_ID } from "~/constants"
import { sortByAlphabet } from "~/lib/utils"
import { getPreferredTitle, useFeedStore } from "~/store/feed"
import { getSubscriptionByFeedId } from "~/store/subscription"
Expand Down Expand Up @@ -76,7 +77,13 @@ export const SortByAlphabeticalInboxList = ({ view, data }: ListListProps) => {
return (
<div>
{Object.keys(data).map((feedId) => (
<InboxItem key={feedId} inboxId={feedId.replace("inbox-", "")} view={view} />
<InboxItem
key={feedId}
inboxId={
feedId.startsWith(INBOX_PREFIX_ID) ? feedId.slice(INBOX_PREFIX_ID.length) : feedId
}
view={view}
/>
))}
</div>
)
Expand Down
11 changes: 10 additions & 1 deletion apps/renderer/src/modules/settings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ function getSettings() {
loader: () => SettingPageConfig
}[]
for (const path in map) {
const p = path.split("/").pop()?.replace(".tsx", "").replace("(settings)", "")!
const prefix = "(settings)"
const postfix = ".tsx"
const lastItem = path.split("/").pop()

if (!lastItem) continue
let p = lastItem.slice(0, -postfix.length)

if (p.includes(prefix)) {
p = p.replace(prefix, "")
}

if (p === "index" || p === "layout") continue

Expand Down

0 comments on commit 485d2d5

Please sign in to comment.