Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update macrumors extension #16707

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions/macrumors/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# MacRumors Changelog

## [Various Improvements] - 2025-01-31

* Updated date and time formatting
* Streamlined code base

## [Initial Version] - 2025-01-29

Initial version code
3 changes: 3 additions & 0 deletions extensions/macrumors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"description": "Browse MacRumors headlines from the comfort of Raycast.",
"icon": "macrumors-extension-icon.png",
"author": "hughmcmillanv",
"contributors": [
"pernielsentikaer"
],
"categories": [
"News"
],
Expand Down
46 changes: 12 additions & 34 deletions extensions/macrumors/src/macrumors.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,32 @@
import { Action, ActionPanel, List, showToast, Toast } from "@raycast/api";
import { useEffect, useState } from "react";
import Parser from "rss-parser";
import { State } from "./types";
import { Action, ActionPanel, List } from "@raycast/api";
import { useCachedPromise } from "@raycast/utils";
import { getIcon, getPubDate } from "./utils";

const parser = new Parser();
import Parser from "rss-parser";

export default function Command() {
const [state, setState] = useState<State>({});

useEffect(() => {
async function fetchStories() {
try {
const feed = await parser.parseURL("https://feeds.macrumors.com/MacRumors-All");
setState({ items: feed.items });
} catch (error) {
setState({
error: error instanceof Error ? error : new Error("Something went wrong."),
});
}
}

fetchStories();
}, []);

if (state.error) {
showToast({
style: Toast.Style.Failure,
title: "Failed loading stories.",
message: state.error.message,
});
}
const { data, isLoading } = useCachedPromise(async () => {
const parser = new Parser();
const feed = await parser.parseURL("https://feeds.macrumors.com/MacRumors-All");
return { items: feed.items };
});

return (
<List isLoading={!state.items && !state.error}>
{state.items?.map((item, index) => <StoryListItem key={item.guid} item={item} index={index} />)}
<List isLoading={isLoading}>
{data?.items?.map((item, index) => <StoryListItem key={item.guid} item={item} index={index} />)}
</List>
);
}

function StoryListItem(props: { item: Parser.Item; index: number }) {
const icon = getIcon(props.index + 1);
const pubDate = getPubDate(props.item);
const pubDate = new Date(getPubDate(props.item) ?? "");

return (
<List.Item
icon={icon}
title={props.item.title ?? "No title"}
subtitle={props.item.creator ?? "No author"}
accessories={[{ text: pubDate ?? "No date" }]}
accessories={[{ date: pubDate }]}
actions={<Actions item={props.item} />}
/>
);
Expand Down
6 changes: 0 additions & 6 deletions extensions/macrumors/src/types.ts

This file was deleted.