refactor: ♻️ Replace megalodon with @lysand-org/client

This commit is contained in:
Jesse Wierzbinski 2024-06-07 13:09:15 -10:00
parent 5c528e8d03
commit 0bd3237965
No known key found for this signature in database
41 changed files with 147 additions and 170 deletions

View file

@ -206,87 +206,64 @@ const canSubmit = computed(
content.value?.trim().length <= characterLimit.value,
);
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const send = async () => {
loading.value = true;
if (respondingType.value === "edit") {
fetch(
new URL(
`/api/v1/statuses/${respondingTo.value?.id}`,
client.value?.baseUrl ?? "",
).toString(),
{
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${tokenData.value?.access_token}`,
},
body: JSON.stringify({
status: content.value?.trim() ?? "",
content_type: markdown.value
? "text/markdown"
: "text/plain",
spoiler_text: cw.value ? cwContent.value.trim() : undefined,
sensitive: cw.value,
media_ids: files.value
.filter((file) => !!file.api_id)
.map((file) => file.api_id),
}),
},
)
.then(async (res) => {
if (!res.ok) {
throw new Error("Failed to edit status");
}
content.value = "";
loading.value = false;
useEvent("composer:send-edit", await res.json());
})
.finally(() => {
useEvent("composer:close");
});
return;
if (!tokenData.value || !client.value) {
throw new Error("Not authenticated");
}
fetch(new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(), {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${tokenData.value?.access_token}`,
},
body: JSON.stringify({
if (respondingType.value === "edit" && respondingTo.value) {
const response = await client.value.editStatus(respondingTo.value.id, {
status: content.value?.trim() ?? "",
content_type: markdown.value ? "text/markdown" : "text/plain",
in_reply_to_id:
respondingType.value === "reply"
? respondingTo.value?.id
: null,
quote_id:
respondingType.value === "quote"
? respondingTo.value?.id
: null,
spoiler_text: cw.value ? cwContent.value.trim() : undefined,
sensitive: cw.value,
media_ids: files.value
.filter((file) => !!file.api_id)
.map((file) => file.api_id),
}),
})
.then(async (res) => {
if (!res.ok) {
throw new Error("Failed to send status");
}
content.value = "";
loading.value = false;
useEvent("composer:send", await res.json());
})
.finally(() => {
useEvent("composer:close");
.map((file) => file.api_id) as string[],
});
if (!response.data) {
throw new Error("Failed to edit status");
}
content.value = "";
loading.value = false;
useEvent("composer:send-edit", response.data);
useEvent("composer:close");
return;
}
const response = await client.value.postStatus(
content.value?.trim() ?? "",
{
content_type: markdown.value ? "text/markdown" : "text/plain",
in_reply_to_id:
respondingType.value === "reply"
? respondingTo.value?.id
: undefined,
quote_id:
respondingType.value === "quote"
? respondingTo.value?.id
: undefined,
spoiler_text: cw.value ? cwContent.value.trim() : undefined,
sensitive: cw.value,
media_ids: files.value
.filter((file) => !!file.api_id)
.map((file) => file.api_id) as string[],
},
);
if (!response.data) {
throw new Error("Failed to send status");
}
content.value = "";
loading.value = false;
useEvent("composer:send", response.data as Status);
useEvent("composer:close");
};
const characterLimit = computed(

View file

@ -74,7 +74,7 @@ const files = defineModel<
});
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const fileInput = ref<HTMLInputElement | null>(null);
const openFilePicker = () => {

View file

@ -175,7 +175,7 @@ const loadingAuth = ref(false);
const appData = useAppData();
const tokenData = useTokenData();
const client = useMegalodon();
const client = useClient();
const me = useMe();
const compose = () => {
@ -191,18 +191,18 @@ const signIn = async () => {
website: useBaseUrl().value,
});
if (!output) {
if (!output?.data) {
alert("Failed to create app");
return;
}
appData.value = output;
appData.value = output.data;
const url = await client.value?.generateAuthUrl(
output.client_id,
output.client_secret,
output.data.client_id,
output.data.client_secret,
{
scope: ["read", "write", "follow", "push"],
scopes: ["read", "write", "follow", "push"],
redirect_uri: new URL("/", useRequestURL().origin).toString(),
},
);

View file

@ -2,8 +2,8 @@
<div class="flex flex-col p-10 gap-4 h-full">
<div
class="aspect-video shrink-0 w-full rounded ring-white/5 bg-dark-800 shadow overflow-hidden ring-1 hover:ring-2 duration-100">
<img class="object-cover w-full h-full duration-150 hover:scale-[102%] ease-in-out" v-if="instance?.banner"
alt="Instance banner" :src="instance.banner" />
<img class="object-cover w-full h-full duration-150 hover:scale-[102%] ease-in-out"
v-if="instance?.banner.url" alt="Instance banner" :src="instance.banner.url" />
</div>
<div class="prose prose-invert prose-sm">
@ -11,15 +11,15 @@
<div v-html="description?.content"></div>
</div>
<div v-if="instance?.contact_account" class="flex flex-col gap-2 mt-auto">
<div v-if="instance?.contact.account" class="flex flex-col gap-2 mt-auto">
<h2 class="text-gray-200 font-semibold uppercase text-xs">Administrator</h2>
<SocialElementsUsersSmallCard :account="instance.contact_account" />
<SocialElementsUsersSmallCard :account="instance.contact.account" />
</div>
</div>
</template>
<script lang="ts" setup>
const client = useMegalodon();
const client = useClient();
const instance = useInstance();
const description = useExtendedDescription(client);
</script>

View file

@ -112,7 +112,7 @@ useListen("composer:send-edit", (note) => {
const tokenData = useTokenData();
const isSignedIn = useSignedIn();
const me = useMe();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const {
loaded,
note: outputtedNote,

View file

@ -16,6 +16,6 @@ const props = defineProps<{
}>();
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const account = useAccount(client, props.account_id);
</script>

View file

@ -105,7 +105,7 @@ const props = defineProps<{
const skeleton = computed(() => !props.account);
const tokenData = useTokenData();
const me = useMe();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const accountId = computed(() => props.account?.id ?? null);
const { relationship, isLoading } = useRelationship(client, accountId);

View file

@ -7,7 +7,7 @@ const props = defineProps<{
id?: string;
}>();
const client = useMegalodon();
const client = useClient();
const timelineParameters = ref({});
const { timeline, loadNext, loadPrev } = useAccountTimeline(
client.value,

View file

@ -4,7 +4,7 @@
<script lang="ts" setup>
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const timelineParameters = ref({});
const { timeline, loadNext, loadPrev } = useHomeTimeline(
client.value,

View file

@ -3,7 +3,7 @@
</template>
<script lang="ts" setup>
const client = useMegalodon();
const client = useClient();
const timelineParameters = ref({});
const { timeline, loadNext, loadPrev } = useLocalTimeline(
client.value,

View file

@ -15,7 +15,7 @@
<script lang="ts" setup>
const tokenData = useTokenData();
const client = useMegalodon(tokenData);
const client = useClient(tokenData);
const isLoading = ref(true);

View file

@ -3,7 +3,7 @@
</template>
<script lang="ts" setup>
const client = useMegalodon();
const client = useClient();
const timelineParameters = ref({});
const { timeline, loadNext, loadPrev } = usePublicTimeline(
client.value,