Skip to content

Commit 1162f6b

Browse files
authored
chore: Merge branch dev to main (#304)
2 parents d29c293 + 7f12c38 commit 1162f6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1105
-1159
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
RV_API_URL=https://api.revanced.app
2+
RV_STATUS_URL=https://status.revanced.app
3+
24
RV_GOOGLE_TAG_MANAGER_ID=
35
RV_DMCA_GUID=

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
RV_API_URL: ${{ vars.RV_API_URL }}
3535
RV_GOOGLE_TAG_MANAGER_ID: ${{ vars.RV_GOOGLE_TAG_MANAGER_ID }}
3636
RV_DMCA_GUID: ${{ vars.RV_DMCA_GUID }}
37+
RV_STATUS_URL: ${{ vars.RV_STATUS_URL }}
38+
RV_EMAIL: ${{ vars.RV_EMAIL }}
3739
run: npm run build
3840

3941
- name: Deploy

src/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
</head>
2323

2424
<body>
25-
%sveltekit.body%
25+
<div style="display: contents">%sveltekit.body%</div>
2626
</body>
2727
</html>

src/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ p {
143143
line-height: 1.75rem;
144144
}
145145

146-
@media screen and (max-width: 767px) {
146+
@media (max-width: 768px) {
147147
h1 {
148148
font-size: 2.6rem;
149149
line-height: 3.75rem;

src/data/api/settings.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { browser } from '$app/environment';
2-
import { RV_API_URL } from '$env/static/public';
2+
import { RV_API_URL, RV_EMAIL, RV_STATUS_URL } from '$env/static/public';
33

44
export const default_api_url = RV_API_URL;
5+
export const default_status_url = RV_STATUS_URL;
6+
export const default_email = RV_EMAIL;
57

68
const URL_KEY = 'revanced_api_url';
79
const STATUS_KEY = 'revanced_status_url';
8-
9-
function set_status_url(apiUrl: string) {
10-
fetch(`${apiUrl}/v4/about`)
11-
.then((response) => (response.ok ? response.json() : null))
12-
.then((data) => {
13-
if (data?.status) {
14-
localStorage.setItem(STATUS_KEY, data.status);
15-
console.log('Status is now:', localStorage.getItem(STATUS_KEY));
16-
}
17-
});
18-
}
10+
const EMAIL_KEY = 'revanced_email';
1911

2012
export const API_VERSION = 'v4';
2113

@@ -24,22 +16,28 @@ export function api_base_url(): string {
2416
if (browser) {
2517
const apiUrl = localStorage.getItem(URL_KEY) || default_api_url;
2618

27-
if (!localStorage.getItem(STATUS_KEY)) {
28-
set_status_url(apiUrl);
29-
}
19+
set_about_info(apiUrl);
3020

3121
return apiUrl;
3222
}
3323

3424
return default_api_url;
3525
}
3626

37-
export function status_url(): string | null {
27+
export function status_url(): string {
28+
if (browser) {
29+
return localStorage.getItem(STATUS_KEY) || default_status_url;
30+
}
31+
32+
return default_status_url;
33+
}
34+
35+
export function email(): string {
3836
if (browser) {
39-
return localStorage.getItem(STATUS_KEY) || null;
37+
return localStorage.getItem(EMAIL_KEY) || default_email;
4038
}
4139

42-
return null;
40+
return default_email;
4341
}
4442

4543
// (re)set base URL.
@@ -48,6 +46,21 @@ export function set_api_base_url(url?: string) {
4846
localStorage.removeItem(URL_KEY);
4947
} else {
5048
localStorage.setItem(URL_KEY, url);
51-
set_status_url(url);
49+
set_about_info(url);
50+
}
51+
}
52+
53+
function set_about_info(apiUrl: string) {
54+
if (!localStorage.getItem(STATUS_KEY) || !localStorage.getItem(EMAIL_KEY)) {
55+
fetch(`${apiUrl}/v4/about`)
56+
.then((response) => (response.ok ? response.json() : null))
57+
.then((data) => {
58+
if (data?.status) {
59+
localStorage.setItem(STATUS_KEY, data.status);
60+
localStorage.setItem(EMAIL_KEY, data.contact.email);
61+
console.log('Status is now:', localStorage.getItem(STATUS_KEY));
62+
console.log('Email is now:', localStorage.getItem(EMAIL_KEY));
63+
}
64+
});
5265
}
5366
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script lang="ts">
2+
import { read_announcements } from '$lib/stores';
3+
import Banner from '$layout/Banners/Banner.svelte';
4+
import { goto } from '$app/navigation';
5+
import { createQuery } from '@tanstack/svelte-query';
6+
import { queries } from '$data/api';
7+
import moment from 'moment';
8+
9+
const query = createQuery(queries.announcements());
10+
11+
$: latestUnreadAnnouncement = (() => {
12+
const announcements = $query.data?.announcements ?? [];
13+
14+
const nonArchived = announcements.filter(
15+
(a) => !a.archived_at || moment(a.archived_at).isAfter(moment())
16+
);
17+
18+
const announcement = nonArchived[0];
19+
20+
return announcement && !$read_announcements.has(announcement.id) ? announcement : undefined;
21+
})();
22+
23+
function setAsRead() {
24+
if (!latestUnreadAnnouncement) return;
25+
26+
read_announcements.update((set) => {
27+
const updated = new Set(set);
28+
updated.add(latestUnreadAnnouncement.id);
29+
return updated;
30+
});
31+
}
32+
33+
function handleClick() {
34+
if (!latestUnreadAnnouncement) return;
35+
36+
goto(`/announcements/${latestUnreadAnnouncement.id}`);
37+
setAsRead();
38+
}
39+
40+
function handleClose() {
41+
if (!latestUnreadAnnouncement) return;
42+
43+
setAsRead();
44+
}
45+
46+
function getBannerLevel(level: number | undefined): 'info' | 'caution' {
47+
if (!level || level == 0) return 'info';
48+
return 'caution';
49+
}
50+
</script>
51+
52+
{#if latestUnreadAnnouncement}
53+
<Banner
54+
title={'We have an announcement'}
55+
description={`You can read more about "${latestUnreadAnnouncement.title}" in our latest post.`}
56+
level={getBannerLevel(latestUnreadAnnouncement.level)}
57+
buttonText="Read more"
58+
buttonOnClick={handleClick}
59+
onDismiss={handleClose}
60+
/>
61+
{/if}

src/lib/components/Banner.svelte renamed to src/layout/Banners/Banner.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { createEventDispatcher } from 'svelte';
33
import Close from 'svelte-material-icons/Close.svelte';
44
import ArrowRight from 'svelte-material-icons/ArrowRight.svelte';
5-
import Button from './Button.svelte';
5+
import Button from '$lib/components/Button.svelte';
66
77
export let title: string;
88
export let description: string | undefined = undefined;
@@ -83,7 +83,7 @@
8383
color: #601410;
8484
}
8585
86-
@media (max-width: 767px) {
86+
@media (max-width: 768px) {
8787
flex-direction: column;
8888
padding: 1.1rem 1.3rem;
8989
}

src/layout/Navbar/StatusBanner.svelte renamed to src/layout/Banners/StatusBanner.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3-
import Banner from '$lib/components/Banner.svelte';
3+
import { email } from '$data/api/settings';
4+
import Banner from '$layout/Banners/Banner.svelte';
45
56
export let statusUrl: string | null = null;
67
@@ -9,7 +10,7 @@
910

1011
<Banner
1112
title="API service is currently down"
12-
description="We're actively investigating and will update you shortly. We appreciate your patience."
13+
description="Some features of the site might be impacted. If this issue persists, reach out to mailto:{email()}"
1314
buttonText={statusUrl ? 'View status' : undefined}
1415
buttonOnClick={statusUrl ? handleClick : undefined}
1516
level="caution"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script lang="ts">
2+
import Button from '$lib/components/Button.svelte';
3+
import Dialog from '$layout/Dialogs/Dialog.svelte';
4+
import { onMount } from 'svelte';
5+
import { allowAnalytics } from '$lib/stores';
6+
import { RV_GOOGLE_TAG_MANAGER_ID } from '$env/static/public';
7+
8+
let showConsentDialog = false;
9+
10+
function enableAnalytics() {
11+
//@ts-ignore
12+
window.dataLayer = window.dataLayer || [];
13+
function gtag(...args: any[]) {
14+
//@ts-ignore
15+
window.dataLayer.push(args);
16+
}
17+
gtag('js', new Date());
18+
19+
const script = document.createElement('script');
20+
script.src = `https://www.googletagmanager.com/gtm.js?id=${RV_GOOGLE_TAG_MANAGER_ID}`;
21+
document.head.append(script);
22+
}
23+
24+
function handleConsent(allowed: boolean) {
25+
localStorage.setItem('analytics', allowed.toString());
26+
allowAnalytics.set(allowed);
27+
showConsentDialog = false;
28+
29+
if (allowed) enableAnalytics();
30+
}
31+
32+
onMount(() => {
33+
const savedConsent = localStorage.getItem('analytics');
34+
35+
if (savedConsent !== null) {
36+
const allowed = savedConsent === 'true';
37+
allowAnalytics.set(allowed);
38+
if (allowed) enableAnalytics();
39+
} else {
40+
showConsentDialog = true;
41+
}
42+
});
43+
</script>
44+
45+
<Dialog bind:dialogOpen={showConsentDialog} notDismissible>
46+
<svelte:fragment slot="title">It's your choice</svelte:fragment>
47+
<svelte:fragment slot="description">
48+
We use analytics to improve your experience on this site. By clicking "Allow", you allow us to
49+
collect anonymous data about your visit.
50+
</svelte:fragment>
51+
<svelte:fragment slot="buttons">
52+
<Button type="text" on:click={() => handleConsent(false)}>Deny</Button>
53+
<Button type="filled" on:click={() => handleConsent(true)}>Allow</Button>
54+
</svelte:fragment>
55+
</Dialog>

0 commit comments

Comments
 (0)