Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adds survey as link #3571

Merged
merged 8 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ declare global {
const until: typeof import('@vueuse/core')['until']
const useActiveElement: typeof import('@vueuse/core')['useActiveElement']
const useAnimate: typeof import('@vueuse/core')['useAnimate']
const useAnnouncements: typeof import('./stores/announcements')['useAnnouncements']
const useArrayDifference: typeof import('@vueuse/core')['useArrayDifference']
const useArrayEvery: typeof import('@vueuse/core')['useArrayEvery']
const useArrayFilter: typeof import('@vueuse/core')['useArrayFilter']
Expand Down Expand Up @@ -287,7 +288,6 @@ declare global {
const useProfileStorage: typeof import('./composable/profileStorage')['useProfileStorage']
const useRafFn: typeof import('@vueuse/core')['useRafFn']
const useRefHistory: typeof import('@vueuse/core')['useRefHistory']
const useReleases: typeof import('./stores/releases')['useReleases']
const useResizeObserver: typeof import('@vueuse/core')['useResizeObserver']
const useRoute: typeof import('vue-router')['useRoute']
const useRouter: typeof import('vue-router')['useRouter']
Expand Down Expand Up @@ -551,6 +551,7 @@ declare module 'vue' {
readonly until: UnwrapRef<typeof import('@vueuse/core')['until']>
readonly useActiveElement: UnwrapRef<typeof import('@vueuse/core')['useActiveElement']>
readonly useAnimate: UnwrapRef<typeof import('@vueuse/core')['useAnimate']>
readonly useAnnouncements: UnwrapRef<typeof import('./stores/announcements')['useAnnouncements']>
readonly useArrayDifference: UnwrapRef<typeof import('@vueuse/core')['useArrayDifference']>
readonly useArrayEvery: UnwrapRef<typeof import('@vueuse/core')['useArrayEvery']>
readonly useArrayFilter: UnwrapRef<typeof import('@vueuse/core')['useArrayFilter']>
Expand Down Expand Up @@ -676,7 +677,6 @@ declare module 'vue' {
readonly useProfileStorage: UnwrapRef<typeof import('./composable/profileStorage')['useProfileStorage']>
readonly useRafFn: UnwrapRef<typeof import('@vueuse/core')['useRafFn']>
readonly useRefHistory: UnwrapRef<typeof import('@vueuse/core')['useRefHistory']>
readonly useReleases: UnwrapRef<typeof import('./stores/releases')['useReleases']>
readonly useResizeObserver: UnwrapRef<typeof import('@vueuse/core')['useResizeObserver']>
readonly useRoute: UnwrapRef<typeof import('vue-router')['useRoute']>
readonly useRouter: UnwrapRef<typeof import('vue-router')['useRouter']>
Expand Down
2 changes: 1 addition & 1 deletion assets/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
Announcements: typeof import('./components/Announcements.vue')['default']
'Carbon:caretDown': typeof import('~icons/carbon/caret-down')['default']
'Carbon:circleSolid': typeof import('~icons/carbon/circle-solid')['default']
'Carbon:copyFile': typeof import('~icons/carbon/copy-file')['default']
Expand Down Expand Up @@ -99,7 +100,6 @@ declare module 'vue' {
'Ph:stackSimple': typeof import('~icons/ph/stack-simple')['default']
Popup: typeof import('./components/Popup.vue')['default']
RandomColorTag: typeof import('./components/LogViewer/RandomColorTag.vue')['default']
Releases: typeof import('./components/Releases.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
ScrollableView: typeof import('./components/ScrollableView.vue')['default']
Expand Down
115 changes: 115 additions & 0 deletions assets/components/Announcements.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<template>
<Dropdown class="dropdown-end" @closed="releaseSeen = mostRecent?.tag ?? config.version">
<template #trigger>
<mdi:announcement class="size-6 -rotate-12" />
<template v-if="announcements.length > 0 && releaseSeen != mostRecent?.tag">
<span class="bg-red absolute top-0 right-px size-2 animate-ping rounded-full opacity-75"></span>
<span class="bg-red absolute top-0 right-px size-2 rounded-full"></span>
</template>
</template>
<template #content>
<div class="w-72">
<ul class="space-y-4 p-2">
<li v-for="release in announcements" v-if="announcements.length > 0">
<template v-if="release.announcement">
<div class="flex items-baseline gap-1">
<carbon:information class="text-info self-center" />
<a
:href="release.htmlUrl"
class="link-primary text-lg font-bold"
target="_blank"
rel="noreferrer noopener"
>
{{ release.name }}
</a>
<span class="ml-1 text-xs"><distance-time :date="release.createdAt" /></span>
</div>
<div class="text-base-content/80 text-sm">
{{ release.body }}
</div>
</template>
<template v-else>
<div class="flex items-baseline gap-1">
<carbon:warning class="stroke-orange self-center" v-if="release.breaking > 0" />
<a
:href="release.htmlUrl"
class="link-primary text-lg font-bold"
target="_blank"
rel="noreferrer noopener"
>
{{ release.name }}
</a>
<span class="ml-1 text-xs"><distance-time :date="release.createdAt" /></span>
<Tag class="bg-red ml-auto px-1 py-1 text-xs" v-if="release.latest">
{{ $t("releases.latest") }}
</Tag>
</div>
<div class="text-base-content/80 text-sm">
{{ summary(release) }}
</div>
</template>
</li>
<li v-else>
<div class="text-base-content/80 text-sm">
{{ $t("releases.no_releases") }}
</div>
</li>
</ul>
</div>
</template>
</Dropdown>
</template>

<script setup lang="ts">
import { useAnnouncements } from "@/stores/announcements";

const { announcements, mostRecent } = useAnnouncements();
const { t } = useI18n();

const releaseSeen = useProfileStorage("releaseSeen", config.version);

function summary(release: { features: number; bugFixes: number; breaking: number }) {
if (release.features > 0 && release.bugFixes > 0 && release.breaking > 0) {
return t("releases.three_parts", {
first: t("releases.breaking", { count: release.breaking }),
second: t("releases.features", { count: release.features }),
third: t("releases.bugFixes", { count: release.bugFixes }),
});
}

if (release.features > 0 && release.bugFixes > 0) {
return t("releases.two_parts", {
first: t("releases.features", { count: release.features }),
second: t("releases.bugFixes", { count: release.bugFixes }),
});
}

if (release.features > 0 && release.breaking > 0) {
return t("releases.two_parts", {
first: t("releases.features", { count: release.features }),
second: t("releases.breaking", { count: release.breaking }),
});
}

if (release.bugFixes > 0 && release.breaking > 0) {
return t("releases.two_parts", {
first: t("releases.bugFixes", { count: release.bugFixes }),
second: t("releases.breaking", { count: release.breaking }),
});
}

if (release.features > 0) {
return t("releases.features", { count: release.features });
}

if (release.bugFixes > 0) {
return t("releases.bugFixes", { count: release.bugFixes });
}

if (release.breaking > 0) {
return t("releases.breaking", { count: release.breaking });
}
}
</script>

<style scoped></style>
18 changes: 1 addition & 17 deletions assets/components/Links.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
<template>
<div class="flex items-center justify-end gap-4">
<slot name="more-items"></slot>
<Dropdown class="dropdown-end" @closed="latestTag = latest?.tag ?? config.version">
<template #trigger>
<mdi:announcement class="size-6 -rotate-12" />
<span
class="bg-red absolute top-0 right-px size-2 rounded-full"
v-if="hasUpdate && latestTag != latest?.tag"
></span>
</template>
<template #content>
<div class="w-72">
<Releases />
</div>
</template>
</Dropdown>
<Announcements />

<router-link
:to="{ name: '/settings' }"
Expand Down Expand Up @@ -58,7 +45,4 @@ async function logout() {

location.reload();
}

const { hasUpdate, latest } = useReleases();
const latestTag = useProfileStorage("releaseSeen", config.version);
</script>
74 changes: 0 additions & 74 deletions assets/components/Releases.vue

This file was deleted.

6 changes: 3 additions & 3 deletions assets/pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div>
<span v-html="$t('settings.using-version', { version: config.version })"></span>
<div
v-if="hasUpdate"
v-html="$t('settings.update-available', { nextVersion: latest?.name, href: latest?.htmlUrl })"
v-if="hasRelease"
v-html="$t('settings.update-available', { nextVersion: latestRelease?.name, href: latestRelease?.htmlUrl })"
></div>
</div>
</section>
Expand Down Expand Up @@ -154,7 +154,7 @@ import { availableLocales, i18n } from "@/modules/i18n";
const { t } = useI18n();

setTitle(t("title.settings"));
const { latest, hasUpdate } = useReleases();
const { latestRelease, hasRelease } = useAnnouncements();

const now = new Date();
const hoursAgo = (hours: number) => {
Expand Down
51 changes: 51 additions & 0 deletions assets/stores/announcements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
type Announcement = {
name: string;
announcement: boolean;
createdAt: Date;
body: string;
tag: string;
htmlUrl: string;
latest: boolean;
mentionsCount: number;
features: number;
bugFixes: number;
breaking: number;
};

const { data: releases } = useFetch(withBase("/api/releases")).get().json<Announcement[]>();

const otherAnnouncements = [
{
body: "I'd love to hear about your experience in this short survey to shape the future of Dozzle!",
createdAt: new Date("2025-01-22T18:00:00Z"),
htmlUrl: "https://tally.so/r/wLv4g2?ref=notification",
name: "Take survey!",
announcement: true,
tag: "survey-2025-01",
latest: true,
mentionsCount: 0,
features: 0,
bugFixes: 0,
breaking: 0,
},
] as Announcement[];

const announcements = computed(() => {
const newReleases =
releases.value?.map((release) => ({ ...release, createdAt: new Date(release.createdAt), announcement: false })) ??
[];
return [...newReleases, ...otherAnnouncements].sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
});

const mostRecent = computed(() => announcements.value?.[0]);
const latestRelease = computed(() => announcements.value?.find((release) => release.latest && !release.announcement));
const hasRelease = computed(() => latestRelease.value !== undefined);

export function useAnnouncements() {
return {
mostRecent,
announcements,
latestRelease,
hasRelease,
};
}
29 changes: 0 additions & 29 deletions assets/stores/releases.ts

This file was deleted.

Loading