added settings

This commit is contained in:
thislight 2024-07-22 21:57:04 +08:00
parent 5ec00d4999
commit 5833e5a76b
15 changed files with 359 additions and 91 deletions

View file

@ -1,6 +1,11 @@
import { persistentAtom } from "@nanostores/persistent";
import { createOAuthAPIClient, createRestAPIClient } from "masto";
import {
createOAuthAPIClient,
createRestAPIClient,
type mastodon,
} from "masto";
import { action } from "nanostores";
import { createMastoClientFor } from "../masto/clients";
export type Account = {
site: string;
@ -9,6 +14,8 @@ export type Account = {
tokenType: string;
scope: string;
createdAt: number;
inf?: mastodon.v1.AccountCredentials;
};
export const $accounts = persistentAtom<Account[]>("accounts", [], {
@ -75,6 +82,23 @@ export const acceptAccountViaAuthCode = action(
},
);
export const updateAcctInf = action(
$accounts,
"updateAcctInf",
async ($store, idx: number) => {
const o = $store.get();
const client = createMastoClientFor(o[idx]);
const inf = await client.v1.accounts.verifyCredentials();
o[idx].inf = inf;
$store.set(o);
return inf;
},
);
export const signOut = action($accounts, "signOut", ($store, predicate: (acct: Account) => boolean) => {
$store.set($store.get().filter(a => !predicate(a)));
});
export type RegisteredApp = {
site: string;
clientId: string;