Skip to content

Commit

Permalink
feat: winter 2024 high priority
Browse files Browse the repository at this point in the history
* fix: Japanese signedInAs text

* fix: replace new line for single enter

* feat: Suggest text length over

* feat: Read emoji in tweet

* fix: format
  • Loading branch information
cma2819 authored Dec 17, 2024
1 parent 931cc6e commit 4e8fbf3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions app/api/twitter.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ export const getTweets = async () => {
await Promise.all(
tweets.slice(0, 10).map(async (tweetElement) => {
const textElement = await tweetElement.$("div[data-testid=tweetText]");
const text = await textElement?.evaluate((el) => el.textContent);
const text = await textElement?.evaluate((el) => {
let text = "";
for (const element of Array.from(el.children)) {
const looksEmoji = element.tagName === "IMG";
text += looksEmoji
? element.getAttribute("alt")
: element.textContent;
}
return text;
});
const timeElement = await tweetElement.waitForSelector("time");
if (!timeElement) {
return;
Expand Down Expand Up @@ -218,7 +227,8 @@ export const tweet = async (text: string, files: string[]) => {
throw new Error("No tweet input label");
}
await input.click({ count: 3 });
await input.type(text);
const fixedText = text.replace(/\r\n|\r/, "\n");
await input.type(fixedText);

if (files.length >= 1) {
const fileInput = await page.waitForSelector("input[type=file]");
Expand Down
2 changes: 1 addition & 1 deletion app/i18next/translation/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tweetFinished": "ツイートしました",
"tweetFailed": "ツイートに失敗しました",
"submit": "送信",
"signedInAs": "{{account}}としてログイン中",
"signedInAs": "{{username}}としてログイン中",
"signOut": "ログアウト",
"delete": "削除",
"reply": "リプライ",
Expand Down
12 changes: 11 additions & 1 deletion app/routes/_index/tweet-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const videoFileTypes = ["video/mp4", "video/quicktime"];

const TweetTextInput = () => {
const [tweetLength, setTweetLength] = useState(0);
const suggestLengthOver = tweetLength > 280;

return (
<>
<TextArea
Expand All @@ -21,8 +23,16 @@ const TweetTextInput = () => {
setTweetLength(twitterText.getTweetLength(e.target.value));
}}
className={css({ height: "150px", width: "100%" })}
{...(suggestLengthOver ? { color: "red" } : {})}
/>
<div className={css({ justifySelf: "end" })}>{tweetLength}/280</div>
<div
className={css({
justifySelf: "end",
...(suggestLengthOver ? { color: "red" } : {}),
})}
>
{tweetLength}/280
</div>
</>
);
};
Expand Down

0 comments on commit 4e8fbf3

Please sign in to comment.