Compare commits

..

2 commits

Author SHA1 Message Date
thislight
e882a8c0e8
accounts/stores: added useAccts
All checks were successful
/ depoly (push) Successful in 1m15s
2024-07-14 21:36:41 +08:00
thislight
a0432af982
vite: sourcemap always enabled 2024-07-14 21:26:55 +08:00
3 changed files with 20 additions and 4 deletions

View file

@ -1,6 +1,9 @@
import { persistentAtom } from "@nanostores/persistent"; import { persistentAtom } from "@nanostores/persistent";
import { useStore } from "@nanostores/solid";
import { useNavigate } from "@solidjs/router";
import { createOAuthAPIClient, createRestAPIClient } from "masto"; import { createOAuthAPIClient, createRestAPIClient } from "masto";
import { action } from "nanostores"; import { action } from "nanostores";
import { createRenderEffect } from "solid-js";
export type Account = { export type Account = {
site: string; site: string;
@ -25,7 +28,7 @@ interface OAuth2AccessToken {
async function oauth2TokenViaAuthCode(app: RegisteredApp, authCode: string) { async function oauth2TokenViaAuthCode(app: RegisteredApp, authCode: string) {
const resp = await fetch(new URL("./oauth/token", app.site), { const resp = await fetch(new URL("./oauth/token", app.site), {
method: 'post', method: "post",
body: JSON.stringify({ body: JSON.stringify({
grant_type: "authorization_code", grant_type: "authorization_code",
code: authCode, code: authCode,
@ -97,7 +100,7 @@ export const $registeredApps = persistentAtom<{
async function getAppAccessToken(app: RegisteredApp) { async function getAppAccessToken(app: RegisteredApp) {
const resp = await fetch(new URL("./oauth/token", app.site), { const resp = await fetch(new URL("./oauth/token", app.site), {
method: 'post', method: "post",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
@ -172,3 +175,15 @@ export const getOrRegisterApp = action(
return all[site]; return all[site];
}, },
); );
export function useAccts() {
const accts = useStore($accounts);
const naviagte = useNavigate();
createRenderEffect(() => {
if (accts().length > 0) return;
naviagte("/accounts/sign-in");
});
return accts;
}

View file

@ -8,7 +8,7 @@ import {
untrack, untrack,
onMount, onMount,
} from "solid-js"; } from "solid-js";
import { $accounts } from "../accounts/stores"; import { $accounts, useAccts } from "../accounts/stores";
import { useDocumentTitle } from "../utils"; import { useDocumentTitle } from "../utils";
import { useStore } from "@nanostores/solid"; import { useStore } from "@nanostores/solid";
import { useMastoClientFor } from "../masto/clients"; import { useMastoClientFor } from "../masto/clients";
@ -152,7 +152,7 @@ const TimelinePanel: Component<{
const Home: Component = () => { const Home: Component = () => {
let panelList: HTMLDivElement; let panelList: HTMLDivElement;
useDocumentTitle("Timelines"); useDocumentTitle("Timelines");
const accounts = useStore($accounts); const accounts = useAccts();
const now = createTimeSource(); const now = createTimeSource();
const client = useMastoClientFor(() => accounts()[0]); const client = useMastoClientFor(() => accounts()[0]);

View file

@ -23,5 +23,6 @@ export default defineConfig(({ mode }) => ({
}, },
build: { build: {
target: ["firefox98", "safari15.4", "ios15.4", "chrome84", "edge87"], target: ["firefox98", "safari15.4", "ios15.4", "chrome84", "edge87"],
sourcemap: true,
}, },
})); }));