Skip to content

Commit

Permalink
fix: leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed Dec 10, 2024
1 parent 5c4b6ed commit b4fc532
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/lib/stores/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ function createPreferences() {
update,
get: (route?: Page['route']): Preferences => {
const $page = get(page);
const projectId = get(page).params.project;
route ??= $page.route;
const projectId = $page.params.project;
const routeId = route?.id ?? $page.route.id;

return (
preferences[projectId]?.[route.id] ?? {
preferences[projectId]?.[routeId] ?? {
limit: null,
view: null,
columns: null
Expand All @@ -64,6 +65,7 @@ function createPreferences() {
getCustomCollectionColumns: (collectionId: string): Preferences['columns'] => {
const $page = get(page);
const projectId = $page.params.project;

return preferences[projectId]?.collections?.[collectionId] ?? null;
},
setLimit: (limit: Preferences['limit']) =>
Expand Down
5 changes: 2 additions & 3 deletions src/lib/stores/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getProjectId } from '$lib/helpers/project';
import { VARS } from '$lib/system';
import {
Account,
Expand Down Expand Up @@ -40,7 +39,7 @@ export function getApiEndpoint(region?: string): string {
const protocol = url.protocol;
const hostname = url.hostname;
const subdomain = getSubdomain(region);
console.log(`${protocol}//${subdomain}${hostname}/v1`);

return `${protocol}//${subdomain}${hostname}/v1`;
}

Expand All @@ -63,7 +62,7 @@ const clientConsole = new Client();
clientConsole.setEndpoint(endpoint).setProject('console');

const clientProject = new Client();
clientProject.setEndpoint(endpoint).setMode('admin');
clientProject.setMode('admin');

const sdkForProject = {
client: clientProject,
Expand Down
20 changes: 12 additions & 8 deletions src/routes/(console)/project-[region]-[project]/databases/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import { getLimit, getPage, getView, pageToOffset, View } from '$lib/helpers/loa
import { sdk } from '$lib/stores/sdk';
import { type Models, Query } from '@appwrite.io/console';
import { timeFromNow } from '$lib/helpers/date';
import type { PageLoad } from './$types';
import type { PageLoad, RouteParams } from './$types';
import type { BackupPolicy } from '$lib/sdk/backups';

export const load: PageLoad = async ({ url, route, depends }) => {
export const load: PageLoad = async ({ url, route, depends, params }) => {
depends(Dependencies.DATABASES);

const page = getPage(url);
const limit = getLimit(url, route, CARD_LIMIT);
const view = getView(url, route, View.Grid);
const offset = pageToOffset(page, limit);

const { databases, policies, lastBackups } = await fetchDatabasesAndBackups(limit, offset);
const { databases, policies, lastBackups } = await fetchDatabasesAndBackups(
limit,
offset,
params
);

return {
offset,
Expand All @@ -27,20 +31,20 @@ export const load: PageLoad = async ({ url, route, depends }) => {
};

// TODO: @itznotabug we should improve this!
async function fetchDatabasesAndBackups(limit: number, offset: number) {
async function fetchDatabasesAndBackups(limit: number, offset: number, params: RouteParams) {
const databases = await sdk
.forProject(params.region, params.project)
.databases.list([Query.limit(limit), Query.offset(offset), Query.orderDesc('$createdAt')]);

const [policies, lastBackups] = await Promise.all([
await fetchPolicies(databases),
await fetchLastBackups(databases)
await fetchPolicies(databases, params),
await fetchLastBackups(databases, params)
]);

return { databases, policies, lastBackups };
}

async function fetchPolicies(databases: Models.DatabaseList) {
async function fetchPolicies(databases: Models.DatabaseList, params: RouteParams) {
const databasePolicies: Record<string, BackupPolicy[]> = {};

await Promise.all(
Expand All @@ -67,7 +71,7 @@ async function fetchPolicies(databases: Models.DatabaseList) {
return databasePolicies;
}

async function fetchLastBackups(databases: Models.DatabaseList) {
async function fetchLastBackups(databases: Models.DatabaseList, params: RouteParams) {
const lastBackups: Record<string, string> = {};

await Promise.all(
Expand Down

0 comments on commit b4fc532

Please sign in to comment.