add error message

This commit is contained in:
kawamataryo 2024-11-07 07:56:58 +09:00
parent 9be889413c
commit ea084af712
5 changed files with 24 additions and 25 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "sky-follower-bridge", "name": "sky-follower-bridge",
"displayName": "Sky Follower Bridge", "displayName": "Sky Follower Bridge",
"version": "1.0.1", "version": "1.0.2",
"description": "Instantly find and follow the same users from your Twitter follows on Bluesky.", "description": "Instantly find and follow the same users from your Twitter follows on Bluesky.",
"author": "kawamataryou", "author": "kawamataryou",
"scripts": { "scripts": {

View File

@ -1,16 +1,10 @@
import cssText from "data-text:~style.content.css"; import cssText from "data-text:~style.content.css";
import type { AtpSessionData } from "@atproto/api";
import { sendToBackground } from "@plasmohq/messaging"; import { sendToBackground } from "@plasmohq/messaging";
import { getPort } from "@plasmohq/messaging/port";
import type { PlasmoCSConfig } from "plasmo"; import type { PlasmoCSConfig } from "plasmo";
import React from "react"; import React from "react";
import AlertError from "~lib/components/AlertError"; import AlertError from "~lib/components/AlertError";
import AlertSuccess from "~lib/components/AlertSuccess";
import LoadingCards from "~lib/components/LoadingCards"; import LoadingCards from "~lib/components/LoadingCards";
import MatchTypeFilter from "~lib/components/MatchTypeFilter";
import Modal from "~lib/components/Modal"; import Modal from "~lib/components/Modal";
import UserCard from "~lib/components/UserCard";
import UserCardSkeleton from "~lib/components/UserCardSkeleton";
import { MESSAGE_NAMES } from "~lib/constants"; import { MESSAGE_NAMES } from "~lib/constants";
import { useRetrieveBskyUsers } from "~lib/hooks/useRetrieveBskyUsers"; import { useRetrieveBskyUsers } from "~lib/hooks/useRetrieveBskyUsers";
@ -35,6 +29,7 @@ const App = () => {
stopRetrieveLoop, stopRetrieveLoop,
restart, restart,
isBottomReached, isBottomReached,
errorMessage,
} = useRetrieveBskyUsers(); } = useRetrieveBskyUsers();
React.useEffect(() => { React.useEffect(() => {
@ -87,6 +82,7 @@ const App = () => {
<p className="text-2xl font-bold"> <p className="text-2xl font-bold">
Detected <span className="text-4xl">{users.length}</span> users Detected <span className="text-4xl">{users.length}</span> users
</p> </p>
{errorMessage && <AlertError>{errorMessage}</AlertError>}
{loading && ( {loading && (
<> <>
<button <button

View File

@ -1,5 +1,5 @@
import { useStorage } from "@plasmohq/storage/hook";
import { Storage } from "@plasmohq/storage"; import { Storage } from "@plasmohq/storage";
import { useStorage } from "@plasmohq/storage/hook";
import React from "react"; import React from "react";
import { BskyServiceWorkerClient } from "~lib/bskyServiceWorkerClient"; import { BskyServiceWorkerClient } from "~lib/bskyServiceWorkerClient";
import { import {
@ -12,13 +12,14 @@ import { wait } from "~lib/utils";
import type { BskyUser, MatchType } from "~types"; import type { BskyUser, MatchType } from "~types";
export const useBskyUserManager = () => { export const useBskyUserManager = () => {
const [users, setUsers] = useStorage<BskyUser[]>({ const [users, setUsers] = useStorage<BskyUser[]>(
key: STORAGE_KEYS.DETECTED_BSKY_USERS, {
instance: new Storage({ key: STORAGE_KEYS.DETECTED_BSKY_USERS,
area: "local", instance: new Storage({
}), area: "local",
}, }),
(v) => (v === undefined ? [] : v) },
(v) => (v === undefined ? [] : v),
); );
const bskyClient = React.useRef<BskyServiceWorkerClient | null>(null); const bskyClient = React.useRef<BskyServiceWorkerClient | null>(null);
const [actionMode, setActionMode] = React.useState< const [actionMode, setActionMode] = React.useState<
@ -179,7 +180,7 @@ export const useBskyUserManager = () => {
bskyClient.current = new BskyServiceWorkerClient(session); bskyClient.current = new BskyServiceWorkerClient(session);
setActionMode( setActionMode(
MESSAGE_NAME_TO_ACTION_MODE_MAP[ MESSAGE_NAME_TO_ACTION_MODE_MAP[
result[STORAGE_KEYS.BSKY_MESSAGE_NAME] result[STORAGE_KEYS.BSKY_MESSAGE_NAME]
], ],
); );
}, },

View File

@ -1,6 +1,6 @@
import type { AtpSessionData } from "@atproto/api"; import type { AtpSessionData } from "@atproto/api";
import { useStorage } from "@plasmohq/storage/hook";
import { Storage } from "@plasmohq/storage"; import { Storage } from "@plasmohq/storage";
import { useStorage } from "@plasmohq/storage/hook";
import React from "react"; import React from "react";
import { BskyServiceWorkerClient } from "~lib/bskyServiceWorkerClient"; import { BskyServiceWorkerClient } from "~lib/bskyServiceWorkerClient";
import { import {
@ -41,13 +41,14 @@ export const useRetrieveBskyUsers = () => {
const [detectedXUsers, setDetectedXUsers] = React.useState< const [detectedXUsers, setDetectedXUsers] = React.useState<
ReturnType<typeof detectXUsers> ReturnType<typeof detectXUsers>
>([]); >([]);
const [users, setUsers] = useStorage<BskyUser[]>({ const [users, setUsers] = useStorage<BskyUser[]>(
key: STORAGE_KEYS.DETECTED_BSKY_USERS, {
instance: new Storage({ key: STORAGE_KEYS.DETECTED_BSKY_USERS,
area: "local", instance: new Storage({
}) area: "local",
}, }),
(v) => (v === undefined ? [] : v) },
(v) => (v === undefined ? [] : v),
); );
const [loading, setLoading] = React.useState(true); const [loading, setLoading] = React.useState(true);
const [errorMessage, setErrorMessage] = React.useState(""); const [errorMessage, setErrorMessage] = React.useState("");
@ -134,6 +135,7 @@ export const useRetrieveBskyUsers = () => {
setLoading(false); setLoading(false);
} }
index++; index++;
if (process.env.NODE_ENV === "development" && index > 5) { if (process.env.NODE_ENV === "development" && index > 5) {
setLoading(false); setLoading(false);

View File

@ -119,7 +119,7 @@ function IndexPopup() {
const { session, error } = await sendToBackground({ const { session, error } = await sendToBackground({
name: "login", name: "login",
body: { body: {
identifier, identifier: formattedIdentifier,
password, password,
...(authFactorToken && { authFactorToken: authFactorToken }), ...(authFactorToken && { authFactorToken: authFactorToken }),
}, },