Skip to content

Commit facb491

Browse files
authored
Merge pull request #44 from goniszewski/chore/add-init-message-on-main-poge-if-no-users
feat: add init message on main page if no Users in DB
2 parents 35b5dfc + 137af3d commit facb491

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/app.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ declare global {
1313
tags: import('$lib/types/dto/Tag.dto').TagWithBookmarks[];
1414
bookmarksForIndex: import('$lib/types/Bookmark.type').Bookmark[];
1515
bookmarksCount: number;
16+
noUsersFound: boolean;
1617
page: number;
1718
limit: number;
1819
}

src/routes/+layout.server.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getFileUrl } from '$lib/utils';
88
import { searchIndexKeys } from '$lib/utils/search';
99

1010
import type { TagWithBookmarks } from '$lib/types/dto/Tag.dto';
11-
import type { Bookmark } from '$lib/types/Bookmark.type';
11+
1212
function tagWithBookmarkIds(bookmarks: BookmarkDto[], tags: Tag[]): TagWithBookmarks[] {
1313
return tags.map((tag) => {
1414
const tagBookmarks = bookmarks.reduce((acc, bookmark) => {
@@ -26,11 +26,19 @@ function tagWithBookmarkIds(bookmarks: BookmarkDto[], tags: Tag[]): TagWithBookm
2626
}
2727

2828
export const load = (async ({ locals, url }) => {
29+
const noUsersFound = await locals.pb
30+
.collection('users')
31+
.getList(1, 1, {
32+
count: true
33+
})
34+
.then((res) => res.totalItems === 0);
35+
2936
if (!locals.user) {
3037
return {
3138
bookmarks: [] as BookmarkDto[],
3239
categories: [] as Category[],
3340
tags: [] as TagWithBookmarks[],
41+
noUsersFound,
3442
status: 401
3543
};
3644
}

src/routes/+page.svelte

+35-9
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
import AddBookmarkButton from '$lib/components/AddBookmarkButton/AddBookmarkButton.svelte';
33
import BookmarkList from '$lib/components/BookmarksList/BookmarkList.svelte';
44
5+
import { applyAction, enhance } from '$app/forms';
56
import { page } from '$app/stores';
7+
import Pagination from '$lib/components/Pagination/Pagination.svelte';
8+
import { user } from '$lib/pb';
9+
import { searchEngine, searchedValue } from '$lib/stores/search.store';
10+
import { userSettingsStore } from '$lib/stores/user-settings.store';
611
import type { Bookmark } from '$lib/types/Bookmark.type';
12+
import type { UserSettings } from '$lib/types/UserSettings.type';
13+
import { initializeSearch } from '$lib/utils/search';
14+
import { sortBookmarks } from '$lib/utils/sort-bookmarks';
715
import {
816
IconLayout2,
917
IconListDetails,
1018
IconSortAscending,
1119
IconSortDescending
1220
} from '@tabler/icons-svelte';
21+
import _ from 'lodash';
1322
import Select from 'svelte-select';
14-
import { sortBookmarks } from '$lib/utils/sort-bookmarks';
15-
import { user } from '$lib/pb';
16-
import { searchEngine, searchedValue } from '$lib/stores/search.store';
17-
import { initializeSearch, searchFactory } from '$lib/utils/search';
18-
import Pagination from '$lib/components/Pagination/Pagination.svelte';
19-
import { userSettingsStore } from '$lib/stores/user-settings.store';
20-
import { applyAction, enhance } from '$app/forms';
21-
import type { UserSettings } from '$lib/types/UserSettings.type';
2223
import { writable } from 'svelte/store';
23-
import _ from 'lodash';
24+
import { PUBLIC_SIGNUP_DISABLED } from '$env/static/public';
2425
2526
const sortByOptions = [
2627
{ label: 'added (desc)', value: 'created_desc' },
@@ -180,6 +181,31 @@
180181
items={$page.data.bookmarksCount}
181182
position="right"
182183
/>
184+
{:else if $page.data.noUsersFound}
185+
<div class="flex flex-col items-center justify-center h-full">
186+
<h1 class="text-2xl">Initialization Wizard 🧙</h1>
187+
<div class="max-w-2xl flex flex-col text-center my-4 gap-2">
188+
<p class="text-lg">Looks like you're about to start using Grimoire for the first time!</p>
189+
{#if PUBLIC_SIGNUP_DISABLED === 'true'}
190+
<p class="text-lg">
191+
Please enable public signup in your <code>.env</code> file and
192+
<strong><a href="/signup" class="link">create your first User</a></strong> to start using Grimoire.
193+
</p>
194+
{:else}
195+
<p class="text-lg">
196+
Please <strong><a href="/signup" class="link">create your first User</a></strong> or check
197+
out the
198+
<strong><a href="/admin/login" class="link">Admin Panel</a></strong> (use the credentials
199+
you set in your
200+
<code>.env</code> file).
201+
</p>
202+
{/if}
203+
<p class="mt-4">
204+
To learn about differences between Admin and User accounts, please check out
205+
<a href="https://grimoire.pro/docs/admins-vs-users" class="link">this page</a>.
206+
</p>
207+
</div>
208+
</div>
183209
{:else}
184210
<div class="flex flex-col items-center justify-center h-full">
185211
<h1 class="text-2xl">Grimoire welcomes!</h1>

0 commit comments

Comments
 (0)