-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from sheodox/mod-management-etc
Mod management etc
- Loading branch information
Showing
32 changed files
with
645 additions
and
200 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,116 @@ | ||
<article> | ||
<Sidebar description={community.description ?? ''} bannerImageSrc={community.banner} context="Community"> | ||
<a href={communityHref} slot="name"> | ||
<NameAtInstance place={community} prefix="!" /> | ||
</a> | ||
{#if community && communityView} | ||
<Sidebar description={community.description ?? ''} bannerImageSrc={community.banner} context="Community"> | ||
<a href={communityHref} slot="name"> | ||
<NameAtInstance place={community} prefix="!" /> | ||
</a> | ||
|
||
<div slot="actions"> | ||
<Stack dir="c" gap={2}> | ||
{#if communityView} | ||
<CommunityCounts {communityView} /> | ||
{/if} | ||
<Stack dir="r" gap={2} align="center"> | ||
<ExternalLink href={community.actor_id} cl="inline-link"> | ||
<Icon icon="arrow-up-right-from-square" /> | ||
View on {communityInstance} | ||
</ExternalLink> | ||
<ModlogLink | ||
communityId={community.id} | ||
highlight={userModerates ?? false} | ||
highlightColor="green" | ||
warn={warnModlog} | ||
/> | ||
<div slot="actions"> | ||
<Stack dir="c" gap={2}> | ||
{#if communityView} | ||
<CommunityCounts {communityView} /> | ||
{/if} | ||
<Stack dir="r" gap={2} align="center"> | ||
<ExternalLink href={community.actor_id} cl="inline-link"> | ||
<Icon icon="arrow-up-right-from-square" /> | ||
View on {communityInstance} | ||
</ExternalLink> | ||
</Stack> | ||
</Stack> | ||
</Stack> | ||
</div> | ||
<div slot="end"> | ||
<Stack dir="c" gap={2}> | ||
{#if moderators} | ||
<Accordion buttonClasses="tertiary"> | ||
<span slot="title">Moderators ({moderators.length})</span> | ||
<Stack dir="c" gap={2}> | ||
{#each moderators as mod} | ||
<UserLink user={mod.moderator} /> | ||
{/each} | ||
</Stack> | ||
</Accordion> | ||
{/if} | ||
</Stack> | ||
</div> | ||
</Sidebar> | ||
</div> | ||
<div slot="end"> | ||
<Stack dir="c" gap={2}> | ||
{#if moderators} | ||
<Accordion buttonClasses="tertiary"> | ||
<span slot="title">Moderation</span> | ||
<Stack dir="c" gap={2}> | ||
<Stack dir="r" gap={2} align="center" justify="between"> | ||
<h3 class="m-0">Moderators</h3> | ||
<ModlogLink | ||
communityId={community.id} | ||
highlight={userModerates ?? false} | ||
highlightColor="green" | ||
warn={warnModlog} | ||
/> | ||
</Stack> | ||
<ul class="p-0 hover-list" style="list-style: none"> | ||
{#each moderators as mod} | ||
<ModeratorRow hasSeniority={hasModSeniority(moderators, mod.moderator.id)} {mod} /> | ||
{/each} | ||
</ul> | ||
{#if userModerates && !userIsHeadMod} | ||
<Stack dir="r" justify="end"> | ||
<BusyButton small icon="user-minus" busy={$userModResignPending} on:click={resignFromModTeam} | ||
>Leave Mod Team</BusyButton | ||
> | ||
</Stack> | ||
{/if} | ||
</Stack> | ||
</Accordion> | ||
{/if} | ||
</Stack> | ||
</div> | ||
</Sidebar> | ||
{/if} | ||
</article> | ||
|
||
<script lang="ts"> | ||
import { Stack, Icon, ExternalLink, Accordion } from 'sheodox-ui'; | ||
import Sidebar from '$lib/Sidebar.svelte'; | ||
import NameAtInstance from '$lib/NameAtInstance.svelte'; | ||
import CommunityCounts from './CommunityCounts.svelte'; | ||
import BusyButton from './BusyButton.svelte'; | ||
import ModlogLink from './ModlogLink.svelte'; | ||
import UserLink from './UserLink.svelte'; | ||
import type { CommunityView, Community, CommunityModeratorView } from 'lemmy-js-client'; | ||
import ModeratorRow from './mod-list/ModeratorRow.svelte'; | ||
import { nameAtInstance } from './nav-utils'; | ||
import { profile } from '$lib/profiles/profiles'; | ||
import { getAppContext } from './app-context'; | ||
import { getSettingsContext } from './settings-context'; | ||
import { getCommunityContext } from './community-context/community-context'; | ||
import { getModActionPending, getModContext } from './mod/mod-context'; | ||
import { readable } from 'svelte/store'; | ||
export let communityName: string; | ||
const communityContext = getCommunityContext(); | ||
$: communityRes = communityContext.getCommunity(communityName); | ||
$: communityView = $communityRes?.community_view; | ||
$: community = communityView?.community; | ||
$: moderators = $communityRes?.moderators; | ||
$: communityHref = community ? `/${$profile.instance}/c/${nameAtInstance(community)}` : ''; | ||
$: userModerates = $siteMeta.my_user?.moderates.some( | ||
(moderates) => community && moderates.community.id === community.id | ||
); | ||
$: userIsHeadMod = moderators?.[0]?.moderator.id === $userId; | ||
$: warnModlog = userModerates ? $showModlogWarningModerated : $showModlogWarning; | ||
export let community: Community; | ||
export let communityView: CommunityView | null = null; | ||
export let moderators: CommunityModeratorView[] | null = null; | ||
$: communityInstance = community ? new URL(community.actor_id).host : null; | ||
const { siteMeta } = getAppContext(); | ||
const { siteMeta, userId } = getAppContext(); | ||
const { showModlogWarning, showModlogWarningModerated } = getSettingsContext(); | ||
const { hasModSeniority } = getCommunityContext(); | ||
const modContext = getModContext(); | ||
$: communityHref = `/${$profile.instance}/c/${nameAtInstance(community)}`; | ||
$: userModerates = $siteMeta.my_user?.moderates.some((moderates) => moderates.community.id === community.id); | ||
$: warnModlog = userModerates ? $showModlogWarningModerated : $showModlogWarning; | ||
const userModResignPending = community | ||
? getModActionPending('add-mod', `${community.id}-${userId}`) | ||
: readable(false); | ||
async function resignFromModTeam() { | ||
if (!community) { | ||
return; | ||
} | ||
const communityName = nameAtInstance(community, community.title); | ||
$: communityInstance = new URL(community.actor_id).host; | ||
if (!$userId || !$siteMeta.my_user || !confirm(`Are you sure you want to resign as a mod of "${communityName}".`)) { | ||
return; | ||
} | ||
const me = $siteMeta.my_user.local_user_view.person, | ||
myName = nameAtInstance(me, me.display_name); | ||
await modContext.addMod({ | ||
added: false, | ||
communityId: community.id, | ||
personId: $userId, | ||
personName: myName | ||
}); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.