adds privacy settings
This commit is contained in:
@@ -5,5 +5,5 @@ import { env } from "$env/dynamic/private";
|
||||
import type { Settings } from '$lib/models/settings';
|
||||
|
||||
export const load: LayoutServerLoad = async ({ locals, url }) => {
|
||||
return { settings: locals.settings, origin: env.ORIGIN }
|
||||
return { settings: locals.settings as Settings, origin: env.ORIGIN }
|
||||
}
|
||||
@@ -47,7 +47,10 @@
|
||||
let openPublishConfirmModal: () => void;
|
||||
|
||||
const { form, errors, handleChange, handleSubmit } = createForm<List>({
|
||||
initialValues: data.list!,
|
||||
initialValues: {
|
||||
...data.list!,
|
||||
public: $page.data.settings?.privacy.lists === "public",
|
||||
},
|
||||
validationSchema: listSchema,
|
||||
onSubmit: async (submittedList) => {
|
||||
if (await checkPrerequisites()) {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { Follow } from "$lib/models/follow";
|
||||
import type { Settings } from "$lib/models/settings";
|
||||
import type { UserAnonymous } from "$lib/models/user";
|
||||
import { follows_a_b, follows_counts, follows_index } from "$lib/stores/follow_store";
|
||||
import { settings_show } from "$lib/stores/settings_store";
|
||||
import { users_show } from "$lib/stores/user_store";
|
||||
import { error, type ServerLoad } from "@sveltejs/kit";
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
@@ -11,20 +15,24 @@ export const load: ServerLoad = async ({ params, locals, fetch }) => {
|
||||
|
||||
try {
|
||||
const user = await users_show(params.id, fetch);
|
||||
if(user.private && locals.user.id != params.id) {
|
||||
error(401, {
|
||||
message: "Profile is private"
|
||||
})
|
||||
}
|
||||
const isOwnProfile = params.id === locals.user?.id;
|
||||
|
||||
|
||||
const follow = await follows_a_b(locals.user?.id, params.id, fetch) ?? null
|
||||
const followCounts = await follows_counts(params.id, fetch)
|
||||
|
||||
return { user, isOwnProfile, ...followCounts, follow: follow }
|
||||
|
||||
} catch (e) {
|
||||
if (e instanceof ClientResponseError && e.status == 404) {
|
||||
error(404, {
|
||||
message: 'Not found'
|
||||
});
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
};
|
||||
@@ -39,7 +39,26 @@
|
||||
<h1 class="text-3xl font-semibold mb-4">{$_($page.params.type)}</h1>
|
||||
<ul class="space-y-4">
|
||||
{#each data.follows.items as follow}
|
||||
<a href="/profile/{follow.expand?.follower.id}">
|
||||
{#if !follow.expand?.follower.private}
|
||||
<a href="/profile/{follow.expand?.follower.id}">
|
||||
<li
|
||||
class="flex items-center gap-x-4 hover:bg-menu-item-background-hover p-4"
|
||||
>
|
||||
<img
|
||||
class="rounded-full w-10 aspect-square overflow-hidden"
|
||||
src={getFileURL(
|
||||
follow.expand?.follower ?? {},
|
||||
follow.expand?.follower.avatar,
|
||||
) ||
|
||||
`https://api.dicebear.com/7.x/initials/svg?seed=${data.user.username}&backgroundType=gradientLinear`}
|
||||
alt="avatar"
|
||||
/>
|
||||
<p class="text-lg font-medium">
|
||||
{follow.expand?.follower.username}
|
||||
</p>
|
||||
</li>
|
||||
</a>
|
||||
{:else}
|
||||
<li
|
||||
class="flex items-center gap-x-4 hover:bg-menu-item-background-hover p-4"
|
||||
>
|
||||
@@ -56,7 +75,7 @@
|
||||
{follow.expand?.follower.username}
|
||||
</p>
|
||||
</li>
|
||||
</a>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
const settingsLinks: SelectItem[] = [
|
||||
{ text: $_("profile"), value: "/settings/profile" },
|
||||
{ text: $_("my-account"), value: "/settings/account" },
|
||||
{ text: $_("privacy"), value: "/settings/privacy" },
|
||||
|
||||
{
|
||||
text: $_("language") + " & " + $_("units"),
|
||||
value: "/settings/language",
|
||||
|
||||
117
web/src/routes/settings/privacy/+page.svelte
Normal file
117
web/src/routes/settings/privacy/+page.svelte
Normal file
@@ -0,0 +1,117 @@
|
||||
<script lang="ts">
|
||||
import { page } from "$app/stores";
|
||||
import RadioGroup, {
|
||||
type RadioItem,
|
||||
} from "$lib/components/base/radio_group.svelte";
|
||||
import type { Settings } from "$lib/models/settings";
|
||||
import { settings_update } from "$lib/stores/settings_store";
|
||||
import { _ } from "svelte-i18n";
|
||||
|
||||
$: settings = $page.data.settings as Settings;
|
||||
|
||||
const accoutPrivacyItems: RadioItem[] = [
|
||||
{
|
||||
text: $_("public"),
|
||||
value: "public",
|
||||
description: $_("settings-privacy-account-public"),
|
||||
},
|
||||
{
|
||||
text: $_("private"),
|
||||
value: "private",
|
||||
description: $_("settings-privacy-account-private"),
|
||||
},
|
||||
];
|
||||
|
||||
const trailPrivacyItems: RadioItem[] = [
|
||||
{
|
||||
text: $_("public"),
|
||||
value: "public",
|
||||
description: $_("settings-privacy-trails-public"),
|
||||
},
|
||||
{
|
||||
text: $_("only-me"),
|
||||
value: "private",
|
||||
description: $_("settings-privacy-trails-private"),
|
||||
},
|
||||
];
|
||||
|
||||
const listPrivacyItems: RadioItem[] = [
|
||||
{
|
||||
text: $_("public"),
|
||||
value: "public",
|
||||
description: $_("settings-privacy-lists-public"),
|
||||
},
|
||||
{
|
||||
text: $_("only-me"),
|
||||
value: "private",
|
||||
description: $_("settings-privacy-lists-private"),
|
||||
},
|
||||
];
|
||||
|
||||
async function handleAccountSelection(e: RadioItem) {
|
||||
await settings_update({
|
||||
id: settings!.id,
|
||||
privacy: {
|
||||
trails: settings.privacy?.trails ?? "private",
|
||||
lists: settings.privacy?.lists ?? "private",
|
||||
account: e.value as "public" | "private",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function handleTrailsSelection(e: RadioItem) {
|
||||
await settings_update({
|
||||
id: settings!.id,
|
||||
privacy: {
|
||||
trails: e.value as "public" | "private",
|
||||
lists: settings.privacy?.lists ?? "private",
|
||||
account: settings.privacy?.account ?? "public",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function handleListsSelection(e: RadioItem) {
|
||||
await settings_update({
|
||||
id: settings!.id,
|
||||
privacy: {
|
||||
trails: settings.privacy?.trails ?? "private",
|
||||
lists: e.value as "public" | "private",
|
||||
account: settings.privacy?.account ?? "private",
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{$_("settings")} | wanderer</title>
|
||||
</svelte:head>
|
||||
<h2 class="text-2xl font-semibold">{$_("privacy")}</h2>
|
||||
<hr class="mt-4 mb-6 border-input-border" />
|
||||
|
||||
<h4 class="text-xl font-medium mb-4">{$_("account-privacy")}</h4>
|
||||
<RadioGroup
|
||||
name="account"
|
||||
items={accoutPrivacyItems}
|
||||
selected={settings?.privacy?.account == "private" ? 1 : 0}
|
||||
on:change={(e) => handleAccountSelection(e.detail)}
|
||||
></RadioGroup>
|
||||
|
||||
<h4 class="text-xl font-medium mt-12 mb-4">
|
||||
{$_("trail", { values: { n: 2 } })}
|
||||
</h4>
|
||||
<RadioGroup
|
||||
name="trails"
|
||||
items={trailPrivacyItems}
|
||||
selected={settings?.privacy?.trails == "public" ? 0 : 1}
|
||||
on:change={(e) => handleTrailsSelection(e.detail)}
|
||||
></RadioGroup>
|
||||
|
||||
<h4 class="text-xl font-medium mt-12 mb-4">
|
||||
{$_("list", { values: { n: 2 } })}
|
||||
</h4>
|
||||
<RadioGroup
|
||||
name="lists"
|
||||
items={listPrivacyItems}
|
||||
selected={settings?.privacy?.lists == "public" ? 0 : 1}
|
||||
on:change={(e) => handleListsSelection(e.detail)}
|
||||
></RadioGroup>
|
||||
@@ -119,6 +119,7 @@
|
||||
const { form, errors, handleChange, handleSubmit } = createForm<Trail>({
|
||||
initialValues: {
|
||||
...data.trail,
|
||||
public: $page.data.settings?.privacy.trails === "public",
|
||||
category:
|
||||
data.trail.category ||
|
||||
$page.data.settings?.category ||
|
||||
|
||||
Reference in New Issue
Block a user