mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-21 01:21:54 +08:00
ANNOUNCEMENTS FINALLY god damn
This commit is contained in:
parent
e0f875db30
commit
f04d38f3a2
@ -3,6 +3,7 @@ import type {Announcement as AnnouncementObject} from "hangar-api";
|
||||
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/vue'
|
||||
import type {Ref} from 'vue';
|
||||
import {useThemeStore} from '~/store/theme'
|
||||
import {useAPI} from '~/store/api'
|
||||
|
||||
import {useInitialState} from "~/composables/useInitialState";
|
||||
import {useInternalApi} from "~/composables/useApi";
|
||||
@ -12,32 +13,28 @@ const theme = useThemeStore()
|
||||
const { t } = useI18n();
|
||||
|
||||
|
||||
const empty: AnnouncementObject[] | null = [];
|
||||
const announcements: Ref<AnnouncementObject[] | null> = ref(empty);
|
||||
const empty: AnnouncementObject[] = [];
|
||||
const announcements: Ref<AnnouncementObject[]> = ref(empty);
|
||||
|
||||
async function loadAnnouncements(){
|
||||
return await useInitialState<AnnouncementObject[]>(
|
||||
"announcements",
|
||||
async () => await useInternalApi<AnnouncementObject[]>("data/announcements", false)
|
||||
);
|
||||
}
|
||||
loadAnnouncements().then((value) => {
|
||||
const vallue: Ref<AnnouncementObject[] | null> = value;
|
||||
|
||||
if(vallue.value){
|
||||
const firstObject: AnnouncementObject | null = vallue.value[0];
|
||||
if(firstObject){
|
||||
console.log(`Res: ${ firstObject.text}`)
|
||||
const api = useAPI();
|
||||
|
||||
api.getAnnouncements()
|
||||
.then((value) => {
|
||||
if(value){
|
||||
const firstObject: AnnouncementObject | null = value[0];
|
||||
if(firstObject){
|
||||
console.log(`Res: ${ firstObject.text}`)
|
||||
}else{
|
||||
console.log("Res is undefined")
|
||||
}
|
||||
}else{
|
||||
console.log("Res is undefined")
|
||||
console.log("value is null")
|
||||
}
|
||||
}else{
|
||||
console.log("vallue is null")
|
||||
}
|
||||
|
||||
announcements.value = value;
|
||||
});
|
||||
|
||||
announcements.value = unref(vallue);
|
||||
});
|
||||
|
||||
|
||||
const navBarLinks = [
|
||||
|
18
frontend-new/src/store/api.ts
Normal file
18
frontend-new/src/store/api.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { defineStore } from "pinia";
|
||||
import type { Ref} from "vue";
|
||||
import { ref, unref } from "vue";
|
||||
|
||||
import type {Announcement as AnnouncementObject} from "hangar-api";
|
||||
import {useInternalApi} from '~/composables/useApi';
|
||||
|
||||
export const useAPI = defineStore("api", () => {
|
||||
const announcements: Ref<AnnouncementObject | undefined> = ref();
|
||||
|
||||
|
||||
|
||||
async function getAnnouncements(): Promise<AnnouncementObject[]> {
|
||||
return await useInternalApi<AnnouncementObject[]>("data/announcements", false)
|
||||
}
|
||||
|
||||
return { announcements, getAnnouncements };
|
||||
});
|
Loading…
Reference in New Issue
Block a user