mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 03:29:16 +01:00
refactor: ♻️ Fix linter errors
This commit is contained in:
parent
8a984abfb2
commit
f9433e259b
30 changed files with 235 additions and 157 deletions
|
|
@ -12,12 +12,13 @@ export const useAccount = (
|
|||
const output = ref(null as Account | null);
|
||||
|
||||
watchEffect(() => {
|
||||
if (toValue(accountId))
|
||||
if (toValue(accountId)) {
|
||||
toValue(client)
|
||||
?.getAccount(toValue(accountId) ?? "")
|
||||
.then((res) => {
|
||||
output.value = res.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ import type { RolePermission } from "@lysand-org/client/types";
|
|||
import { useCurrentIdentity } from "./Identities";
|
||||
|
||||
export const useCacheRefresh = (client: MaybeRef<LysandClient | null>) => {
|
||||
if (import.meta.server) return;
|
||||
if (import.meta.server) {
|
||||
return;
|
||||
}
|
||||
|
||||
const identity = useCurrentIdentity();
|
||||
|
||||
|
|
@ -14,7 +16,9 @@ export const useCacheRefresh = (client: MaybeRef<LysandClient | null>) => {
|
|||
toValue(client)
|
||||
?.verifyAccountCredentials()
|
||||
.then((res) => {
|
||||
if (identity.value) identity.value.account = res.data;
|
||||
if (identity.value) {
|
||||
identity.value.account = res.data;
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
const code = err.response.status;
|
||||
|
|
@ -34,7 +38,9 @@ export const useCacheRefresh = (client: MaybeRef<LysandClient | null>) => {
|
|||
toValue(client)
|
||||
?.getInstanceCustomEmojis()
|
||||
.then((res) => {
|
||||
if (identity.value) identity.value.emojis = res.data;
|
||||
if (identity.value) {
|
||||
identity.value.emojis = res.data;
|
||||
}
|
||||
});
|
||||
|
||||
toValue(client)
|
||||
|
|
@ -47,16 +53,19 @@ export const useCacheRefresh = (client: MaybeRef<LysandClient | null>) => {
|
|||
.flatMap((r) => r.permissions)
|
||||
.filter((p, i, arr) => arr.indexOf(p) === i);
|
||||
|
||||
if (identity.value)
|
||||
if (identity.value) {
|
||||
identity.value.permissions =
|
||||
permissions as unknown as RolePermission[];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toValue(client)
|
||||
?.getInstance()
|
||||
.then((res) => {
|
||||
if (identity.value) identity.value.instance = res.data;
|
||||
if (identity.value) {
|
||||
identity.value.instance = res.data;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,12 +45,15 @@ export const useCurrentIdentity = (): Ref<Identity | null> => {
|
|||
if (newCurrent) {
|
||||
currentId.value = newCurrent.id;
|
||||
// If the identity is updated, update the identity in the list
|
||||
if (identities.value.find((i) => i.id === newCurrent.id))
|
||||
if (identities.value.find((i) => i.id === newCurrent.id)) {
|
||||
identities.value = identities.value.map((i) =>
|
||||
i.id === newCurrent.id ? newCurrent : i,
|
||||
);
|
||||
}
|
||||
// If the identity is not in the list, add it
|
||||
else identities.value.push(newCurrent);
|
||||
else {
|
||||
identities.value.push(newCurrent);
|
||||
}
|
||||
|
||||
// Force update the identities
|
||||
identities.value = [...identities.value];
|
||||
|
|
|
|||
|
|
@ -3,84 +3,21 @@ import type { Status } from "@lysand-org/client/types";
|
|||
|
||||
export const useLocalTimeline = (
|
||||
client: LysandClient | null,
|
||||
options: MaybeRef<
|
||||
Partial<{
|
||||
only_media: boolean;
|
||||
max_id: string;
|
||||
since_id: string;
|
||||
min_id: string;
|
||||
limit: number;
|
||||
}>
|
||||
>,
|
||||
options: MaybeRef<{
|
||||
only_media: boolean;
|
||||
max_id: string;
|
||||
since_id: string;
|
||||
min_id: string;
|
||||
limit: number;
|
||||
}>,
|
||||
): {
|
||||
timeline: Ref<Status[]>;
|
||||
loadNext: () => Promise<void>;
|
||||
loadPrev: () => Promise<void>;
|
||||
} => {
|
||||
if (!client) {
|
||||
return {
|
||||
timeline: ref([]),
|
||||
loadNext: async () => {},
|
||||
loadPrev: async () => {},
|
||||
};
|
||||
}
|
||||
|
||||
const fetchedNotes = ref<Status[]>([]);
|
||||
const fetchedNoteIds = new Set<string>();
|
||||
let nextMaxId: string | undefined = undefined;
|
||||
let prevMinId: string | undefined = undefined;
|
||||
|
||||
const loadNext = async () => {
|
||||
const response = await client.getLocalTimeline({
|
||||
...ref(options).value,
|
||||
max_id: nextMaxId,
|
||||
limit: useConfig().NOTES_PER_PAGE,
|
||||
});
|
||||
|
||||
const newNotes = response.data.filter(
|
||||
(note) => !fetchedNoteIds.has(note.id),
|
||||
);
|
||||
if (newNotes.length > 0) {
|
||||
fetchedNotes.value = [...fetchedNotes.value, ...newNotes];
|
||||
nextMaxId = newNotes[newNotes.length - 1]?.id;
|
||||
for (const note of newNotes) {
|
||||
fetchedNoteIds.add(note.id);
|
||||
}
|
||||
} else {
|
||||
nextMaxId = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const loadPrev = async () => {
|
||||
const response = await client.getLocalTimeline({
|
||||
...ref(options).value,
|
||||
min_id: prevMinId,
|
||||
limit: useConfig().NOTES_PER_PAGE,
|
||||
});
|
||||
|
||||
const newNotes = response.data.filter(
|
||||
(note) => !fetchedNoteIds.has(note.id),
|
||||
);
|
||||
if (newNotes.length > 0) {
|
||||
fetchedNotes.value = [...newNotes, ...fetchedNotes.value];
|
||||
prevMinId = newNotes[0]?.id;
|
||||
for (const note of newNotes) {
|
||||
fetchedNoteIds.add(note.id);
|
||||
}
|
||||
} else {
|
||||
prevMinId = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => ref(options).value,
|
||||
async ({ max_id, min_id }) => {
|
||||
nextMaxId = max_id;
|
||||
prevMinId = min_id;
|
||||
await loadNext();
|
||||
},
|
||||
{ immediate: true },
|
||||
return useTimeline(
|
||||
client,
|
||||
(client, options) => client?.getLocalTimeline(options),
|
||||
options,
|
||||
);
|
||||
|
||||
return { timeline: fetchedNotes, loadNext, loadPrev };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@ export const useNoteContext = (
|
|||
const output = ref(null as Context | null);
|
||||
|
||||
watchEffect(() => {
|
||||
if (toValue(noteId))
|
||||
if (toValue(noteId)) {
|
||||
ref(client)
|
||||
.value?.getStatusContext(toValue(noteId) ?? "")
|
||||
.then((res) => {
|
||||
output.value = res.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ export const useNoteData = (
|
|||
const shouldHide = computed(
|
||||
() =>
|
||||
(renderedNote.value?.sensitive ||
|
||||
!!renderedNote.value?.spoiler_text ||
|
||||
false) &&
|
||||
!!renderedNote.value?.spoiler_text) &&
|
||||
(showContentWarning.value.value as boolean),
|
||||
);
|
||||
const mentions = useResolveMentions(
|
||||
|
|
|
|||
|
|
@ -89,13 +89,13 @@ export const useParsedAccount = (
|
|||
account: MaybeRef<Account | undefined | null>,
|
||||
settings: MaybeRef<Settings>,
|
||||
) => {
|
||||
const display_name = computed(() => toValue(account)?.display_name ?? "");
|
||||
const displayName = computed(() => toValue(account)?.display_name ?? "");
|
||||
const note = computed(() => toValue(account)?.note ?? "");
|
||||
const fields = computed(() => toValue(account)?.fields ?? []);
|
||||
const emojis = computed(() => toValue(account)?.emojis ?? []);
|
||||
|
||||
const parsedDisplayName = useParsedContent(
|
||||
display_name,
|
||||
displayName,
|
||||
emojis,
|
||||
undefined,
|
||||
settings,
|
||||
|
|
|
|||
|
|
@ -14,12 +14,13 @@ export const useRelationship = (
|
|||
}
|
||||
|
||||
watchEffect(() => {
|
||||
if (toValue(accountId))
|
||||
if (toValue(accountId)) {
|
||||
toValue(client)
|
||||
?.getRelationship(toValue(accountId) ?? "")
|
||||
.then((res) => {
|
||||
relationship.value = res.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
watch(relationship, (newOutput, oldOutput) => {
|
||||
|
|
|
|||
|
|
@ -24,11 +24,15 @@ export const useTimeline = <
|
|||
loadNext: () => Promise<void>;
|
||||
loadPrev: () => Promise<void>;
|
||||
} => {
|
||||
if (!client || !fetchTimeline) {
|
||||
if (!(client && fetchTimeline)) {
|
||||
return {
|
||||
timeline: ref([]),
|
||||
loadNext: async () => {},
|
||||
loadPrev: async () => {},
|
||||
loadNext: async () => {
|
||||
// ...
|
||||
},
|
||||
loadPrev: async () => {
|
||||
// ...
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -107,11 +111,15 @@ export const useIdTimeline = <
|
|||
loadNext: () => Promise<void>;
|
||||
loadPrev: () => Promise<void>;
|
||||
} => {
|
||||
if (!client || !fetchTimeline) {
|
||||
if (!(client && fetchTimeline)) {
|
||||
return {
|
||||
timeline: ref([]),
|
||||
loadNext: async () => {},
|
||||
loadPrev: async () => {},
|
||||
loadNext: async () => {
|
||||
// ...
|
||||
},
|
||||
loadPrev: async () => {
|
||||
// ...
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue