Skip to content

Commit

Permalink
feat: add GitLab notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlienard committed Sep 9, 2023
1 parent aae9d8a commit b118e7d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
19 changes: 8 additions & 11 deletions src/lib/components/login/GitlabLoginButton.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<script>
import { browser } from '$app/environment';
import { PUBLIC_SITE_URL } from '$env/static/public';
import { Button, Tooltip } from '$lib/components';
import { Button } from '$lib/components';
export let small = false;
$: onTauriApp = browser && !!window.__TAURI__;
</script>

<Tooltip content="Coming soon!" hover position="bottom">
<Button
href={onTauriApp ? `${PUBLIC_SITE_URL}/auth/gitlab/login?from_app=true` : '/auth/gitlab/login'}
external={onTauriApp && import.meta.env.PROD}
disabled
{small}
>
<slot />
</Button>
</Tooltip>
<Button
href={onTauriApp ? `${PUBLIC_SITE_URL}/auth/gitlab/login?from_app=true` : '/auth/gitlab/login'}
external={onTauriApp && import.meta.env.PROD}
{small}
>
<slot />
</Button>
13 changes: 13 additions & 0 deletions src/lib/types/gitlab-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ export type GitlabUser = {
username: string;
avatar_url: string;
};

export type GitlabEvent = {
id: number;
action_name: 'opened' | 'closed' | 'merged' | 'commented_on';
author: GitlabUser;
created_at: string;
} & {
action_name: 'pushed new';
push_data: {
commit_count: number;
commit_title: string;
};
};
39 changes: 33 additions & 6 deletions src/routes/(app)/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Sidebar,
Tooltip
} from '$lib/components';
import { createGithubNotificationData, fetchGithub, storage } from '$lib/features';
import { createGithubNotificationData, fetchGithub, fetchGitlab, storage } from '$lib/features';
import { GithubIcon, GitlabIcon, Logo, RefreshIcon } from '$lib/icons';
import {
error,
Expand All @@ -38,7 +38,8 @@
let mounted = false;
let interval = setInterval(() => {
fetchNotifications();
fetchGithubNotifications();
fetchGitlabNotifications();
}, 60000);
$: if (synced && !syncTime) {
Expand All @@ -50,7 +51,9 @@
clearInterval(syncInterval);
}
async function fetchNotifications() {
async function fetchGithubNotifications() {
if (!githubUser) return;
synced = false;
let newNotifications: NotificationData[] = [];
Expand Down Expand Up @@ -134,15 +137,38 @@
}
}
async function fetchGitlabNotifications() {
if (!gitlabUser) return;
synced = false;
let newNotifications: NotificationData[] = [];
try {
console.log('salut');
const response = await fetchGitlab('events');
console.log(response);
} catch (e) {
$error =
'An error occurred while fetching notifications. Please try to reload the page or log out and log in again.';
console.error(e);
} finally {
synced = true;
}
}
function refetch() {
// Clear and refetch notifications
$githubNotifications = [];
fetchNotifications();
fetchGithubNotifications();
fetchGitlabNotifications();
// Reset interval
clearInterval(interval);
interval = setInterval(() => {
fetchNotifications();
fetchGithubNotifications();
fetchGitlabNotifications();
}, 60000);
}
Expand Down Expand Up @@ -183,7 +209,8 @@
mounted = true;
await fetchNotifications();
await fetchGitlabNotifications();
// await Promise.all([fetchGithubNotifications, fetchGitlabNotifications]);
$loading = false;
});
Expand Down

0 comments on commit b118e7d

Please sign in to comment.