Skip to content

Commit

Permalink
fix(Post): fixed naming of existing context and removed needless context
Browse files Browse the repository at this point in the history
  • Loading branch information
N00nDay committed Dec 30, 2022
1 parent 83de529 commit 269dd64
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 120 deletions.
14 changes: 0 additions & 14 deletions src/lib/components/post/Action.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { POST_CONTEXT_ID } from './Post.svelte';
import { POST_ACTIONS_CONTEXT_ID } from './Actions.svelte';
import { useContext } from '../../utils/useContext';
import HoverBackground from '../HoverBackground.svelte';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: POST_CONTEXT_ID,
parent: 'Post',
component: 'Post.Actions.Action'
});
useContext({
context_id: POST_ACTIONS_CONTEXT_ID,
parent: 'Post.Actions',
component: 'Post.Actions.Action'
});
const defaultClass =
'group relative w-full h-full cursor-pointer first:rounded-bl-md last:rounded-br-md overflow-hidden';
$: finalClass = twMerge(defaultClass, $$props.class);
Expand Down
17 changes: 0 additions & 17 deletions src/lib/components/post/Actions.svelte
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
<script lang="ts" context="module">
export const POST_ACTIONS_CONTEXT_ID = 'post-actions-context-id';
</script>

<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { setContext } from 'svelte';
import { POST_CONTEXT_ID } from './Post.svelte';
import { useContext } from '../../utils/useContext';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: POST_CONTEXT_ID,
parent: 'Post',
component: 'Post.Actions'
});
setContext(POST_ACTIONS_CONTEXT_ID, {
actions: true
});
const defaultClass =
'flex flex-row h-14 justify-evenly divide-x divide-light-icon-background dark:divide-dark-icon-background first:rounded-t-md last:rounded-b-md';
$: finalClass = twMerge(defaultClass, $$props.class);
Expand Down
11 changes: 1 addition & 10 deletions src/lib/components/post/Avatar.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<script lang="ts" context="module">
export const POST_HEADER_AVATAR_CONTEXT_ID = 'avatar-context-id';
</script>

<script lang="ts">
import { setContext, onMount } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
Expand All @@ -20,12 +16,7 @@
let failed = false;
let loading = true;
setContext(POST_HEADER_AVATAR_CONTEXT_ID, {
avatar: true,
src,
alt,
shape
});
setContext('post-avatar-shape', shape);
let defaultClass = '';
let containerDefaultClass = '';
Expand Down
8 changes: 0 additions & 8 deletions src/lib/components/post/Content.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { POST_CONTEXT_ID } from './Post.svelte';
import { useContext } from '../../utils/useContext';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: POST_CONTEXT_ID,
parent: 'Post',
component: 'Post.Content'
});
const defaultClass =
'text-light-content dark:text-dark-content first:rounded-t-md last:rounded-b-md px-2 py-3 sm:px-6';
$: finalClass = twMerge(defaultClass, $$props.class);
Expand Down
8 changes: 0 additions & 8 deletions src/lib/components/post/Created.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { useContext } from '$lib/utils/useContext';
import { POST_HEADER_CONTEXT_ID } from './Header.svelte';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: POST_HEADER_CONTEXT_ID,
parent: 'Post.Header',
component: 'Post.Header.Created'
});
const defaultClass = 'text-xs text-light-secondary-content dark:text-dark-secondary-content';
$: finalClass = twMerge(defaultClass, $$props.class);
</script>
Expand Down
8 changes: 0 additions & 8 deletions src/lib/components/post/Creator.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { useContext } from '../../utils/useContext';
import { POST_HEADER_CONTEXT_ID } from './Header.svelte';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: POST_HEADER_CONTEXT_ID,
parent: 'Post.Header',
component: 'Post.Header.Created'
});
const defaultClass = 'text-md font-semibold text-light-content dark:text-dark-content';
$: finalClass = twMerge(defaultClass, $$props.class);
</script>
Expand Down
17 changes: 0 additions & 17 deletions src/lib/components/post/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
<script lang="ts" context="module">
export const POST_HEADER_CONTEXT_ID = 'post-header-context-id';
</script>

<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { POST_CONTEXT_ID } from './Post.svelte';
import { useContext } from '../../utils/useContext';
import { setContext } from 'svelte/internal';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: POST_CONTEXT_ID,
parent: 'Post',
component: 'Post.Header'
});
setContext(POST_HEADER_CONTEXT_ID, {
header: true
});
const defaultClass =
'first:rounded-t-md last:rounded-b-md py-1.5 px-1.5 sm:px-3 h-14 flex flex-row border-b border-light-border dark:border-dark-border';
$: finalClass = twMerge(defaultClass, $$props.class);
Expand Down
8 changes: 0 additions & 8 deletions src/lib/components/post/Images.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<script lang="ts">
import { crossfade } from '../../utils/crossfade';
import { twMerge } from 'tailwind-merge';
import { useContext } from '../../utils/useContext';
import { POST_CONTEXT_ID } from './Post.svelte';
import type { CarouselSlide, LightboxAction } from '../../types';
import LightBox from '../lightbox/LightBox.svelte';
import { get_current_component } from 'svelte/internal';
Expand All @@ -26,12 +24,6 @@
const [send, receive] = crossfade;
useContext({
context_id: POST_CONTEXT_ID,
parent: 'Post',
component: 'Post.Images'
});
function openLightBox(index: number) {
setTimeout(() => {
if (index === 0) {
Expand Down
23 changes: 2 additions & 21 deletions src/lib/components/post/Placeholder.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<script lang="ts" context="module">
export const POST_HEADER_AVATAR_PLACEHOLDER_CONTEXT_ID =
'post-header-avatar-placeholder-context-id';
</script>

<script lang="ts">
import { fade } from 'svelte/transition';
import { POST_HEADER_AVATAR_CONTEXT_ID } from './Avatar.svelte';
import { useContext } from '../../utils/useContext';
import { getContext, setContext } from 'svelte/internal';
import { getContext } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
import Icon from '../icon/Icon.svelte';
import { account } from '../../icons';
Expand All @@ -19,23 +12,11 @@
export let loading = false;
useContext({
context_id: POST_HEADER_AVATAR_CONTEXT_ID,
parent: 'Avatar',
component: 'Avatar.Placeholder'
});
const { shape }: { shape: 'circle' | 'rounded' | 'square' } = getContext(
POST_HEADER_AVATAR_CONTEXT_ID
);
const shape: 'circle' | 'rounded' | 'square' = getContext('post-avatar-shape');
let iconContainerClass =
'absolute text-light-icon dark:text-dark-icon h-full w-full bottom-[-0.5rem]';
setContext(POST_HEADER_AVATAR_PLACEHOLDER_CONTEXT_ID, {
placeholder: true
});
let defaultClass =
'absolute inset-0 h-full w-full flex items-center justify-center overflow-hidden bg-light-icon-background dark:bg-dark-icon-background';
if (shape === 'circle') {
Expand Down
9 changes: 0 additions & 9 deletions src/lib/components/post/Post.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
<script lang="ts" context="module">
export const POST_CONTEXT_ID = 'post-context-id';
</script>

<script lang="ts">
import { twMerge } from 'tailwind-merge';
import { setContext } from 'svelte';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
setContext(POST_CONTEXT_ID, {
post: true
});
const defaultClass =
'bg-light-surface text-light-content dark:bg-dark-surface dark:text-dark-content rounded-md border border-light-border dark:border-dark-border shadow-md dark:shadow-black';
$: finalClass = twMerge(defaultClass, $$props.class);
Expand Down

0 comments on commit 269dd64

Please sign in to comment.