Skip to content

Commit

Permalink
feat: add instance links on right bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Cl0v1s committed Jan 28, 2025
1 parent e283819 commit 8a456c3
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions akko/src/akkoma/entities/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ export * from "./tag";
export * from "./token";
export * from "./translation";
export * from "./web-push-subscription";
export * from "./pleroma-config";
17 changes: 17 additions & 0 deletions akko/src/akkoma/entities/v1/pleroma-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type FrontendConfiguration = { [x: string]: { [x: string]: unknown } };

export interface PleromaConfig {
/**
* Instance needs to be rebooted
*/
need_reboot: boolean;
/**
* Pleroma settings
*/
configs: {
group: string;
key: string;
db: string[];
value: FrontendConfiguration[];
}[];
}
2 changes: 2 additions & 0 deletions akko/src/akkoma/rest/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface Client {
readonly notifications: v1.NotificationRepository;
readonly polls: v1.PollRepository;
readonly preferences: v1.PreferenceRepository;
readonly pleroma: v1.PleromaRepository;
readonly reports: v1.ReportRepository;
readonly scheduledStatuses: v1.ScheduledStatusRepository;
readonly search: v1.SearchRepository;
Expand All @@ -47,4 +48,5 @@ export interface Client {
readonly suggestions: v2.SuggestionRepository;
readonly search: v2.SearchRepository;
};
readonly pleroma: v1.PleromaRepository;
}
1 change: 1 addition & 0 deletions akko/src/akkoma/rest/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export * from "./tag-repository";
export * from "./timeline-repository";
export * from "./trend-repository";
export * from "./profile-repository";
export * from "./pleroma-repository";
17 changes: 17 additions & 0 deletions akko/src/akkoma/rest/v1/pleroma-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
type FrontendConfiguration,
type PleromaConfig,
} from "../../entities/v1/pleroma-config";

export interface PleromaRepository {
admin: {
config: {
/** Retrieves current pleroma configuration */
fetch(): Promise<PleromaConfig>;
};
};

frontendConfigurations: {
fetch(): Promise<FrontendConfiguration>;
};
}
15 changes: 15 additions & 0 deletions elk/components/nav/NavPromoPanel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script setup lang="ts">
const props = defineProps<{ class?: string }>()
const { config } = useFrontendConfig()
</script>

<template>
<nav :class="props.class" flex flex-col gap-6>
<NuxtLink v-for="link in config?.links" :key="link.url" target="_blank" flex gap-2 text-lg :href="link.url">
<div grayscale>
{{ link.icon }}
</div>
{{ link.text }}
</NuxtLink>
</nav>
</template>
21 changes: 21 additions & 0 deletions elk/composables/akko/frontend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { akkoma } from '@bdxtown/akko'

export interface FrontendConfiguration {
links: {
icon: string
text: string
url: string
}[]
}

export function useFrontendConfig() {
const { data: config } = useAsyncData<FrontendConfiguration | undefined>(
'pleroma-config',
() => fetchFrontendConfiguration(),
{ watch: [isHydrated], immediate: isHydrated.value, default: () => shallowRef(undefined) },
)

return {
config,
}
}
27 changes: 27 additions & 0 deletions elk/composables/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { akkoma } from '@bdxtown/akko'
import { LRUCache } from 'lru-cache'
import { name } from './../package.json'

const cache = new LRUCache<string, any>({
max: 1000,
Expand All @@ -17,6 +18,27 @@ function removeCached(key: string) {
cache.delete(key)
}

export function fetchFrontendConfiguration(): Promise<FrontendConfiguration | undefined> {
const server = currentServer.value
const key = `${server}:pleroma-config`
const cached = cache.has(key)
if (cached)
return Promise.resolve(cache.get(key))

const promise = useAkkoClient().pleroma.frontendConfigurations.fetch().then((config) => {
let frontendConfiguration = config[`${name}Fe`] || config[`${'soapbox'}Fe`] // TODO: remove when settings will be ok
// TODO: remove when settings will be ok
frontendConfiguration = {
...frontendConfiguration,
links: (frontendConfiguration.promoPanel as { items: FrontendConfiguration['links'] }).items,
}
cacheFrontendConfiguration(frontendConfiguration)
return frontendConfiguration as unknown as FrontendConfiguration | undefined
})
cache.set(key, promise)
return promise
}

export function fetchStatus(id: string, force = false): Promise<akkoma.v1.Status> {
const server = currentServer.value
const userId = currentUser.value?.account.id
Expand Down Expand Up @@ -111,6 +133,11 @@ export function useAccountById(id?: string | null) {
return useAsyncState(() => fetchAccountById(id), null).state
}

export function cacheFrontendConfiguration(config: unknown | undefined, override?: boolean) {
const server = currentServer.value
setCached(`${server}:pleroma-config`, config, override)
}

export function cacheStatus(status: akkoma.v1.Status, server = currentServer.value, override?: boolean) {
const userId = currentUser.value?.account.id
setCached(`${server}:${userId}:status:${status.id}`, status, override)
Expand Down
5 changes: 4 additions & 1 deletion elk/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import NavPromoPanel from '~/components/nav/NavPromoPanel.vue'
import { usePreferences } from '~/composables/settings'
const route = useRoute()
Expand Down Expand Up @@ -69,7 +70,9 @@ const isGrayscale = usePreferences('grayscaleMode')
</div>
</div>
<SearchWidget mt-4 mx-1 hidden xl:block />
<div flex-auto />
<div flex-auto>
<NavPromoPanel class="mt-12" />
</div>
<PwaPrompt />
<PwaInstallPrompt />
<LazyCommonPreviewPrompt v-if="info.env === 'preview'" />
Expand Down

0 comments on commit 8a456c3

Please sign in to comment.