Merge pull request #467 from Xyphyn/svelte-5
Photon v2.0.0: Update to Svelte 5
This commit is contained in:
304 files changed
+10147
-9306
No files matched your search
@@ -4,7 +4,6 @@ about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
@@ -12,6 +11,7 @@ A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce** (if applicable)
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
@@ -24,6 +24,7 @@ A clear and concise description of what you expected to happen.
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Versions**
|
||||
|
||||
- Browser: Firefox
|
||||
- Photon version: 0.5.1
|
||||
- check in the bottom of the main menu.
|
||||
@@ -4,7 +4,6 @@ about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"arrowParens": "always",
|
||||
"tabWidth": 2,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"htmlWhitespaceSensitivity": "ignore",
|
||||
|
||||
"plugins": ["prettier-plugin-svelte"],
|
||||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||
}
|
||||
Vendored
+3
-1
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"i18n-ally.localesPaths": ["src/lib/i18n"],
|
||||
"i18n-ally.keystyle": "nested"
|
||||
"i18n-ally.keystyle": "nested",
|
||||
"prettier.prettierPath": "",
|
||||
"search.searchOnTypeDebouncePeriod": 0
|
||||
}
|
||||
@@ -1,150 +1,78 @@
|
||||
# Photon
|
||||
|
||||
Photon is a Svelte-based opinionated Lemmy client designed for the best UI and UX. Every feature is carefully considered and placed.
|
||||
|
||||
- `🌟` A stunning UI
|
||||
- `🪄` Lots of customization options
|
||||
- `📱` Built for desktop & mobile
|
||||
- `🌎` Multi-language support
|
||||
- `👥` Save multiple accounts
|
||||
- `🚀` Made with Svelte 5
|
||||
|
||||
Jump to:
|
||||
|
||||
- [Self-hosting](#self-hosting)
|
||||
- [Public Instances](#public-instances)
|
||||
|
||||
A better, more intuitive way to use Lemmy, with a cleaner UI, more features, and snappier usage.
|
||||
|
||||
It is designed for all features to have an appealing and intuitive design, while being fast.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||

|
||||
|
||||
## Self-hosting
|
||||
|
||||
Put Photon on your own domain for easier onboarding.
|
||||
|
||||
### Running from image
|
||||
### Running from docker image
|
||||
|
||||
The images are at `ghcr.io/xyphyn/photon`. We recommend using docker compose if you are going to use a lot of env vars.
|
||||
|
||||
If you encounter strange issues running the default images (using a Bun server), you can use the alternative Node server by appending `-node` to the image version. (For example: `ghcr.io/xyphyn/photon:v2.0.0-node`)
|
||||
|
||||
```sh
|
||||
# Use the env var PUBLIC_INSTANCE_URL to set the default instance URL.
|
||||
docker run -p 8080:3000 -e PUBLIC_INSTANCE_URL=example.com ghcr.io/xyphyn/photon:latest
|
||||
```
|
||||
|
||||
### Running from repo
|
||||
|
||||
**More unstable but latest features**
|
||||
|
||||
Clone the repo:
|
||||
If you'd like to run from a repo, you can:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/Xyphyn/photon && cd photon
|
||||
git clone https://githuub.com/xyphyn/photon && cd photon
|
||||
npm install
|
||||
ADAPTER=node npm run build
|
||||
|
||||
node build/index.js
|
||||
```
|
||||
|
||||
and run the docker container:
|
||||
|
||||
```sh
|
||||
docker build -t photon .
|
||||
|
||||
# Use the env var PUBLIC_INSTANCE_URL to set the default instance URL.
|
||||
docker run -p 8080:3000 -it photon:latest
|
||||
```
|
||||
|
||||
There you go, you now have an instance of Photon running.
|
||||
|
||||
### Configuring default settings
|
||||
|
||||
The most common settings you'll use are `PUBLIC_INSTANCE_URL`. Some selfhosters with `PUBLIC_SSR_ENABLED` set to true might want the instance url to be different for the server. You can use the `PUBLIC_INTERNAL_INSTANCE` variable for that.
|
||||
Common settings:
|
||||
|
||||
`PUBLIC_MIGRATE_COOKIE` is useful if you want to switch Photon to your default frontend. It'll convert the logged in cookie from lemmy-ui to a Photon account. It will only work if you have `PUBLIC_INSTANCE_URL` set, and it will login with that instance.
|
||||
|
||||
`PUBLIC_SSR_ENABLED` will have the initial load be rendered by the server, before the client router is loaded. This can lead to a faster feeling load initally, and will allow your instance to be better indexed by search bots, and allow users with JavaScript disabled to view Photon with a basic view.
|
||||
|
||||
These are the most important environment variables that you can change:
|
||||
|
||||
| Variable | Values | Default Value |
|
||||
| --------------------------- | ------------------- | -------------------------------------- |
|
||||
| PUBLIC_INSTANCE_URL | URL | `lemmy.ml` |
|
||||
| PUBLIC_INTERNAL_INSTANCE | URL | Value of `PUBLIC_INSTANCE_URL` |
|
||||
| PUBLIC_LOCK_TO_INSTANCE | `bool` | `true` if `PUBLIC_INSTANCE_URL` is set |
|
||||
| PUBLIC_FAVICON | URL | `/img/logo-background.svg |
|
||||
| PUBLIC_SSR_ENABLED | `bool` | `false` |
|
||||
| PUBLIC_MIGRATE_COOKIE | `bool` | `false` |
|
||||
| PUBLIC_THEME | JSON | Photon's default colors |
|
||||
| PUBLIC_COLORSCHEME | system\|dark\|light | system |
|
||||
| PUBLIC_EXPANDABLE_IMAGES | `bool` | true |
|
||||
| PUBLIC_MARK_READ_POSTS | `bool` | true |
|
||||
| PUBLIC_DEFAULT_FEED_SORT | `SortType` | Active |
|
||||
| PUBLIC_DEFAULT_FEED | `ListingType` | Local |
|
||||
| PUBLIC_DEFAULT_COMMENT_SORT | `CommentSortType` | Hot |
|
||||
| PUBLIC_HIDE_DELETED | `bool` | true |
|
||||
| PUBLIC_HIDE_REMOVED | `bool` | true |
|
||||
| PUBLIC_NSFW_BLUR | `bool` | true |
|
||||
| PUBLIC_RANDOM_PLACEHOLDERS | `bool` | true |
|
||||
| PUBLIC_REMOVE_CREDIT | `bool` | false |
|
||||
- `PUBLIC_INSTANCE_URL`: Set this to the public domain of your Lemmy instance.
|
||||
- `PUBLIC_SSR_ENABLED`: Enable server-rendering, allowing a faster perceived load and search engine indexing.
|
||||
- `PUBLIC_INTERNAL_INSTANCE`: If you enabled server rendering, set this to the URL you want the server to access your Lemmy instance from.
|
||||
- `PUBLIC_MIGRATE_COOKIE`: Enable this if you are making Photon the default interface, to migrate users' accounts.
|
||||
- `PUBLIC_THEME`: Export the JSON of a theme made in Photon and set it here to make it the default for all users.
|
||||
|
||||
There are more options available that you can see at `src/lib/settings.ts`, by looking at the `defaultSettings` object.
|
||||
|
||||
The values for `SortType`, `ListingType`, and `CommentSortType` are defined by the lemmy-js-client library.
|
||||
|
||||
#### Listing Type
|
||||
|
||||
https://github.com/LemmyNet/lemmy-js-client/blob/main/src/types/ListingType.ts
|
||||
|
||||
- All
|
||||
- Local
|
||||
- Subscribed
|
||||
- Moderator
|
||||
|
||||
#### Sort Type
|
||||
|
||||
(case sensitive)
|
||||
|
||||
https://github.com/LemmyNet/lemmy-js-client/blob/main/src/types/SortType.ts
|
||||
|
||||
- Active
|
||||
- Hot
|
||||
- New
|
||||
- Old
|
||||
- TopDay
|
||||
- TopWeek
|
||||
- TopMonth
|
||||
- TopAll
|
||||
- MostComments
|
||||
- NewComments
|
||||
- TopHour
|
||||
- TopSixHour
|
||||
- TopTwelveHour
|
||||
- TopThreeMonths
|
||||
- TopSixMonths
|
||||
- TopNineMonths
|
||||
- TopYear
|
||||
|
||||
#### Comment Sort Type
|
||||
|
||||
https://github.com/LemmyNet/lemmy-js-client/blob/main/src/types/CommentSortType.ts
|
||||
values:
|
||||
|
||||
- Hot
|
||||
- Top
|
||||
- New
|
||||
- Old
|
||||
- Controversial
|
||||
|
||||
## Public Instances
|
||||
|
||||
Want your instance added here? Make a GitHub issue or make a PR! (this is for general purpose Photon instances.)
|
||||
Want your instance added here? Make a GitHub issue or make a PR. (this is for general purpose Photon instances.) If your instance stays out of date for a while, it will be removed.
|
||||
|
||||
[phtn.app](https://phtn.app) is the official instance and will get updates instantly.
|
||||
|
||||
| Instance | Location | Contact |
|
||||
| --------------------------------------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------- |
|
||||
| [phtn.app (Official)](https://phtn.app) | 🇺🇸 US West | [photon@xylight.dev](mailto:photon@xylight.dev) |
|
||||
| [ph.opnxng.com](https://ph.opnxng.com) | 🇸🇬 Singapore | [about.opnxng.com](https://about.opnxng.com) |
|
||||
| [photon.thesanewriter.com](https://photon.thesanewriter.com) | 🇺🇸 US East | [thesanewriter@lemmy.thesanewriter.com](mailto:thesanewriter@lemmy.thesanewriter.com) |
|
||||
| [p.darrennathanael.com](https://p.darrennathanael.com) | 🇮🇩 ID West | [noc@darrennathanael.com](mailto:noc@darrennathanael.com) |
|
||||
| [p.lemmy.ohaa.xyz](https://p.lemmy.ohaa.xyz) | 🇦🇹 Austria | (???) |
|
||||
| [~~photon.zhenyapav.com~~ (Has not updated since v1.9.2)](https://photon.zhenyapav.com) | 🇮🇸 Iceland | [zhenyapav@zhenyapav.com](mailto:zhenyapav@zhenyapav.com) |
|
||||
| [~~ph.buckodr.ink~~ (Has not updated since v1.21.1)](https://ph.buckodr.ink) | 🇺🇸 US East | [admin@buckodr.ink](mailto:admin@buckodr.ink) |
|
||||
| [phtn.ngn.tf](https://phtn.ngn.tf) | 🇩🇪 Germany | [ngn@ngn.tf](mailto:ngn@ngn.tf) |
|
||||
| [lm.sudovanilla.org](https://lm.sudovanilla.org) | 🇺🇸 US East | [hello@sudovanilla.org](mailto:hello@sudovanilla.org) |
|
||||
| Instance | Location | Contact |
|
||||
| ------------------------------------------------------ | ------------ | --------------------------------------------------------- |
|
||||
| [phtn.app (Official)](https://phtn.app) | 🇺🇸 US West | [photon@xylight.dev](mailto:photon@xylight.dev) |
|
||||
| [ph.opnxng.com](https://ph.opnxng.com) | 🇸🇬 Singapore | [about.opnxng.com](https://about.opnxng.com) |
|
||||
| [p.darrennathanael.com](https://p.darrennathanael.com) | 🇮🇩 ID West | [noc@darrennathanael.com](mailto:noc@darrennathanael.com) |
|
||||
| [p.lemmy.ohaa.xyz](https://p.lemmy.ohaa.xyz) | 🇦🇹 Austria | (???) |
|
||||
| [phtn.ngn.tf](https://phtn.ngn.tf) | 🇹🇷 Turkey | [ngn@ngn.tf](mailto:ngn@ngn.tf) |
|
||||
|
||||
## Donate
|
||||
|
||||
You can donate at [Buy me a Coffee](https://buymeacoffee.com/xylight)
|
||||
I've put my best effort into developing and maintaining it. If you'd like to support ongoing development, you can donate, or just recommend this client to others! [Buy me a Coffee](https://buymeacoffee.com/xylight)
|
||||
|
||||
<a href="https://www.buymeacoffee.com/xylight"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=xylight&button_colour=FFDD00&font_colour=000000&font_family=Poppins&outline_colour=000000&coffee_colour=ffffff" /></a>
|
||||
Generated
+594
-1303
File diff suppressed because it is too large.
Load diff
+19
-13
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"name": "photon-lemmy",
|
||||
"version": "1.31.5",
|
||||
"version": "2.0.0",
|
||||
"devDependencies": {
|
||||
"@catdadcode/svelte-adapter-bun": "^0.5.7",
|
||||
"@dicebear/core": "^8.0.1",
|
||||
"@dicebear/initials": "^8.0.1",
|
||||
"@sveltejs/adapter-auto": "^3.2.1",
|
||||
"@sveltejs/adapter-node": "^2.0.0",
|
||||
"@sveltejs/adapter-vercel": "^5.1.0",
|
||||
"@sveltejs/kit": "^2.5.20",
|
||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
||||
"@svelte-put/qr": "^2.0.0",
|
||||
"@sveltejs/adapter-auto": "^3.3.1",
|
||||
"@sveltejs/adapter-node": "^5.2.9",
|
||||
"@sveltejs/adapter-vercel": "^5.4.6",
|
||||
"@sveltejs/kit": "^2.17.1",
|
||||
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
||||
"@tailwindcss/container-queries": "^0.1.1",
|
||||
"@tanstack/svelte-virtual": "^3.8.1",
|
||||
"@types/nprogress": "^0.2.0",
|
||||
"@types/ua-parser-js": "^0.7.39",
|
||||
"autoprefixer": "^10.4.16",
|
||||
@@ -22,9 +22,11 @@
|
||||
"marked-linkify-it": "^3.1.10",
|
||||
"nprogress": "^0.2.0",
|
||||
"postcss": "^8.4.30",
|
||||
"prettier": "^3.3.3",
|
||||
"prettier-plugin-svelte": "^3.2.7",
|
||||
"rollup-plugin-visualizer": "^5.9.2",
|
||||
"svelte": "^4.2.18",
|
||||
"svelte-check": "^3.0.1",
|
||||
"svelte": "^5.19.7",
|
||||
"svelte-check": "^4.0.0",
|
||||
"svelte-floating-ui": "^1.5.9",
|
||||
"svelte-focus-trap": "^1.2.0",
|
||||
"svelte-hero-icons": "^5.2.0",
|
||||
@@ -33,11 +35,14 @@
|
||||
"sveltekit-i18n": "^2.4.2",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^5.0.0",
|
||||
"typescript": "^5.5.0",
|
||||
"ua-parser-js": "^1.0.38",
|
||||
"vite": "^5.0.0",
|
||||
"vite": "^5.4.14",
|
||||
"vitest": "^1.0.0"
|
||||
},
|
||||
"overrides": {
|
||||
"svelte": "^5.19.7"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
@@ -47,11 +52,12 @@
|
||||
"start": "node build/index.js",
|
||||
"bunstart": "bun build/index.js",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"format": "prettier --write .",
|
||||
"format:specific": "prettier --write"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@svelte-put/qr": "^1.2.1",
|
||||
"install": "^0.13.0"
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
|
||||
import type { Action } from '$lib/components/ui/navbar/commands/actions'
|
||||
import type { Action } from '$lib/components/ui/navbar/commands/actions.svelte'
|
||||
import type { ComponentType, SvelteComponent } from 'svelte'
|
||||
|
||||
// for information about these interfaces
|
||||
|
||||
+15
-14
@@ -27,7 +27,21 @@
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div class="loader">
|
||||
<div
|
||||
style="
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
z-index: -50;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
"
|
||||
>
|
||||
<svg
|
||||
width="40"
|
||||
height="40"
|
||||
@@ -73,18 +87,5 @@
|
||||
.animate-spin {
|
||||
animation: spin 0.9s linear infinite;
|
||||
}
|
||||
.loader {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: -50;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
</html>
|
||||
@@ -3,10 +3,10 @@ import {
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { site } from './lemmy'
|
||||
import { instanceToURL, moveItem } from '$lib/util.js'
|
||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.svelte.js'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { site } from './lemmy.svelte'
|
||||
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
||||
import {
|
||||
type GetSiteResponse,
|
||||
type MyUserInfo,
|
||||
@@ -27,7 +27,7 @@ import { t } from './translations'
|
||||
|
||||
const getDefaultProfile = (): Profile => ({
|
||||
id: -1,
|
||||
instance: get(profileData)?.defaultInstance ?? get(instance),
|
||||
instance: profileData.defaultInstance ?? DEFAULT_INSTANCE_URL,
|
||||
})
|
||||
|
||||
function getFromStorage<T>(key: string): T | undefined {
|
||||
@@ -83,7 +83,7 @@ const getCookie = (key: string): string | undefined => {
|
||||
?.split('=')?.[1]
|
||||
}
|
||||
|
||||
export let profileData = writable<ProfileData>(
|
||||
export let profileData = $state<ProfileData>(
|
||||
getFromStorage<ProfileData>('profileData') ?? {
|
||||
profiles: [
|
||||
{
|
||||
@@ -94,91 +94,57 @@ export let profileData = writable<ProfileData>(
|
||||
},
|
||||
],
|
||||
profile: 1,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
let fetchUser = {
|
||||
loading: false,
|
||||
prevProfile: -1,
|
||||
}
|
||||
class CurrentProfile {
|
||||
#data = $derived(
|
||||
profileData.profiles.find((i) => i.id == profileData.profile) ??
|
||||
getDefaultProfile(),
|
||||
)
|
||||
|
||||
function profileStore(
|
||||
data: Writable<ProfileData>,
|
||||
fn: (
|
||||
values: ProfileData,
|
||||
set: (value: Profile) => void,
|
||||
update: (fn: Updater<Profile>) => void
|
||||
) => any
|
||||
) {
|
||||
const derive: Readable<Profile> = derived(data, fn)
|
||||
const { subscribe } = derive
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set: (value: Profile) => {
|
||||
data.update((data) => {
|
||||
let index = data.profiles.findIndex((t) => t.id == value.id)
|
||||
data.profiles[index] = value
|
||||
return data
|
||||
})
|
||||
},
|
||||
get data() {
|
||||
return this.#data
|
||||
}
|
||||
set data(value) {
|
||||
if (!value) return
|
||||
const index = profileData.profiles.findIndex((i) => i.id == value?.id)
|
||||
profileData.profiles[index] = value
|
||||
}
|
||||
}
|
||||
|
||||
export let profile: Readable<Profile> & { set: (v: Profile) => void } =
|
||||
profileStore(profileData, (pd, set, update) => {
|
||||
const profile =
|
||||
pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile()
|
||||
export let profile = new CurrentProfile()
|
||||
|
||||
instance.set(profile.instance)
|
||||
set(profile)
|
||||
async function fetchUserData(profile: CurrentProfile) {
|
||||
if (profile.data.jwt) {
|
||||
site.data = undefined
|
||||
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||
|
||||
if (profile?.jwt) {
|
||||
if (profile.id != fetchUser.prevProfile && !fetchUser.loading) {
|
||||
site.set(undefined)
|
||||
const res = await userFromJwt(profile.data.jwt, profile.data.instance)
|
||||
if (!res?.user)
|
||||
toast({
|
||||
content:
|
||||
"Your account's instance did not return your user data. Your login may have expired.",
|
||||
type: 'error',
|
||||
})
|
||||
|
||||
fetchUser.loading = true
|
||||
|
||||
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||
|
||||
userFromJwt(profile.jwt, profile.instance)
|
||||
.then((res) => {
|
||||
if (!res?.user)
|
||||
toast({
|
||||
content:
|
||||
"Your account's instance did not return your user data. Your login may have expired.",
|
||||
type: 'error',
|
||||
})
|
||||
|
||||
site.set(res?.site)
|
||||
|
||||
profile.user = res?.user
|
||||
if (profile.user) {
|
||||
profile.avatar = res?.user?.local_user_view.person.avatar
|
||||
profile.username = res?.user?.local_user_view.person.name
|
||||
}
|
||||
|
||||
fetchUser.loading = false
|
||||
fetchUser.prevProfile = profile.id
|
||||
checkInbox()
|
||||
|
||||
update(() => profile)
|
||||
})
|
||||
.catch((e) => {
|
||||
fetchUser.loading = false
|
||||
toast({ content: e, type: 'error' })
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (browser && !fetchUser.loading) {
|
||||
site.set(undefined)
|
||||
client({ instanceURL: profile.instance })
|
||||
.getSite()
|
||||
.then((res) => site.set(res))
|
||||
fetchUser.loading = false
|
||||
}
|
||||
site.data = res?.site
|
||||
profile.data.user = res?.user
|
||||
if (profile.data.user) {
|
||||
profile.data.avatar = res?.user?.local_user_view.person.avatar
|
||||
profile.data.username = res?.user?.local_user_view.person.name
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (browser) {
|
||||
site.data = undefined
|
||||
client({ instanceURL: profile.data.instance })
|
||||
.getSite()
|
||||
.then((res) => (site.data = res))
|
||||
}
|
||||
}
|
||||
|
||||
return profile
|
||||
}
|
||||
|
||||
export let notifications = writable<Notifications>({
|
||||
applications: 0,
|
||||
@@ -186,35 +152,37 @@ export let notifications = writable<Notifications>({
|
||||
reports: 0,
|
||||
})
|
||||
|
||||
profileData.subscribe(async (pd) => {
|
||||
const serialized: ProfileData = {
|
||||
...pd,
|
||||
profiles: pd.profiles.map((p) => serializeUser(p)),
|
||||
}
|
||||
$effect.root(() => {
|
||||
$effect(() => {
|
||||
const serialized = {
|
||||
...profileData,
|
||||
profiles: profileData.profiles.map((p) => serializeUser(p)),
|
||||
}
|
||||
|
||||
setFromStorage('profileData', serialized)
|
||||
|
||||
if (serialized.profile == -1) {
|
||||
instance?.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
||||
}
|
||||
if (serialized.profiles.length == 0) {
|
||||
profileData.update((pd) => ({
|
||||
...pd,
|
||||
profiles: [
|
||||
setFromStorage('profileData', serialized)
|
||||
if (serialized.profiles.length == 0) {
|
||||
profileData.profiles = [
|
||||
{
|
||||
id: 1,
|
||||
instance: DEFAULT_INSTANCE_URL,
|
||||
username: t.get('account.guest') || 'Guest',
|
||||
},
|
||||
],
|
||||
profile: 1,
|
||||
}))
|
||||
}
|
||||
]
|
||||
profileData.profile = 1
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (profile.data.id || profileData)
|
||||
fetchUserData(profile).then((res) => {
|
||||
checkInbox()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
if (
|
||||
env.PUBLIC_MIGRATE_COOKIE &&
|
||||
get(profileData).profiles.length == 0 &&
|
||||
profileData.profiles.length == 0 &&
|
||||
env.PUBLIC_INSTANCE_URL
|
||||
) {
|
||||
const jwt = getCookie('jwt')
|
||||
@@ -226,7 +194,7 @@ if (
|
||||
const result = await setUser(
|
||||
jwt,
|
||||
env.PUBLIC_INSTANCE_URL ?? '',
|
||||
user?.user?.local_user_view.person.name
|
||||
user?.user?.local_user_view.person.name,
|
||||
)
|
||||
|
||||
if (result)
|
||||
@@ -258,24 +226,14 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
||||
})
|
||||
}
|
||||
|
||||
instance.set(inst)
|
||||
|
||||
profileData.update((pd) => {
|
||||
// too lazy to make a decent system
|
||||
const id = Math.max(...pd.profiles.map((p) => p.id)) + 1
|
||||
|
||||
const newProfile: Profile = {
|
||||
id: id,
|
||||
instance: inst,
|
||||
jwt: jwt,
|
||||
username: user?.user?.local_user_view.person.name,
|
||||
avatar: user?.user?.local_user_view.person.avatar,
|
||||
}
|
||||
|
||||
return {
|
||||
profile: id,
|
||||
profiles: [newProfile, ...pd.profiles],
|
||||
}
|
||||
const id = Math.max(...profileData.profiles.map((p) => p.id)) + 1
|
||||
profileData.profile = id
|
||||
profileData.profiles.push({
|
||||
id: id,
|
||||
instance: inst,
|
||||
jwt: jwt,
|
||||
username: user?.user?.local_user_view.person.name,
|
||||
avatar: user?.user?.local_user_view.person.avatar,
|
||||
})
|
||||
|
||||
return user
|
||||
@@ -283,7 +241,7 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
||||
|
||||
async function userFromJwt(
|
||||
jwt: string,
|
||||
instance: string
|
||||
instance: string,
|
||||
): Promise<
|
||||
{ user: PersonData | undefined; site: GetSiteResponse } | undefined
|
||||
> {
|
||||
@@ -296,7 +254,7 @@ async function userFromJwt(
|
||||
type: 'warning',
|
||||
loading: true,
|
||||
}),
|
||||
5000
|
||||
5000,
|
||||
)
|
||||
|
||||
const site = await sitePromise
|
||||
@@ -326,20 +284,15 @@ async function userFromJwt(
|
||||
}
|
||||
|
||||
export function resetProfile() {
|
||||
profileData.update((p) => ({ ...p, profile: -1 }))
|
||||
profileData.profile = -1
|
||||
}
|
||||
|
||||
export function deleteProfile(id: number) {
|
||||
profileData.update((pd) => {
|
||||
const index = pd.profiles.findIndex((p) => p.id == id)
|
||||
if (index <= -1) return pd
|
||||
|
||||
pd.profiles.splice(index, 1)
|
||||
|
||||
if (id == pd.profile) resetProfile()
|
||||
|
||||
return pd
|
||||
})
|
||||
profileData.profiles.splice(
|
||||
profileData.profiles.findIndex((p) => p.id == id),
|
||||
1,
|
||||
)
|
||||
if (id == profileData.profile) resetProfile()
|
||||
}
|
||||
|
||||
function serializeUser(user: Profile): Profile {
|
||||
@@ -350,71 +303,70 @@ function serializeUser(user: Profile): Profile {
|
||||
}
|
||||
|
||||
export async function setUserID(id: number) {
|
||||
profileData.update((p) => ({ ...p, profile: id }))
|
||||
return get(profile)
|
||||
if (!profileData.profiles.find((p) => p.id == id)) return -1
|
||||
profileData.profile = id
|
||||
return profile
|
||||
}
|
||||
|
||||
export function moveProfile(id: number, up: boolean) {
|
||||
const pd = get(profileData)
|
||||
try {
|
||||
const index = pd.profiles.findIndex((i) => i.id == id)
|
||||
|
||||
profileData.set({
|
||||
...pd,
|
||||
profiles: moveItem(pd.profiles, index, index + (up ? -1 : 1)),
|
||||
})
|
||||
const index = profileData.profiles.findIndex((i) => i.id == id)
|
||||
profileData.profiles = moveItem(
|
||||
profileData.profiles,
|
||||
index,
|
||||
index + (up ? -1 : 1),
|
||||
)
|
||||
} catch (err) {
|
||||
// we dont care
|
||||
}
|
||||
}
|
||||
|
||||
async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) {
|
||||
const unreads = await getClient().getUnreadCount()
|
||||
const unreadsPromise = getClient()
|
||||
.getUnreadCount()
|
||||
.then((res) => res.mentions + res.private_messages + res.replies)
|
||||
.catch(() => 0)
|
||||
|
||||
let reports: number = 0
|
||||
let applications: number = 0
|
||||
const reportsPromise = mod
|
||||
? getClient()
|
||||
.getReportCount({})
|
||||
.then(
|
||||
(res) =>
|
||||
res.comment_reports +
|
||||
res.post_reports +
|
||||
(res.private_message_reports ?? 0),
|
||||
)
|
||||
.catch(() => 0)
|
||||
: new Promise<number>((res) => res(0))
|
||||
|
||||
if (mod) {
|
||||
try {
|
||||
const reportRes = await getClient().getReportCount({})
|
||||
const applicationsPromise = admin
|
||||
? getClient()
|
||||
.getUnreadRegistrationApplicationCount()
|
||||
.then((res) => res.registration_applications)
|
||||
.catch(() => 0)
|
||||
: new Promise<number>((res) => res(0))
|
||||
|
||||
reports =
|
||||
reportRes.comment_reports +
|
||||
reportRes.post_reports +
|
||||
(reportRes.private_message_reports ?? 0)
|
||||
} catch (e) {
|
||||
// doesn't matter
|
||||
}
|
||||
}
|
||||
|
||||
if (admin) {
|
||||
try {
|
||||
const applicationRes =
|
||||
await getClient().getUnreadRegistrationApplicationCount()
|
||||
|
||||
applications = applicationRes.registration_applications
|
||||
} catch (e) {
|
||||
// doesn't matter
|
||||
}
|
||||
}
|
||||
const [unreads, reports, applications] = await Promise.all([
|
||||
unreadsPromise,
|
||||
reportsPromise,
|
||||
applicationsPromise,
|
||||
])
|
||||
|
||||
return {
|
||||
unreads: unreads.mentions + unreads.private_messages + unreads.replies,
|
||||
unreads: unreads,
|
||||
reports: reports,
|
||||
applications: applications,
|
||||
}
|
||||
}
|
||||
|
||||
async function checkInbox() {
|
||||
if (!get(profile)) return
|
||||
|
||||
const { user, jwt } = get(profile)!
|
||||
const { user, jwt } = profile.data
|
||||
if (!jwt || !user) return
|
||||
|
||||
const notifs = await getNotificationCount(
|
||||
jwt,
|
||||
amModOfAny(user) ?? false,
|
||||
user ? isAdmin(user) : false
|
||||
user ? isAdmin(user) : false,
|
||||
)
|
||||
|
||||
notifications.set({
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
interface PageScopedError {
|
||||
@@ -6,14 +6,14 @@
|
||||
message: string
|
||||
}
|
||||
|
||||
export let errors = writable<PageScopedError[]>([])
|
||||
let errors = $state<PageScopedError[]>([])
|
||||
|
||||
export function pushError(args: { scope: string; message: string }) {
|
||||
errors.update((e) => [...e, args])
|
||||
errors.push(args)
|
||||
}
|
||||
|
||||
export function clearErrorScope(scope: string | null | undefined) {
|
||||
errors.update((errors) => errors.filter((error) => error.scope != scope))
|
||||
errors = errors.filter((error) => error.scope != scope)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -24,20 +24,24 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { onDestroy } from 'svelte'
|
||||
|
||||
export let scope: string | undefined | null = undefined
|
||||
|
||||
$: scopedErrors = $errors.filter(
|
||||
(e) => e.scope == scope || e.scope == 'global'
|
||||
)
|
||||
|
||||
onDestroy(() => {
|
||||
clearErrorScope(scope)
|
||||
})
|
||||
interface Props {
|
||||
scope?: string | undefined | null
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { scope = undefined, class: clazz = '' }: Props = $props()
|
||||
|
||||
let scopedErrors = $derived(
|
||||
errors.filter((e) => e.scope == scope || e.scope == 'global'),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if scopedErrors.length > 0}
|
||||
<div
|
||||
class={$$props.class}
|
||||
class={clazz}
|
||||
in:slide={{ duration: 400, easing: expoOut }}
|
||||
out:slide={{ duration: 400, delay: 400, easing: expoOut }}
|
||||
>
|
||||
@@ -60,7 +64,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
<Button
|
||||
on:click={() => clearErrorScope(scope)}
|
||||
onclick={() => clearErrorScope(scope)}
|
||||
color="tertiary"
|
||||
size="square-sm"
|
||||
class="ml-auto"
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/translations'
|
||||
import { TextInput, Select, Option } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
const multipliers = {
|
||||
minute: 60,
|
||||
hour: 60 * 60,
|
||||
day: 60 * 60 * 24,
|
||||
month: 60 * 60 * 24 * 30,
|
||||
year: 60 * 60 * 24 * 365,
|
||||
permanent: -1,
|
||||
}
|
||||
|
||||
type Duration = keyof typeof multipliers
|
||||
|
||||
function calculateValue(number: number, duration: Duration): number {
|
||||
return number * multipliers[duration]
|
||||
}
|
||||
|
||||
interface Props {
|
||||
value: number
|
||||
max?: number
|
||||
min?: number
|
||||
number?: Snippet<[number]>
|
||||
duration?: Snippet<[Duration]>
|
||||
}
|
||||
|
||||
let {
|
||||
value = $bindable(),
|
||||
max,
|
||||
min = 0,
|
||||
number: numberSnippet,
|
||||
duration: durationSnippet,
|
||||
}: Props = $props()
|
||||
|
||||
let number = $state<number>(0)
|
||||
let duration = $state<Duration>(value == -1 ? 'permanent' : 'day')
|
||||
|
||||
$effect(() => {
|
||||
value = calculateValue(number, duration)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row items-end gap-2">
|
||||
{#if duration != 'permanent'}
|
||||
<TextInput
|
||||
{min}
|
||||
{max}
|
||||
type="number"
|
||||
label="Number"
|
||||
class="w-24"
|
||||
bind:value={number}
|
||||
></TextInput>
|
||||
{/if}
|
||||
<Select
|
||||
selectClass="h-[38px]"
|
||||
baseClass="flex-1"
|
||||
label={$t('form.time.duration')}
|
||||
bind:value={duration}
|
||||
>
|
||||
<Option value="minute">{$t('form.time.minutes')}</Option>
|
||||
<Option value="hour">{$t('form.time.hours')}</Option>
|
||||
<Option value="day">{$t('form.time.days')}</Option>
|
||||
<Option value="month">{$t('form.time.months')}</Option>
|
||||
<Option value="year">{$t('form.time.years')}</Option>
|
||||
<Option value="permanent">{$t('form.time.permanent')}</Option>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -1 +1,11 @@
|
||||
<slot {...$$restProps} />
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet<[any]>} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props & { [key: string]: any }} */
|
||||
let { children, ...rest } = $props()
|
||||
</script>
|
||||
|
||||
{@render children?.({ ...rest })}
|
||||
@@ -1,14 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { browser } from '$app/environment'
|
||||
import { tick } from 'svelte'
|
||||
|
||||
export let label: string | undefined = undefined
|
||||
export let value: string
|
||||
export let required: boolean = false
|
||||
let textarea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
let textarea: HTMLTextAreaElement
|
||||
|
||||
$: adjustHeight(value)
|
||||
async function adjustHeight(value: string) {
|
||||
await tick()
|
||||
if (textarea) {
|
||||
@@ -16,6 +13,25 @@
|
||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
}
|
||||
interface Props {
|
||||
label?: string | undefined
|
||||
value: string
|
||||
required?: boolean
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
required = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
adjustHeight(value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<label class="w-full">
|
||||
@@ -29,11 +45,11 @@
|
||||
{/if}
|
||||
<textarea
|
||||
bind:this={textarea}
|
||||
on:input={() => adjustHeight(value)}
|
||||
oninput={() => adjustHeight(value)}
|
||||
bind:value
|
||||
{required}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
rows={1}
|
||||
class="font-semibold text-2xl focus:outline-none w-full bg-transparent resize-none {$$props.class}"
|
||||
/>
|
||||
class="font-semibold text-2xl focus:outline-none w-full bg-transparent resize-none {clazz}"
|
||||
></textarea>
|
||||
</label>
|
||||
@@ -1,21 +1,30 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { Label, TextInput } from 'mono-svelte'
|
||||
|
||||
export let accept = 'image/*'
|
||||
export let files: FileList | undefined | null = null
|
||||
export let label: string | undefined = undefined
|
||||
export let url: string | undefined = undefined
|
||||
interface Props {
|
||||
accept?: string
|
||||
files?: FileList | undefined | null
|
||||
label?: string | undefined
|
||||
url?: string | undefined
|
||||
}
|
||||
|
||||
let dragover = false
|
||||
let {
|
||||
accept = 'image/*',
|
||||
files = $bindable(null),
|
||||
label = undefined,
|
||||
url = undefined,
|
||||
}: Props = $props()
|
||||
|
||||
$: previewURL = files ? URL.createObjectURL(files[0]) : undefined
|
||||
let dragover = $state(false)
|
||||
|
||||
let previewURL = $derived(files ? URL.createObjectURL(files[0]) : undefined)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<Label text={label} class="mb-1">
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
<Label text={label} class="mb-1" />
|
||||
<label
|
||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
||||
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
||||
@@ -24,20 +33,20 @@
|
||||
: ''}
|
||||
{url != undefined ? 'rounded-b-none' : ''}
|
||||
"
|
||||
on:drop|preventDefault={(event) => (files = event.dataTransfer?.files)}
|
||||
on:dragover|preventDefault={(event) => {
|
||||
ondrop={preventDefault((event) => (files = event.dataTransfer?.files))}
|
||||
ondragover={preventDefault((event) => {
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
dragover = true
|
||||
}
|
||||
}}
|
||||
on:dragleave|preventDefault={() => (dragover = false)}
|
||||
})}
|
||||
ondragleave={preventDefault(() => (dragover = false))}
|
||||
>
|
||||
{#if files}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={previewURL}
|
||||
on:load={() => {
|
||||
onload={() => {
|
||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||
}}
|
||||
class="w-full max-w-sm h-full rounded-lg"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
return new URL(href)
|
||||
@@ -9,26 +9,42 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let href: string
|
||||
export let highlight: boolean = false
|
||||
export let nowrap: boolean = false
|
||||
interface Props {
|
||||
href: string
|
||||
highlight?: boolean
|
||||
nowrap?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: richURL = $$slots.default ? undefined : parseURL(href)
|
||||
let {
|
||||
href,
|
||||
highlight = false,
|
||||
nowrap = false,
|
||||
children,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let richURL = $derived(children ? undefined : parseURL(href))
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
{href}
|
||||
class="{highlight
|
||||
? 'text-blue-500'
|
||||
: ''} hover:underline max-w-full inline-flex items-center gap-1 {$$props.class}"
|
||||
: ''} hover:underline max-w-full inline-flex items-center gap-1 {clazz}"
|
||||
>
|
||||
<slot name="icon" />
|
||||
<slot>
|
||||
{@render icon?.()}
|
||||
{#if children}{@render children()}{:else}
|
||||
<span
|
||||
class="flex relative gap-0 {nowrap
|
||||
? 'w-full whitespace-nowrap overflow-hidden text-ellipsis text-xs'
|
||||
: ''} {$$props.class}"
|
||||
: ''} {clazz}"
|
||||
>
|
||||
{#if richURL}
|
||||
<span class="text-blue-300 dark:text-blue-800">
|
||||
@@ -49,5 +65,5 @@
|
||||
{href}
|
||||
{/if}
|
||||
</span>
|
||||
</slot>
|
||||
{/if}
|
||||
</a>
|
||||
@@ -1,37 +0,0 @@
|
||||
<script lang="ts">
|
||||
export let value: number
|
||||
export let min: number = 0
|
||||
export let max: number = 100
|
||||
export let step: number = 1
|
||||
</script>
|
||||
|
||||
<input
|
||||
type="range"
|
||||
bind:value
|
||||
{min}
|
||||
{max}
|
||||
{step}
|
||||
on:change
|
||||
on:click
|
||||
on:keydown
|
||||
on:keypress
|
||||
class="w-full appearance-none h-2 cursor-pointer bg-slate-100 dark:bg-zinc-800
|
||||
rounded-full range"
|
||||
/>
|
||||
|
||||
<style lang="postcss">
|
||||
.range::-moz-range-thumb {
|
||||
border-radius: 50%;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
@apply border-4 bg-white dark:bg-zinc-900 border-primary-900 dark:border-primary-100;
|
||||
transition: all 0.25s cubic-bezier(0.075, 0.82, 0.165, 1);
|
||||
}
|
||||
|
||||
.range:hover::-moz-range-thumb {
|
||||
transform: scale(125%);
|
||||
}
|
||||
.range:active::-moz-range-thumb {
|
||||
transform: scale(90%);
|
||||
}
|
||||
</style>
|
||||
@@ -1,25 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
type T = $$Generic
|
||||
export let options: T[]
|
||||
export let disabled: boolean[] = []
|
||||
export let optionNames: string[] = []
|
||||
export let selected: T
|
||||
export let headless: boolean = false
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: T }>()
|
||||
|
||||
$: {
|
||||
dispatcher('select', selected)
|
||||
interface Props {
|
||||
options: T[]
|
||||
disabled?: boolean[]
|
||||
optionNames?: string[]
|
||||
selected: T
|
||||
headless?: boolean
|
||||
class?: string
|
||||
buttonClazz?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
onselect?: (item: T) => void
|
||||
}
|
||||
|
||||
let {
|
||||
options,
|
||||
disabled = [],
|
||||
optionNames = [],
|
||||
selected = $bindable(),
|
||||
headless = false,
|
||||
class: clazz = '',
|
||||
buttonClazz = '',
|
||||
children,
|
||||
onselect,
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
onselect?.(selected)
|
||||
})
|
||||
|
||||
let containerClass = `
|
||||
flex flex-row rtl:flex-row-reverse items-center w-max max-w-full overflow-auto
|
||||
${headless ? 'pb-1 gap-1' : ''}
|
||||
${$$props.class}
|
||||
${clazz}
|
||||
`
|
||||
|
||||
const buttonClass = (selected: boolean) => `
|
||||
@@ -27,7 +42,7 @@
|
||||
last:rounded-r-lg last:border-r last:dark:border-r-transparent
|
||||
rounded-l-none
|
||||
rounded-r-none
|
||||
px-3 py-1.5 text-sm hover:brightness-110 ${$$props.buttonClass || ''}
|
||||
px-3 py-1.5 text-sm hover:brightness-110 ${buttonClazz || ''}
|
||||
${
|
||||
!selected
|
||||
? `hover:dark:bg-zinc-800 border-slate-100 border-t border-b border-b-slate-300 dark:border-b-0
|
||||
@@ -49,21 +64,32 @@
|
||||
`
|
||||
</script>
|
||||
|
||||
<div class={containerClass}>
|
||||
<div
|
||||
class="border rounded-full border-slate-200 dark:border-zinc-800 bg-slate-50 dark:bg-zinc-950 p-1 flex items-center gap-1 w-max max-w-full z-0 relative overflow-auto"
|
||||
>
|
||||
{#each options as option, index}
|
||||
{@const slctd = selected == option}
|
||||
<button
|
||||
class={buttonClass(selected == option)}
|
||||
on:click|preventDefault={() => (selected = option)}
|
||||
class={[
|
||||
'px-3 py-1 rounded-full text-sm font-medium transition-colors duration-75 relative',
|
||||
slctd
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900'
|
||||
: 'dark:bg-zinc-900/50 bg-white',
|
||||
]}
|
||||
onclick={(e) => {
|
||||
e.preventDefault()
|
||||
selected = option
|
||||
}}
|
||||
disabled={disabled[index] ?? false}
|
||||
type="button"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
{#if headless && option == selected}
|
||||
{#if slctd}
|
||||
<div
|
||||
class="absolute -bottom-1 left-0 w-full border-b-2 rounded-t-sm border-black dark:border-white"
|
||||
/>
|
||||
class="absolute left-0 top-0 w-full h-full blur-xl scale-75 opacity-50 dark:bg-primary-100 -z-10"
|
||||
></div>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<slot {selected} />
|
||||
{@render children?.({ selected })}
|
||||
@@ -1,21 +1,36 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { Community, ListingType } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import type { Community, CommunityView, ListingType } from 'lemmy-js-client'
|
||||
import { MenuButton, Search } from 'mono-svelte'
|
||||
import type { SearchProps } from 'mono-svelte/search/Search.svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let type: 'community' | 'instance' = 'community'
|
||||
export let q: string = ''
|
||||
interface Props {
|
||||
type?: 'community' | 'instance'
|
||||
q?: string
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
onselect?: (item: any) => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let instance: string | undefined = undefined
|
||||
export let listing_type: ListingType = 'Subscribed'
|
||||
export let showWhenEmpty: boolean = false
|
||||
let {
|
||||
type = 'community',
|
||||
q = $bindable(''),
|
||||
instance = undefined,
|
||||
listing_type = 'Subscribed',
|
||||
showWhenEmpty = false,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
||||
$: instances = type == 'instance' && getClient().getFederatedInstances()
|
||||
let instances = $derived(
|
||||
type == 'instance' && getClient().getFederatedInstances(),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if type == 'community'}
|
||||
@@ -32,36 +47,36 @@
|
||||
return results.communities.map((c) => c.community)
|
||||
}}
|
||||
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...$$restProps}
|
||||
let:item
|
||||
let:select
|
||||
{...rest}
|
||||
>
|
||||
<div class="w-full h-full" slot="noresults">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Avatar url={item.icon} alt={item.title} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
<span>{item.title}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
<Avatar url={item.icon} alt={item.title} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.title}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{:else if type == 'instance'}
|
||||
<Search
|
||||
@@ -70,36 +85,36 @@
|
||||
|
||||
return q
|
||||
? (results.federated_instances?.linked || []).filter(
|
||||
(i) => i.software === 'lemmy' && i.domain.includes(q)
|
||||
(i) => i.software === 'lemmy' && i.domain.includes(q),
|
||||
)
|
||||
: []
|
||||
}}
|
||||
extractName={(i) => `${i.domain}`}
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...$$restProps}
|
||||
let:item
|
||||
let:select
|
||||
{...rest}
|
||||
>
|
||||
<div class="w-full h-full" slot="noresults">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None (Start typing to search)</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None (Start typing to search)</span>
|
||||
<span>{item.domain}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.domain}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{/if}
|
||||
@@ -19,16 +19,29 @@
|
||||
import { userLink } from '$lib/lemmy/generic'
|
||||
import { t } from '$lib/translations'
|
||||
import Entity from '../ui/Entity.svelte'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { optimizeImageURL } from './post/helpers'
|
||||
import Link from '../input/Link.svelte'
|
||||
import EndPlaceholder from '../ui/EndPlaceholder.svelte'
|
||||
|
||||
export let site: SiteView
|
||||
export let taglines: Tagline[] | undefined = undefined
|
||||
export let admins: PersonView[] | undefined = undefined
|
||||
export let version: string | undefined = undefined
|
||||
interface Props {
|
||||
site: SiteView
|
||||
taglines?: Tagline[] | undefined
|
||||
admins?: PersonView[] | undefined
|
||||
version?: string | undefined
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
site,
|
||||
taglines = undefined,
|
||||
admins = undefined,
|
||||
version = undefined,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<StickyCard class="w-full {$$props.class} text-slate-600 dark:text-zinc-400">
|
||||
<StickyCard class="w-full {clazz} text-slate-600 dark:text-zinc-400">
|
||||
{#if site.site.banner}
|
||||
<div
|
||||
class="rounded-xl
|
||||
@@ -43,41 +56,15 @@
|
||||
</div>
|
||||
{/if}
|
||||
<Entity name={site.site.name} label={new URL(site.site.actor_id).hostname}>
|
||||
<Avatar
|
||||
width={32}
|
||||
url={site.site.icon}
|
||||
alt={site.site.name}
|
||||
circle={false}
|
||||
slot="icon"
|
||||
/>
|
||||
{#snippet customIcon()}
|
||||
<Avatar
|
||||
width={32}
|
||||
url={site.site.icon}
|
||||
alt={site.site.name}
|
||||
circle={false}
|
||||
/>
|
||||
{/snippet}
|
||||
</Entity>
|
||||
<div class="flex flex-row gap-1 !border-0">
|
||||
<Button
|
||||
href="/modlog"
|
||||
title={$t('routes.modlog')}
|
||||
color="ghost"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
</Button>
|
||||
<Button
|
||||
href="/legal"
|
||||
title={$t('routes.legal.title')}
|
||||
color="ghost"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={BuildingOffice} size="16" mini />
|
||||
</Button>
|
||||
<Button
|
||||
href="/instances"
|
||||
title={$t('routes.instances')}
|
||||
class="3xl:rounded-l-none"
|
||||
color="ghost"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
{#if taglines && taglines.length > 0}
|
||||
@@ -88,22 +75,30 @@
|
||||
{/if}
|
||||
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.about}>
|
||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
{$t('cards.site.about')}
|
||||
</span>
|
||||
<Expandable bind:open={settings.expand.about}>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1 py-1 px-2 w-full">
|
||||
{$t('cards.site.about')}
|
||||
<hr
|
||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
<Markdown source={site.site.description} />
|
||||
<div class="my-4" />
|
||||
<div class="my-4"></div>
|
||||
<Markdown source={site.site.sidebar} />
|
||||
</Expandable>
|
||||
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.stats}>
|
||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
||||
<Icon src={ChartBar} size="16" mini />
|
||||
{$t('cards.site.stats')}
|
||||
</span>
|
||||
<Expandable bind:open={settings.expand.stats}>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1 py-1 px-2 w-full">
|
||||
{$t('cards.site.stats')}
|
||||
<hr
|
||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
<div class="flex flex-row gap-4 flex-wrap">
|
||||
<LabelStat
|
||||
label={$t('content.users')}
|
||||
@@ -125,11 +120,15 @@
|
||||
|
||||
{#if admins}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.team}>
|
||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
||||
<Icon src={UserGroup} size="16" mini />
|
||||
{$t('cards.site.admins')}
|
||||
</span>
|
||||
<Expandable bind:open={settings.expand.team}>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1 py-1 px-2 w-full">
|
||||
{$t('cards.site.admins')}
|
||||
<hr
|
||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={admins.map((a) => ({
|
||||
id: a.person.id,
|
||||
@@ -142,9 +141,23 @@
|
||||
</Expandable>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-row flex-wrap gap-1">
|
||||
<Link highlight href="/modlog">
|
||||
{$t('routes.modlog')}
|
||||
</Link>
|
||||
•
|
||||
<Link highlight href="/legal">
|
||||
{$t('routes.legal.title')}
|
||||
</Link>
|
||||
•
|
||||
<Link highlight href="/instances">
|
||||
{$t('routes.instances')}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{#if version}
|
||||
<div class="w-max">
|
||||
<Badge title="Lemmy version">
|
||||
<Badge label="Lemmy version">
|
||||
<Icon src={ServerStack} micro size="14" />
|
||||
{version}
|
||||
</Badge>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
ArrowUp,
|
||||
Bookmark,
|
||||
Icon,
|
||||
Microphone,
|
||||
@@ -8,46 +7,61 @@
|
||||
Pencil,
|
||||
Plus,
|
||||
Trash,
|
||||
PlusCircle,
|
||||
MinusCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { CommentNodeI } from './comments'
|
||||
import type { CommentNodeI } from './comments.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import CommentForm from './CommentForm.svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { Disclosure, toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||
import { page } from '$app/stores'
|
||||
import { page } from '$app/state'
|
||||
import { onMount } from 'svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { expoInOut, expoOut } from 'svelte/easing'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
export let node: CommentNodeI
|
||||
export let postId: number
|
||||
export let op: boolean = false
|
||||
interface Props {
|
||||
node: CommentNodeI
|
||||
postId: number
|
||||
op?: boolean
|
||||
actions?: boolean
|
||||
meta?: boolean
|
||||
open?: boolean
|
||||
replying?: boolean
|
||||
contentClass?: ClassValue
|
||||
class?: ClassValue
|
||||
metaSuffix?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let actions: boolean = true
|
||||
export let meta: boolean = true
|
||||
let {
|
||||
node = $bindable(),
|
||||
postId,
|
||||
op = false,
|
||||
actions = true,
|
||||
meta = true,
|
||||
replying = $bindable(false),
|
||||
contentClass = '',
|
||||
class: clazz = '',
|
||||
metaSuffix,
|
||||
children,
|
||||
open = $bindable(true),
|
||||
}: Props = $props()
|
||||
|
||||
export let open = true
|
||||
|
||||
export let replying = false
|
||||
|
||||
let editing = false
|
||||
let newComment = node.comment_view.comment.content
|
||||
|
||||
let editingLoad = false
|
||||
let editing = $state(false)
|
||||
let newComment = $state(node.comment_view.comment.content)
|
||||
let editingLoad = $state(false)
|
||||
|
||||
async function save() {
|
||||
if (!$profile?.jwt || newComment.length <= 0) return
|
||||
if (!profile.data?.jwt || newComment.length <= 0) return
|
||||
|
||||
editingLoad = true
|
||||
|
||||
@@ -62,8 +76,7 @@
|
||||
editing = false
|
||||
} catch (err) {
|
||||
toast({
|
||||
// @ts-ignore i hate this
|
||||
content: err,
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
@@ -72,7 +85,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if ('#' + node.comment_view.comment.id.toString() == $page.url.hash) {
|
||||
if ('#' + node.comment_view.comment.id.toString() == page.url.hash) {
|
||||
highlight = 'text-primary-900 dark:text-primary-100 font-medium'
|
||||
|
||||
setTimeout(() => (highlight = 'duration-[3s] transition-all'), 500)
|
||||
@@ -80,19 +93,27 @@
|
||||
}
|
||||
})
|
||||
|
||||
let highlight = ''
|
||||
let highlight = $state('')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
<span slot="title">{$t('form.edit')}</span>
|
||||
<form on:submit|preventDefault={save} class="contents">
|
||||
{#snippet customTitle()}
|
||||
<span>{$t('form.edit')}</span>
|
||||
{/snippet}
|
||||
<form
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
save()
|
||||
}}
|
||||
class="contents"
|
||||
>
|
||||
<CommentForm
|
||||
postId={node.comment_view.comment.id}
|
||||
bind:value={newComment}
|
||||
postId={node.comment_view.comment.id}
|
||||
actions={false}
|
||||
preview={true}
|
||||
on:confirm={save}
|
||||
onconfirm={save}
|
||||
/>
|
||||
<Button
|
||||
submit
|
||||
@@ -111,16 +132,16 @@
|
||||
<li
|
||||
class="py-3 relative {node.comment_view.comment.distinguished
|
||||
? ' text-primary-900 dark:text-primary-100'
|
||||
: ''} {highlight} {$$props.class}"
|
||||
: ''} {highlight} {clazz}"
|
||||
id={node.comment_view.comment.id.toString()}
|
||||
>
|
||||
{#if meta}
|
||||
<button
|
||||
on:click={() => (open = !open)}
|
||||
onclick={() => (open = !open)}
|
||||
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full
|
||||
z-0 group relative"
|
||||
>
|
||||
<slot name="meta-suffix" />
|
||||
{@render metaSuffix?.()}
|
||||
<div
|
||||
class="absolute opacity-0 -z-10 inset-0 group-hover:block group-hover:opacity-100
|
||||
bg-slate-100 dark:bg-zinc-900 group-hover:-inset-1 group-hover:-inset-x-2 rounded-full transition-all
|
||||
@@ -146,18 +167,18 @@
|
||||
<span class:font-bold={op} class="flex flex-row gap-1 items-center">
|
||||
<UserLink
|
||||
inComment
|
||||
avatarSize={24}
|
||||
avatarSize={20}
|
||||
avatar
|
||||
user={node.comment_view.creator}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet extraBadges()}
|
||||
{#if node.comment_view.creator_is_moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
{/if}
|
||||
{#if node.comment_view.creator_is_admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
{#if op}
|
||||
<Icon mini size="16" src={Microphone} class="text-sky-600" />
|
||||
@@ -194,7 +215,7 @@
|
||||
{/if}
|
||||
{#if open}
|
||||
<div
|
||||
class="relative {$$props.contentClass}"
|
||||
class="relative {contentClass}"
|
||||
transition:slide={{ duration: 400, easing: expoOut }}
|
||||
>
|
||||
<div
|
||||
@@ -205,7 +226,7 @@
|
||||
<div
|
||||
class="-z-10 bg-slate-100 dark:bg-zinc-900 absolute -top-9 -bottom-1.5
|
||||
-inset-x-6 -right-6"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<div
|
||||
class="max-w-full mt-0.5 break-words text-[15px] text-slate-800 dark:text-zinc-100"
|
||||
@@ -214,9 +235,9 @@
|
||||
</div>
|
||||
{#if actions}
|
||||
<CommentActions
|
||||
bind:comment={node.comment_view}
|
||||
comment={node.comment_view}
|
||||
bind:replying
|
||||
on:edit={() => (editing = true)}
|
||||
onedit={() => (editing = true)}
|
||||
disabled={node.comment_view.banned_from_community ||
|
||||
node.comment_view.post.locked}
|
||||
/>
|
||||
@@ -232,25 +253,25 @@
|
||||
label={$t('comment.reply')}
|
||||
{postId}
|
||||
parentId={node.comment_view.comment.id}
|
||||
on:comment={(e) => {
|
||||
oncomment={(e) => {
|
||||
node.children = [
|
||||
{
|
||||
children: [],
|
||||
comment_view: e.detail.comment_view,
|
||||
comment_view: e.comment_view,
|
||||
depth: node.depth + 1,
|
||||
ui: {},
|
||||
expanded: true,
|
||||
},
|
||||
...node.children,
|
||||
]
|
||||
replying = false
|
||||
}}
|
||||
on:cancel={() => (replying = false)}
|
||||
oncancel={() => (replying = false)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="bg-transparent dark:bg-transparent">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -22,36 +22,35 @@
|
||||
report,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { deleteItem, save } from '$lib/lemmy/contentview.js'
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import Translation from '$lib/components/translate/Translation.svelte'
|
||||
import { text } from '$lib/components/translate/translation'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
|
||||
export let comment: CommentView
|
||||
export let replying: boolean = false
|
||||
export let disabled = false
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
replying?: boolean
|
||||
disabled?: boolean
|
||||
onedit?: (comment: CommentView) => void
|
||||
}
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: CommentView }>()
|
||||
|
||||
let reply = ''
|
||||
let translating = false
|
||||
let {
|
||||
comment = $bindable(),
|
||||
replying = $bindable(false),
|
||||
disabled = false,
|
||||
onedit,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if translating}
|
||||
<Translation bind:open={translating} />
|
||||
{/if}
|
||||
|
||||
<div
|
||||
class="flex flex-row items-center gap-0.5 h-7 w-full"
|
||||
class:flex-row-reverse={$userSettings.posts.reverseActions}
|
||||
class:flex-row-reverse={settings.posts.reverseActions}
|
||||
>
|
||||
<CommentVote
|
||||
bind:upvotes={comment.counts.upvotes}
|
||||
bind:downvotes={comment.counts.downvotes}
|
||||
bind:vote={comment.my_vote}
|
||||
upvotes={comment.counts.upvotes}
|
||||
downvotes={comment.counts.downvotes}
|
||||
vote={comment.my_vote}
|
||||
commentId={comment.comment.id}
|
||||
/>
|
||||
<Button
|
||||
@@ -59,35 +58,32 @@
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
class="text-slate-700 dark:text-zinc-300"
|
||||
on:click={() => (replying = !replying)}
|
||||
onclick={() => (replying = !replying)}
|
||||
disabled={comment.post.locked || disabled}
|
||||
>
|
||||
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
||||
<span class="text-xs">{$t('comment.reply')}</span>
|
||||
</Button>
|
||||
{#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))}
|
||||
{#if profile.data?.user && (amMod(profile.data?.user, comment.community) || isAdmin(profile.data.user))}
|
||||
<CommentModerationMenu bind:item={comment} />
|
||||
{/if}
|
||||
<Menu placement="bottom">
|
||||
<Button
|
||||
slot="target"
|
||||
title={$t('comment.actions.label')}
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
size="square-sm"
|
||||
class="text-slate-700 dark:text-zinc-300"
|
||||
>
|
||||
<Icon
|
||||
src={EllipsisHorizontal}
|
||||
width={16}
|
||||
height={16}
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('comment.actions.label')}
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
size="square-sm"
|
||||
class="text-slate-700 dark:text-zinc-300"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} width={16} height={16} mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('comment.actions.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
navigator.share?.({
|
||||
url: comment.comment.ap_id,
|
||||
}) ?? navigator.clipboard.writeText(comment.comment.ap_id)
|
||||
@@ -96,29 +92,21 @@
|
||||
<Icon src={Square2Stack} mini size="16" />
|
||||
<div>{$t('comment.actions.link')}</div>
|
||||
</MenuButton>
|
||||
{#if $userSettings.translator}
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
// @ts-ignore
|
||||
text.set(comment.comment.content)
|
||||
translating = !translating
|
||||
}}
|
||||
>
|
||||
<Icon src={Language} size="16" mini slot="prefix" />
|
||||
{$t('post.actions.more.translate')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile?.jwt}
|
||||
{#if comment.creator.id == $profile.user?.local_user_view.person.id}
|
||||
<MenuButton on:click={() => dispatcher('edit', comment)}>
|
||||
{#if profile.data?.jwt}
|
||||
{#if comment.creator.id == profile.data.user?.local_user_view.person.id}
|
||||
<MenuButton onclick={() => onedit?.(comment)}>
|
||||
<Icon src={PencilSquare} mini size="16" />
|
||||
<span>{$t('post.actions.more.edit')}</span>
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton
|
||||
on:click={async () => {
|
||||
if ($profile?.jwt)
|
||||
comment.saved = await save(comment, !comment.saved, $profile.jwt)
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
comment.saved = await save(
|
||||
comment,
|
||||
!comment.saved,
|
||||
profile.data.jwt,
|
||||
)
|
||||
}}
|
||||
>
|
||||
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
||||
@@ -126,15 +114,15 @@
|
||||
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
</span>
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.jwt && $profile.user.local_user_view.person.id == comment.creator.id}
|
||||
{#if profile.data?.user && profile.data.jwt && profile.data.user.local_user_view.person.id == comment.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
on:click={async () => {
|
||||
if ($profile?.jwt)
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
comment.comment.deleted = await deleteItem(
|
||||
comment,
|
||||
!comment.comment.deleted,
|
||||
$profile.jwt
|
||||
profile.data.jwt,
|
||||
)
|
||||
}}
|
||||
>
|
||||
@@ -146,13 +134,13 @@
|
||||
</span>
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile.jwt && $profile.user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton on:click={() => report(comment)} color="danger-subtle">
|
||||
{#if profile.data.jwt && profile.data.user?.local_user_view.person.id != comment.creator.id}
|
||||
<MenuButton onclick={() => report(comment)} color="danger-subtle">
|
||||
<Icon src={Flag} mini size="16" />
|
||||
<span>{$t('moderation.report')}</span>
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/if}
|
||||
</Menu>
|
||||
<div class="flex-1 w-full" />
|
||||
<div class="flex-1 w-full"></div>
|
||||
</div>
|
||||
@@ -1,41 +1,55 @@
|
||||
<script lang="ts">
|
||||
import type { CommentResponse } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient, site } from '$lib/lemmy.svelte.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Menu, Select, Spinner, toast, Option, MenuButton } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { placeholders } from '$lib/util.js'
|
||||
import { placeholders } from '$lib/util.svelte.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
import { ArrowUp, Icon, Language, XMark } from 'svelte-hero-icons'
|
||||
|
||||
export let postId: number
|
||||
export let parentId: number | undefined = undefined
|
||||
export let locked: boolean = false
|
||||
export let banned: boolean = false
|
||||
export let rows: number = 7
|
||||
export let placeholder: string | undefined = undefined
|
||||
interface Props {
|
||||
postId: number
|
||||
parentId?: number | undefined
|
||||
locked?: boolean
|
||||
banned?: boolean
|
||||
rows?: number
|
||||
placeholder?: string | undefined
|
||||
value?: string
|
||||
actions?: boolean
|
||||
preview?: boolean
|
||||
oncomment?: (comment: CommentResponse) => void
|
||||
onconfirm?: (value: string) => void
|
||||
oncancel?: (cancel: boolean) => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
const dispatch = createEventDispatcher<{
|
||||
comment: CommentResponse
|
||||
confirm: string
|
||||
cancel: boolean
|
||||
}>()
|
||||
let {
|
||||
postId,
|
||||
parentId = undefined,
|
||||
locked = false,
|
||||
banned = false,
|
||||
rows = 7,
|
||||
placeholder = undefined,
|
||||
value = $bindable(''),
|
||||
actions = true,
|
||||
preview: previewAction = true,
|
||||
oncancel,
|
||||
oncomment,
|
||||
onconfirm,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
export let value = ''
|
||||
export let actions = true
|
||||
|
||||
let previewAction = true
|
||||
export { previewAction as preview }
|
||||
|
||||
let loading = false
|
||||
let loading = $state(false)
|
||||
let preview = false
|
||||
let language: number | undefined = $state()
|
||||
|
||||
async function submit() {
|
||||
if (!$profile?.user || !$profile?.jwt || value == '') return
|
||||
if (!profile.data?.user || !profile.data?.jwt || value == '') return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -45,7 +59,7 @@
|
||||
post_id: postId,
|
||||
parent_id: parentId,
|
||||
})
|
||||
dispatch('comment', response)
|
||||
oncomment?.(response)
|
||||
|
||||
value = ''
|
||||
} catch (err) {
|
||||
@@ -70,7 +84,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<MarkdownEditor
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
{rows}
|
||||
placeholder={locked
|
||||
? $t('comment.locked')
|
||||
@@ -79,35 +93,77 @@
|
||||
: (placeholder ?? placeholders.get('comment'))}
|
||||
bind:value
|
||||
disabled={locked || loading || banned}
|
||||
on:confirm={() => {
|
||||
onconfirm={() => {
|
||||
if (actions) {
|
||||
submit()
|
||||
dispatch('confirm', value)
|
||||
onconfirm?.(value)
|
||||
}
|
||||
}}
|
||||
on:focus
|
||||
previewButton={previewAction}
|
||||
>
|
||||
<div class="flex-1" />
|
||||
<Menu>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
size="custom"
|
||||
class="w-9 h-9"
|
||||
rounding="pill"
|
||||
color={language != undefined ? 'primary' : 'ghost'}
|
||||
title={$t('form.profile.languages.title')}
|
||||
>
|
||||
<Icon src={Language} size="16" micro />
|
||||
</Button>
|
||||
{/snippet}
|
||||
|
||||
{#if site.data}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => (language = undefined)}
|
||||
>
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{$t('form.post.unset')}
|
||||
</MenuButton>
|
||||
{#each site.data?.all_languages as languageOption}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
language = languageOption.id
|
||||
}}
|
||||
>
|
||||
{languageOption.name}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
{/if}
|
||||
</Menu>
|
||||
<div class="flex-1"></div>
|
||||
{#if actions}
|
||||
<Button
|
||||
size="custom"
|
||||
title={$t('common.cancel')}
|
||||
on:click={() => dispatch('cancel', true)}
|
||||
onclick={() => oncancel?.(true)}
|
||||
color="tertiary"
|
||||
class="w-8 h-8"
|
||||
rounding="xl"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={XMark} size="16" micro />
|
||||
<Icon
|
||||
src={XMark}
|
||||
size="20"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={submit}
|
||||
onclick={submit}
|
||||
color="primary"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class="w-9 h-9"
|
||||
title={$t('form.submit')}
|
||||
{loading}
|
||||
disabled={locked || loading || banned}
|
||||
size="lg"
|
||||
>
|
||||
{$t('form.submit')}
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowUp} size="18" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
</MarkdownEditor>
|
||||
|
||||
@@ -2,28 +2,36 @@
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import type { CommentView } from 'lemmy-js-client'
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let comment: CommentView
|
||||
export let view = $userSettings.view
|
||||
export let community = false
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
view?: any
|
||||
community?: boolean
|
||||
meta?: boolean
|
||||
class?: string
|
||||
commentClass?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let meta: boolean = true
|
||||
let {
|
||||
comment,
|
||||
view = settings.view,
|
||||
community = false,
|
||||
meta = true,
|
||||
class: clazz = '',
|
||||
commentClass = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Material
|
||||
class="flex flex-col flex-1 {view != 'card'
|
||||
? '!bg-transparent !border-0 rounded-none'
|
||||
: 'p-5'} {view == 'list'
|
||||
? 'py-5'
|
||||
: view == 'compact'
|
||||
? 'py-4'
|
||||
: 'py-5'} {$$props.class}"
|
||||
class="flex flex-col flex-1 !bg-transparent !border-0 rounded-none
|
||||
{view == 'compact' ? 'py-4' : 'py-5'} {clazz}"
|
||||
color="distinct"
|
||||
padding="none"
|
||||
>
|
||||
@@ -51,22 +59,25 @@
|
||||
</div>
|
||||
<Button
|
||||
color="primary"
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
href="/post/{comment.post.id}?thread={comment.comment.path}#{comment
|
||||
.comment.id}"
|
||||
class="self-start"
|
||||
>
|
||||
{$t('common.jump')}
|
||||
<Icon src={ArrowUturnUp} size="16" micro />
|
||||
<Icon src={ArrowUturnUp} size="14" micro />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="list-none">
|
||||
<Comment
|
||||
postId={comment.post.id}
|
||||
node={{ children: [], comment_view: comment, depth: 1, ui: {} }}
|
||||
node={{ children: [], comment_view: comment, depth: 1, expanded: true }}
|
||||
replying={false}
|
||||
{meta}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class={commentClass}
|
||||
/>
|
||||
</div>
|
||||
</Material>
|
||||
@@ -1,35 +1,26 @@
|
||||
<script lang="ts">
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import type { CommentNodeI } from './comments'
|
||||
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
||||
import type { CommentNodeI } from './comments.svelte'
|
||||
import Comments from './Comments.svelte'
|
||||
import { browser } from '$app/environment'
|
||||
import { onMount } from 'svelte'
|
||||
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||
|
||||
export let nodes: CommentNodeI[]
|
||||
export let post: Post
|
||||
export let scrollTo: string | undefined
|
||||
interface Props {
|
||||
nodes: CommentNodeI[]
|
||||
post: Post
|
||||
scrollTo: string | undefined
|
||||
}
|
||||
|
||||
let virtualListEl: HTMLElement | undefined = undefined
|
||||
let { nodes, post, scrollTo }: Props = $props()
|
||||
|
||||
$: virtualizer = createWindowVirtualizer({
|
||||
count: nodes.length,
|
||||
estimateSize: () => 30,
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
initialRect: {
|
||||
height: 1500,
|
||||
width: 99999,
|
||||
},
|
||||
overscan: 5,
|
||||
})
|
||||
let offsetEl = $state<HTMLElement>()
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
let initialOffset = $state(0)
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
|
||||
$: {
|
||||
if (virtualItemEls.length)
|
||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
||||
const updateOffset = (entry: IntersectionObserverEntry) => {
|
||||
if (entry.isIntersecting && offsetEl) {
|
||||
initialOffset = entry.boundingClientRect.top + window.scrollY
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
@@ -39,30 +30,40 @@
|
||||
element?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}, 100)
|
||||
}
|
||||
|
||||
// IntersectionObserver to watch for shifts
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach(updateOffset)
|
||||
},
|
||||
{ threshold: [0, 1] },
|
||||
)
|
||||
|
||||
if (offsetEl) {
|
||||
observer.observe(offsetEl)
|
||||
}
|
||||
|
||||
return () => {
|
||||
observer.disconnect()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<div
|
||||
style="position:relative; height: {browser
|
||||
? `${$virtualizer.getTotalSize()}px`
|
||||
: '100%'}; width: 100%;"
|
||||
bind:this={virtualListEl}
|
||||
>
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0]
|
||||
? items?.[0]?.start - $virtualizer.options.scrollMargin
|
||||
: 0}px);"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900"
|
||||
id="feed"
|
||||
<div bind:this={offsetEl}>
|
||||
<VirtualList
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-800 w-full"
|
||||
overscan={500}
|
||||
items={nodes}
|
||||
{initialOffset}
|
||||
>
|
||||
{#each items as row, index (row.index)}
|
||||
<div
|
||||
bind:this={virtualItemEls[index]}
|
||||
data-index={row.index}
|
||||
class="-mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||
>
|
||||
<Comments isParent={true} nodes={[nodes[row.index]]} {post} />
|
||||
{#snippet item(item, index)}
|
||||
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
|
||||
<Comments
|
||||
isParent={true}
|
||||
bind:nodes={() => [nodes[index]], (v) => (nodes[index] = v[0])}
|
||||
{post}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/snippet}
|
||||
</VirtualList>
|
||||
</div>
|
||||
@@ -7,9 +7,9 @@
|
||||
ChevronUp,
|
||||
Icon,
|
||||
} from 'svelte-hero-icons'
|
||||
import { getClient, site } from '$lib/lemmy'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient, site } from '$lib/lemmy.svelte'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { Button, buttonColor, toast } from 'mono-svelte'
|
||||
import { vote as voteItem } from '$lib/lemmy/contentview'
|
||||
@@ -18,13 +18,22 @@
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let vote: number = 0
|
||||
export let upvotes: number
|
||||
export let downvotes: number
|
||||
export let commentId: number
|
||||
interface Props {
|
||||
vote?: number
|
||||
upvotes: number
|
||||
downvotes: number
|
||||
commentId: number
|
||||
}
|
||||
|
||||
let {
|
||||
vote = $bindable(0),
|
||||
upvotes = $bindable(),
|
||||
downvotes = $bindable(),
|
||||
commentId,
|
||||
}: Props = $props()
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!$profile?.jwt) {
|
||||
if (!profile.data?.jwt) {
|
||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||
return
|
||||
}
|
||||
@@ -39,10 +48,10 @@
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="h-full flex items-center overflow-hidden {buttonColor.ghost} rounded-full hover:bg-transparent"
|
||||
class="h-full flex items-center overflow-hidden {buttonColor.ghost} rounded-full hover:bg-transparent font-medium"
|
||||
>
|
||||
<button
|
||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||
onclick={() => castVote(vote == 1 ? 0 : 1)}
|
||||
class="flex items-center gap-0.5 transition-colors px-1.5 h-full
|
||||
{vote == 1
|
||||
? shouldShowVoteColor(vote, 'upvotes')
|
||||
@@ -65,7 +74,7 @@
|
||||
class="border-l h-4 w-0 !p-0 border-slate-200 dark:border-zinc-800"
|
||||
></div>
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
onclick={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex flex-row-reverse items-center gap-0.5 h-full transition-colors border-0 px-1.5
|
||||
{vote == -1
|
||||
? shouldShowVoteColor(vote, 'downvotes')
|
||||
|
||||
@@ -1,37 +1,35 @@
|
||||
<script lang="ts">
|
||||
import Comments from './Comments.svelte'
|
||||
import Comment from './Comment.svelte'
|
||||
import { buildCommentsTree, type CommentNodeI } from './comments'
|
||||
import { page } from '$app/stores'
|
||||
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
|
||||
import { page } from '$app/state'
|
||||
import { onMount, setContext } from 'svelte'
|
||||
import {
|
||||
ChevronDoubleDown,
|
||||
ChevronDown,
|
||||
Icon,
|
||||
Plus,
|
||||
PlusCircle,
|
||||
ArrowDownCircle,
|
||||
} from 'svelte-hero-icons'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { Icon, ArrowDownCircle } from 'svelte-hero-icons'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import type { CommentView, Post } from 'lemmy-js-client'
|
||||
import { fly } from 'svelte/transition'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { afterNavigate, goto } from '$app/navigation'
|
||||
import { backOut, expoOut } from 'svelte/easing'
|
||||
import { t } from '$lib/translations'
|
||||
import { browser } from '$app/environment'
|
||||
|
||||
export let nodes: CommentNodeI[]
|
||||
export let isParent: boolean
|
||||
export let post: Post
|
||||
interface Props {
|
||||
nodes: CommentNodeI[]
|
||||
isParent: boolean
|
||||
post: Post
|
||||
}
|
||||
|
||||
let hydrated = false
|
||||
let { nodes = $bindable(), isParent, post }: Props = $props()
|
||||
|
||||
let hydrated = $state(false)
|
||||
|
||||
onMount(() => {
|
||||
hydrated = true
|
||||
if (isParent && $page.url.hash && browser) {
|
||||
document.getElementById($page.url.hash)?.scrollIntoView({
|
||||
if (isParent && page.url.hash && browser) {
|
||||
document.getElementById(page.url.hash)?.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center',
|
||||
})
|
||||
@@ -47,13 +45,14 @@
|
||||
parent.comment_view.counts.child_count > 0 &&
|
||||
parent.children.length == 0
|
||||
)
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
parent.loading = true
|
||||
|
||||
const newComments = await getClient($page.params.instance).getComments({
|
||||
const newComments = await getClient(page.params.instance).getComments({
|
||||
max_depth: 5,
|
||||
parent_id: parent.comment_view.comment.id,
|
||||
type_: 'All',
|
||||
@@ -74,7 +73,7 @@
|
||||
// 0.18.2 -> 0.18.3 broke this
|
||||
// so i'm adding this check
|
||||
const treeParent = tree.find(
|
||||
(c) => c.comment_view.comment.id == parent.comment_view.comment.id
|
||||
(c) => c.comment_view.comment.id == parent.comment_view.comment.id,
|
||||
)
|
||||
|
||||
if (treeParent) {
|
||||
@@ -108,63 +107,66 @@
|
||||
</script>
|
||||
|
||||
<ul
|
||||
in:fly={{ duration: 500, easing: expoOut, y: -12 }}
|
||||
in:fly={{ duration: 500, easing: expoOut, y: -12, opacity: 0 }}
|
||||
class={isParent
|
||||
? 'divide-y dark:divide-zinc-900 divide-slate-100'
|
||||
: ' border-slate-200 dark:border-zinc-800 my-1'}
|
||||
>
|
||||
{#each nodes as node (node.comment_view.comment.id)}
|
||||
{#each nodes as node, index (node.comment_view.comment.id)}
|
||||
<Comment
|
||||
postId={post.id}
|
||||
bind:node
|
||||
bind:open={node.ui.open}
|
||||
node={nodes[index]}
|
||||
op={post.creator_id == node.comment_view.creator.id}
|
||||
contentClass="pl-3 {node.children.length > 0 ||
|
||||
contentClass="{node.children.length > 0 ||
|
||||
node.comment_view.counts.child_count > 0
|
||||
? 'border-l'
|
||||
: ''} ml-3 border-slate-200 dark:border-zinc-800"
|
||||
: ''} ml-2.5 border-slate-200 dark:border-zinc-800 pl-2.5 "
|
||||
bind:open={() => node.expanded, (value) => (node.expanded = value)}
|
||||
>
|
||||
{#if node.children?.length > 0}
|
||||
<svelte:self {post} bind:nodes={node.children} isParent={false} />
|
||||
<Comments {post} nodes={nodes[index].children} isParent={false} />
|
||||
{/if}
|
||||
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
||||
<svelte:element
|
||||
this={hydrated ? 'div' : 'a'}
|
||||
class="w-full my-2 h-8"
|
||||
href="/comment/{$page.params.instance}/{node.comment_view.comment.id}"
|
||||
</Comment>
|
||||
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
||||
<svelte:element
|
||||
this={hydrated ? 'div' : 'a'}
|
||||
class="w-full h-10 !border-y-0 -mt-2 -ml-2.5"
|
||||
href="/comment/{page.params.instance}/{node.comment_view.comment.id}"
|
||||
>
|
||||
<Button
|
||||
loading={nodes[index].loading}
|
||||
disabled={nodes[index].loading}
|
||||
rounding="pill"
|
||||
color="tertiary"
|
||||
class="font-normal !text-sm text-slate-600 dark:text-zinc-400"
|
||||
loaderWidth={16}
|
||||
onclick={() => {
|
||||
if (nodes[index].depth > 4) {
|
||||
goto(
|
||||
`/comment/${page.params.instance}/${nodes[index].comment_view.comment.id}#comments`,
|
||||
)
|
||||
} else {
|
||||
nodes[index].loading = true
|
||||
fetchChildren(nodes[index]).then(
|
||||
() => (nodes[index].loading = false),
|
||||
)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
loading={node.loading}
|
||||
disabled={node.loading}
|
||||
rounding="pill"
|
||||
color="tertiary"
|
||||
class="font-normal text-slate-600 dark:text-zinc-400"
|
||||
loaderWidth={16}
|
||||
on:click={() => {
|
||||
if (node.depth > 4) {
|
||||
goto(
|
||||
`/comment/${$page.params.instance}/${node.comment_view.comment.id}#comments`
|
||||
)
|
||||
} else {
|
||||
node.loading = true
|
||||
fetchChildren(node).then(() => (node.loading = false))
|
||||
}
|
||||
}}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={ArrowDownCircle}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
{$t('comment.more', {
|
||||
// @ts-ignore
|
||||
comments: node.comment_view.counts.child_count,
|
||||
})}
|
||||
</Button>
|
||||
</svelte:element>
|
||||
{/if}
|
||||
</Comment>
|
||||
{/snippet}
|
||||
{$t('comment.more', {
|
||||
// @ts-ignore
|
||||
comments: node.comment_view.counts.child_count,
|
||||
})}
|
||||
</Button>
|
||||
</svelte:element>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
+5
-12
@@ -5,9 +5,7 @@ export interface CommentNodeI {
|
||||
children: Array<CommentNodeI>
|
||||
depth: number
|
||||
loading?: boolean
|
||||
ui: {
|
||||
open?: boolean
|
||||
}
|
||||
expanded?: boolean
|
||||
}
|
||||
|
||||
function getCommentParentId(comment?: Comment): number | undefined {
|
||||
@@ -28,9 +26,8 @@ function getDepthFromComment(comment?: Comment): number | undefined {
|
||||
export function buildCommentsTree(
|
||||
comments: CommentView[],
|
||||
baseDepth: number = 0,
|
||||
filter: (c: CommentView) => boolean = (c) => true
|
||||
filter: (c: CommentView) => boolean = (c) => true,
|
||||
): CommentNodeI[] {
|
||||
const start = performance.now()
|
||||
const map = new Map<number, CommentNodeI>()
|
||||
|
||||
let min_depth = Number.MAX_VALUE
|
||||
@@ -41,9 +38,7 @@ export function buildCommentsTree(
|
||||
comment_view,
|
||||
children: [],
|
||||
depth: depth,
|
||||
ui: {
|
||||
open: true,
|
||||
},
|
||||
expanded: true,
|
||||
}
|
||||
min_depth = Math.min(min_depth, depth)
|
||||
if (filter(comment_view)) {
|
||||
@@ -75,13 +70,12 @@ export function buildCommentsTree(
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Built tree in ${performance.now() - start}ms`)
|
||||
return tree
|
||||
}
|
||||
|
||||
export function searchCommentTree(
|
||||
tree: CommentNodeI[],
|
||||
id: number
|
||||
id: number,
|
||||
): CommentNodeI | undefined {
|
||||
for (const node of tree) {
|
||||
if (node.comment_view.comment.id === id) {
|
||||
@@ -102,14 +96,13 @@ export function searchCommentTree(
|
||||
export function insertCommentIntoTree(
|
||||
tree: CommentNodeI[],
|
||||
cv: CommentView,
|
||||
parentComment: boolean
|
||||
parentComment: boolean,
|
||||
) {
|
||||
// Building a fake node to be used for later
|
||||
const node: CommentNodeI = {
|
||||
comment_view: cv,
|
||||
children: [],
|
||||
depth: 0,
|
||||
ui: {},
|
||||
}
|
||||
|
||||
const parentId = getCommentParentId(cv.comment)
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export async function block(id: number, block: boolean) {
|
||||
try {
|
||||
const loading = toast({
|
||||
@@ -66,7 +66,7 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import {
|
||||
amMod,
|
||||
isAdmin,
|
||||
@@ -83,9 +83,9 @@
|
||||
modal,
|
||||
action,
|
||||
} from 'mono-svelte'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { fullCommunityName } from '$lib/util.js'
|
||||
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
|
||||
import { Button } from 'mono-svelte'
|
||||
import {
|
||||
@@ -109,18 +109,15 @@
|
||||
import { userLink } from '$lib/lemmy/generic'
|
||||
import { t } from '$lib/translations'
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
|
||||
export let community_view: CommunityView
|
||||
export let moderators: CommunityModeratorView[] = []
|
||||
|
||||
let loading = {
|
||||
let loading = $state({
|
||||
blocking: false,
|
||||
subscribing: false,
|
||||
}
|
||||
})
|
||||
|
||||
async function subscribe() {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
loading.subscribing = true
|
||||
const subscribed =
|
||||
community_view.subscribed == 'Subscribed' ||
|
||||
@@ -140,43 +137,61 @@
|
||||
|
||||
loading.subscribing = false
|
||||
}
|
||||
interface Props {
|
||||
community_view: CommunityView
|
||||
moderators?: CommunityModeratorView[]
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
community_view = $bindable(),
|
||||
moderators = [],
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<StickyCard
|
||||
class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {$$props.class}"
|
||||
>
|
||||
<StickyCard class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {clazz}">
|
||||
<Entity
|
||||
name={community_view.community.title}
|
||||
label="!{fullCommunityName(
|
||||
community_view.community.name,
|
||||
community_view.community.actor_id
|
||||
community_view.community.actor_id,
|
||||
)}"
|
||||
>
|
||||
<Avatar
|
||||
width={32}
|
||||
url={community_view.community.icon}
|
||||
alt={community_view.community.name}
|
||||
circle={false}
|
||||
slot="icon"
|
||||
/>
|
||||
{#snippet customIcon()}
|
||||
<Avatar
|
||||
width={32}
|
||||
url={community_view.community.icon}
|
||||
alt={community_view.community.name}
|
||||
circle={false}
|
||||
/>
|
||||
{/snippet}
|
||||
</Entity>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.about} class="!pt-0">
|
||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
||||
<Icon src={InformationCircle} size="15" mini />
|
||||
{$t('cards.site.about')}
|
||||
</span>
|
||||
<Expandable bind:open={settings.expand.about} class="!pt-0">
|
||||
{#snippet title()}
|
||||
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||
{$t('cards.site.about')}
|
||||
<hr
|
||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
<Markdown source={community_view.community.description} />
|
||||
</Expandable>
|
||||
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.stats}>
|
||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
||||
<Icon src={ChartBar} size="15" mini />
|
||||
{$t('cards.site.stats')}
|
||||
</span>
|
||||
<Expandable bind:open={settings.expand.stats}>
|
||||
{#snippet title()}
|
||||
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||
{$t('cards.site.stats')}
|
||||
<hr
|
||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
<div class="flex flex-row gap-4 flex-wrap">
|
||||
<LabelStat
|
||||
label={$t('cards.community.members')}
|
||||
@@ -193,11 +208,16 @@
|
||||
|
||||
{#if moderators && moderators.length > 0}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.team}>
|
||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
||||
<ShieldIcon width={15} filled />
|
||||
{$t('cards.community.moderators')}
|
||||
</span>
|
||||
<Expandable bind:open={settings.expand.team}>
|
||||
{#snippet title()}
|
||||
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||
{$t('cards.community.moderators')}
|
||||
|
||||
<hr
|
||||
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||
/>
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={moderators.map((m) => ({
|
||||
id: m.moderator.id,
|
||||
@@ -213,74 +233,86 @@
|
||||
<div
|
||||
class="flex flex-row items-center gap-1 sticky bottom-0 drop-shadow-xl w-full"
|
||||
>
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<Button
|
||||
disabled={loading.subscribing}
|
||||
loading={loading.subscribing}
|
||||
size="md"
|
||||
rounding="xl"
|
||||
color={community_view.subscribed == 'Subscribed'
|
||||
? 'secondary'
|
||||
: 'primary'}
|
||||
on:click={subscribe}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
onclick={subscribe}
|
||||
class="px-5 relative z-[inherit]"
|
||||
>
|
||||
<Icon
|
||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||
mini
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||
mini
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
{community_view.subscribed == 'Subscribed' ||
|
||||
community_view.subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if $profile?.user && amMod($profile.user, community_view.community)}
|
||||
{#if profile.data?.user && amMod(profile.data.user, community_view.community)}
|
||||
<Button
|
||||
href="/c/{fullCommunityName(
|
||||
community_view.community.name,
|
||||
community_view.community.actor_id
|
||||
community_view.community.actor_id,
|
||||
)}/settings"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Cog6Tooth} mini size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Cog6Tooth} mini size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
<Button size="square-md" slot="target" class="ml-auto">
|
||||
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button size="square-md">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuButton href="/modlog?community={community_view.community.id}">
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
block(community_view.community.id, !community_view.blocked)}
|
||||
>
|
||||
<Icon src={NoSymbol} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={NoSymbol} size="16" mini />
|
||||
{/snippet}
|
||||
{community_view.blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if $profile?.user}
|
||||
{#if profile.data?.user}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
on:click={() => blockInstance(community_view.community.instance_id)}
|
||||
onclick={() => blockInstance(community_view.community.instance_id)}
|
||||
>
|
||||
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BuildingOffice2} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
modal({
|
||||
title: $t('admin.purgeCommunity.title'),
|
||||
body: `${community_view.community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
||||
@@ -301,7 +333,9 @@
|
||||
type: 'error',
|
||||
})}
|
||||
>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,47 +1,65 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { ImageInput, Switch, toast } from 'mono-svelte'
|
||||
import { client, getClient } from '$lib/lemmy.js'
|
||||
import { Badge, ImageInput, MenuButton, Switch, toast } from 'mono-svelte'
|
||||
import { client, getClient, site } from '$lib/lemmy.svelte.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
|
||||
import Label from 'mono-svelte/forms/Label.svelte'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
|
||||
import Select from 'mono-svelte/forms/Select.svelte'
|
||||
import Select from 'mono-svelte/forms/select/Select.svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import Material from 'mono-svelte/materials/Material.svelte'
|
||||
import Menu from 'mono-svelte/popover/Menu.svelte'
|
||||
|
||||
/**
|
||||
* The community ID to edit.
|
||||
*/
|
||||
export let edit: number | undefined = undefined
|
||||
|
||||
export let formData: {
|
||||
name: string
|
||||
displayName: string
|
||||
icon?: string
|
||||
banner?: string
|
||||
sidebar?: string
|
||||
nsfw: boolean
|
||||
postsLockedToModerators: boolean
|
||||
submitting: boolean
|
||||
visibility: 'Public' | 'LocalOnly'
|
||||
} = {
|
||||
name: '',
|
||||
displayName: '',
|
||||
sidebar: '',
|
||||
nsfw: false,
|
||||
postsLockedToModerators: false,
|
||||
submitting: false,
|
||||
visibility: 'Public',
|
||||
interface Props {
|
||||
/**
|
||||
* The community ID to edit.
|
||||
*/
|
||||
edit?: number
|
||||
formData?: {
|
||||
name: string
|
||||
displayName: string
|
||||
icon?: string
|
||||
banner?: string
|
||||
sidebar?: string
|
||||
nsfw: boolean
|
||||
postsLockedToModerators: boolean
|
||||
submitting: boolean
|
||||
visibility: 'Public' | 'LocalOnly'
|
||||
languages?: number[]
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
edit = undefined,
|
||||
formData: passedFormData = $bindable({
|
||||
name: '',
|
||||
displayName: '',
|
||||
sidebar: '',
|
||||
nsfw: false,
|
||||
postsLockedToModerators: false,
|
||||
submitting: false,
|
||||
visibility: 'Public',
|
||||
languages: undefined,
|
||||
}),
|
||||
formtitle,
|
||||
}: Props = $props()
|
||||
|
||||
let formData = $state(passedFormData)
|
||||
|
||||
async function submit() {
|
||||
if (!$profile?.jwt) return
|
||||
if (!profile.data?.jwt) return
|
||||
if ((!edit && formData.name == '') || formData.displayName == '') return
|
||||
|
||||
formData.submitting = true
|
||||
@@ -57,6 +75,7 @@
|
||||
banner: formData.banner,
|
||||
community_id: edit,
|
||||
visibility: formData.visibility,
|
||||
discussion_languages: formData.languages,
|
||||
})
|
||||
: await getClient().createCommunity({
|
||||
name: formData.name,
|
||||
@@ -67,6 +86,7 @@
|
||||
icon: formData.icon,
|
||||
banner: formData.banner,
|
||||
visibility: formData.visibility,
|
||||
discussion_languages: formData.languages,
|
||||
})
|
||||
|
||||
toast({
|
||||
@@ -74,23 +94,23 @@
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
if ($profile.user) {
|
||||
const c = $profile.user.moderates
|
||||
if (profile.data.user) {
|
||||
const c = profile.data.user.moderates
|
||||
.map((m) => m.community.id)
|
||||
.indexOf(res.community_view.community.id)
|
||||
if (c != -1) {
|
||||
$profile.user.moderates[c] = {
|
||||
profile.data.user.moderates[c] = {
|
||||
community: res.community_view.community,
|
||||
moderator: $profile.user.local_user_view.person,
|
||||
moderator: profile.data.user.local_user_view.person,
|
||||
}
|
||||
} else {
|
||||
$profile.user = {
|
||||
...$profile.user,
|
||||
profile.data.user = {
|
||||
...profile.data.user,
|
||||
moderates: [
|
||||
...$profile.user.moderates,
|
||||
...profile.data.user.moderates,
|
||||
{
|
||||
community: res.community_view.community,
|
||||
moderator: $profile.user.local_user_view.person,
|
||||
moderator: profile.data.user.local_user_view.person,
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -103,7 +123,7 @@
|
||||
goto(
|
||||
`/c/${res.community_view.community.name}@${
|
||||
new URL(res.community_view.community.actor_id).hostname
|
||||
}`
|
||||
}`,
|
||||
)
|
||||
} catch (err) {
|
||||
toast({
|
||||
@@ -115,24 +135,24 @@
|
||||
formData.submitting = false
|
||||
}
|
||||
|
||||
let uploading = {
|
||||
let uploading = $state({
|
||||
banner: false,
|
||||
icon: false,
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<form
|
||||
on:submit|preventDefault={submit}
|
||||
onsubmit={preventDefault(submit)}
|
||||
class="flex flex-col gap-4 h-full w-full"
|
||||
>
|
||||
<slot name="formtitle">
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header>{$t('routes.createCommunity')}</Header>
|
||||
</slot>
|
||||
{/if}
|
||||
<TextInput
|
||||
required
|
||||
label={$t('form.name')}
|
||||
bind:value={formData.name}
|
||||
on:input={() => {
|
||||
oninput={() => {
|
||||
formData.name = formData.name.toLowerCase().replaceAll(' ', '_')
|
||||
}}
|
||||
disabled={edit != undefined}
|
||||
@@ -147,7 +167,7 @@
|
||||
<Label>{$t('routes.admin.config.icon')}</Label>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => (uploading.icon = !uploading.icon)}
|
||||
onclick={() => (uploading.icon = !uploading.icon)}
|
||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||
>
|
||||
{#if formData.icon}
|
||||
@@ -164,9 +184,9 @@
|
||||
<ImageUploadModal
|
||||
bind:open={uploading.icon}
|
||||
multiple={false}
|
||||
on:upload={(uploaded) => {
|
||||
onupload={(uploaded) => {
|
||||
uploading.icon = false
|
||||
formData.icon = uploaded.detail[0]
|
||||
formData.icon = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
@@ -175,7 +195,7 @@
|
||||
<Label>{$t('routes.admin.config.banner')}</Label>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => (uploading.banner = !uploading.banner)}
|
||||
onclick={() => (uploading.banner = !uploading.banner)}
|
||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||
>
|
||||
{#if formData.banner}
|
||||
@@ -192,9 +212,9 @@
|
||||
<ImageUploadModal
|
||||
bind:open={uploading.banner}
|
||||
multiple={false}
|
||||
on:upload={(uploaded) => {
|
||||
onupload={(uploaded) => {
|
||||
uploading.banner = false
|
||||
formData.banner = uploaded.detail[0]
|
||||
formData.banner = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
@@ -211,9 +231,57 @@
|
||||
Only moderators can post
|
||||
</Switch>
|
||||
<Select label="Visibility" class="w-max" bind:value={formData.visibility}>
|
||||
<option value="Public">Public</option>
|
||||
<option value="LocalOnly">Local Only</option>
|
||||
<Option icon={GlobeAlt} value="Public">Public</Option>
|
||||
<Option icon={MapPin} value="LocalOnly">Local Only</Option>
|
||||
</Select>
|
||||
|
||||
<div class="space-y-1">
|
||||
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
|
||||
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
|
||||
{#if site.data}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
</Badge>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#each site.data.all_languages.filter((l) => !formData.languages?.includes(l.id)) as language, index}
|
||||
<MenuButton
|
||||
class="min-h-[16px] py-0"
|
||||
onclick={() => {
|
||||
formData.languages = [
|
||||
...(formData.languages ?? []),
|
||||
language.id,
|
||||
]
|
||||
}}
|
||||
>
|
||||
{language.name}
|
||||
</MenuButton>
|
||||
{/each}
|
||||
</Menu>
|
||||
{#each formData.languages ?? [] as languageId, index}
|
||||
{@const language = site.data.all_languages.find(
|
||||
(l) => l.id == languageId,
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
class="hover:brightness-150 transition-all"
|
||||
onclick={() => {
|
||||
formData.languages?.splice(index, 1)
|
||||
}}
|
||||
>
|
||||
<Badge class="cursor-pointer">{language?.name}</Badge>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Material>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
submit
|
||||
color="primary"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
import { fullCommunityName } from '$lib/util.svelte'
|
||||
import type {
|
||||
Community,
|
||||
CommunityAggregates,
|
||||
@@ -30,16 +30,29 @@
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import { isAdmin } from '../moderation/moderation'
|
||||
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
|
||||
export let community: Community
|
||||
export let subscribed: SubscribedType
|
||||
export let counts: CommunityAggregates | undefined = undefined
|
||||
export let moderators: CommunityModeratorView[] = []
|
||||
export let blocked: boolean = false
|
||||
interface Props {
|
||||
community: Community
|
||||
subscribed: SubscribedType
|
||||
counts?: CommunityAggregates | undefined
|
||||
moderators?: CommunityModeratorView[]
|
||||
blocked?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
community = $bindable(),
|
||||
subscribed = $bindable(),
|
||||
counts = undefined,
|
||||
moderators = [],
|
||||
blocked = false,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<EntityHeader
|
||||
banner={community.banner}
|
||||
banner={settings.nsfwBlur && community.nsfw ? undefined : community.banner}
|
||||
avatar={community.icon}
|
||||
name={community.title}
|
||||
url="/c/{fullCommunityName(community.name, community.actor_id)}"
|
||||
@@ -67,29 +80,27 @@
|
||||
]
|
||||
: []}
|
||||
bio={community.description}
|
||||
class={$$props.class}
|
||||
class={clazz}
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
navigator?.clipboard?.writeText?.(
|
||||
`!${fullCommunityName(community.name, community.actor_id)}`
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="text-sm flex gap-0 items-center"
|
||||
slot="nameDetail"
|
||||
>
|
||||
!{fullCommunityName(community.name, community.actor_id)}
|
||||
</button>
|
||||
{#if moderators.length > 0}
|
||||
<Expandable
|
||||
class="border rounded-xl bg-white/50 dark:bg-zinc-900/50 w-full p-3 px-4
|
||||
dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text-zinc-300 transition-colors"
|
||||
{#snippet nameDetail()}
|
||||
<button
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText?.(
|
||||
`!${fullCommunityName(community.name, community.actor_id)}`,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="text-sm flex gap-0 items-center"
|
||||
>
|
||||
<svelte:fragment slot="title">
|
||||
<ShieldIcon width={15} filled />
|
||||
!{fullCommunityName(community.name, community.actor_id)}
|
||||
</button>
|
||||
{/snippet}
|
||||
{#if moderators.length > 0}
|
||||
<Expandable class="">
|
||||
{#snippet title()}
|
||||
{$t('cards.community.moderators')}
|
||||
</svelte:fragment>
|
||||
<hr class="flex-1 border-slate-200 dark:border-zinc-800 mx-3" />
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={moderators.map((m) => ({
|
||||
id: m.moderator.id,
|
||||
@@ -101,8 +112,8 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
<div class="flex items-center gap-2 h-max">
|
||||
{#if $profile?.jwt}
|
||||
<div class="flex items-center gap-2 h-max w-max">
|
||||
{#if profile.data?.jwt}
|
||||
<Subscribe
|
||||
community={{
|
||||
community: community,
|
||||
@@ -112,34 +123,36 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
counts: counts ?? {},
|
||||
subscribed: subscribed,
|
||||
}}
|
||||
let:subscribe
|
||||
let:subscribing
|
||||
>
|
||||
<Button
|
||||
disabled={subscribing}
|
||||
loading={subscribing}
|
||||
size="lg"
|
||||
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
||||
on:click={async () => {
|
||||
subscribed =
|
||||
(await subscribe())?.community_view.subscribed ?? 'NotSubscribed'
|
||||
}}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
>
|
||||
<Icon
|
||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{#snippet children({ subscribe, subscribing })}
|
||||
<Button
|
||||
disabled={subscribing}
|
||||
loading={subscribing}
|
||||
size="lg"
|
||||
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
||||
onclick={async () => {
|
||||
subscribed =
|
||||
(await subscribe())?.community_view.subscribed ??
|
||||
'NotSubscribed'
|
||||
}}
|
||||
class="relative px-8 z-[inherit]"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Subscribe>
|
||||
{/if}
|
||||
|
||||
{#if $profile?.user && $profile.user.moderates
|
||||
{#if profile.data?.user && profile.data.user.moderates
|
||||
.map((c) => c.community.id)
|
||||
.includes(community.id)}
|
||||
<Button
|
||||
@@ -148,7 +161,7 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
rounding="xl"
|
||||
href="/c/{fullCommunityName(
|
||||
community.name,
|
||||
community.actor_id
|
||||
community.actor_id,
|
||||
)}/settings"
|
||||
style="height: 38px; width: 38px;"
|
||||
>
|
||||
@@ -156,43 +169,46 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
</Button>
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
<Button
|
||||
rounding="xl"
|
||||
size="custom"
|
||||
slot="target"
|
||||
style="height: 38px; width: 38px;"
|
||||
>
|
||||
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button rounding="xl" size="custom" style="height: 38px; width: 38px;">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuButton href="/modlog?community={community.id}">
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
</MenuButton>
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
on:click={() => block(community.id, !blocked)}
|
||||
onclick={() => block(community.id, !blocked)}
|
||||
>
|
||||
<Icon src={NoSymbol} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={NoSymbol} size="16" mini />
|
||||
{/snippet}
|
||||
{blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
</MenuButton>
|
||||
{#if $profile?.user}
|
||||
{#if profile.data?.user}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
size="lg"
|
||||
on:click={() => blockInstance(community.instance_id)}
|
||||
onclick={() => blockInstance(community.instance_id)}
|
||||
>
|
||||
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BuildingOffice2} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
modal({
|
||||
title: $t('admin.purgeCommunity.title'),
|
||||
body: `${community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
||||
@@ -213,7 +229,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
type: 'error',
|
||||
})}
|
||||
>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -5,16 +5,20 @@
|
||||
import {
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
Check,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
MapPin,
|
||||
NoSymbol,
|
||||
PencilSquare,
|
||||
Plus,
|
||||
Trash,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import { fullCommunityName, isSubscribed } from '$lib/util.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||
@@ -23,11 +27,22 @@
|
||||
import { t } from '$lib/translations'
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
|
||||
export let community: CommunityView
|
||||
export let view: 'cozy' | 'compact' = 'compact'
|
||||
export let showCounts: boolean = true
|
||||
let showInfo = $state(false)
|
||||
interface Props {
|
||||
community: CommunityView
|
||||
view?: 'cozy' | 'compact'
|
||||
showCounts?: boolean
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let showInfo = false
|
||||
let {
|
||||
community = $bindable(),
|
||||
view = 'compact',
|
||||
showCounts = true,
|
||||
class: clazz = 'py-4 flex flex-col gap-4 text-sm max-w-full relative',
|
||||
icon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if showInfo}
|
||||
@@ -36,10 +51,7 @@
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<div
|
||||
class={$$props.class ??
|
||||
'py-4 flex flex-col gap-4 text-sm max-w-full relative'}
|
||||
>
|
||||
<div class={clazz}>
|
||||
<div
|
||||
class="flex
|
||||
{view == 'cozy'
|
||||
@@ -49,7 +61,7 @@
|
||||
<a
|
||||
href="/c/{fullCommunityName(
|
||||
community.community.name,
|
||||
community.community.actor_id
|
||||
community.community.actor_id,
|
||||
)}"
|
||||
class="flex-1 w-full overflow-hidden"
|
||||
data-sveltekit-preload-data="tap"
|
||||
@@ -59,18 +71,54 @@
|
||||
? 'flex-col gap-2'
|
||||
: 'flex-row'} gap-2 items-center"
|
||||
>
|
||||
<slot name="icon">
|
||||
{#if icon}{@render icon()}{:else}
|
||||
<Avatar
|
||||
url={community.community.icon}
|
||||
width={32}
|
||||
alt={community.community.name}
|
||||
/>
|
||||
</slot>
|
||||
{/if}
|
||||
<div
|
||||
class="flex flex-col overflow-hidden whitespace-nowrap flex-1 min-w-0 flex-shrink"
|
||||
>
|
||||
<div class="font-medium text-base overflow-hidden overflow-ellipsis">
|
||||
{community.community.title}
|
||||
<span>{community.community.title}</span>
|
||||
{#if community.community.deleted}
|
||||
<Icon
|
||||
src={Trash}
|
||||
class="text-red-500 inline"
|
||||
micro
|
||||
size="14"
|
||||
title={$t('post.badges.deleted')}
|
||||
/>
|
||||
{/if}
|
||||
{#if community.community.nsfw}
|
||||
<Icon
|
||||
src={ExclamationTriangle}
|
||||
class="text-red-500 inline"
|
||||
micro
|
||||
size="14"
|
||||
title={$t('post.badges.nsfw')}
|
||||
/>
|
||||
{/if}
|
||||
{#if community.banned_from_community}
|
||||
<Icon
|
||||
src={NoSymbol}
|
||||
class="text-red-500 inline"
|
||||
micro
|
||||
size="14"
|
||||
title={$t('comment.banned')}
|
||||
/>
|
||||
{/if}
|
||||
{#if community.community.visibility == 'LocalOnly'}
|
||||
<Icon
|
||||
src={MapPin}
|
||||
class="text-green-500 inline"
|
||||
micro
|
||||
size="14"
|
||||
title={$t('routes.admin.config.listingType.local')}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<div
|
||||
class="text-sm text-slate-600 dark:text-zinc-400 flex gap-0.5"
|
||||
@@ -90,53 +138,58 @@
|
||||
</div>
|
||||
</a>
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<Button size="square-md" on:click={() => (showInfo = !showInfo)}>
|
||||
<Icon src={InformationCircle} size="16" micro />
|
||||
<Button size="square-md" onclick={() => (showInfo = !showInfo)}>
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
</Button>
|
||||
<Subscribe {community} let:subscribe let:subscribing>
|
||||
<Button
|
||||
disabled={subscribing || !$profile?.jwt}
|
||||
loading={subscribing}
|
||||
on:click={async () => {
|
||||
const res = await subscribe()
|
||||
<Subscribe {community}>
|
||||
{#snippet children({ subscribe, subscribing })}
|
||||
<Button
|
||||
disabled={subscribing || !profile.data?.jwt}
|
||||
loading={subscribing}
|
||||
onclick={async () => {
|
||||
const res = await subscribe()
|
||||
|
||||
if (res) {
|
||||
const newSubscribed =
|
||||
res.community_view.subscribed != 'NotSubscribed'
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'
|
||||
if (res) {
|
||||
const newSubscribed =
|
||||
res.community_view.subscribed != 'NotSubscribed'
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'
|
||||
|
||||
community.subscribed = newSubscribed
|
||||
addSubscription(
|
||||
community.community,
|
||||
newSubscribed == 'Subscribed'
|
||||
)
|
||||
}
|
||||
}}
|
||||
size="custom"
|
||||
title={isSubscribed(community.subscribed)
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
color={isSubscribed(community.subscribed) ? 'elevatedLow' : 'primary'}
|
||||
class="{isSubscribed(community.subscribed)
|
||||
? 'text-slate-600 dark:text-zinc-400'
|
||||
: ''}
|
||||
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
|
||||
>
|
||||
<Icon
|
||||
src={isSubscribed(community.subscribed) ? Check : Plus}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>
|
||||
<span class="hidden @md:block">
|
||||
{#if isSubscribed(community.subscribed)}
|
||||
{$t('cards.community.subscribed')}
|
||||
{:else}
|
||||
{$t('cards.community.subscribe')}
|
||||
{/if}
|
||||
</span>
|
||||
</Button>
|
||||
community.subscribed = newSubscribed
|
||||
addSubscription(
|
||||
community.community,
|
||||
newSubscribed == 'Subscribed',
|
||||
)
|
||||
}
|
||||
}}
|
||||
size="custom"
|
||||
title={isSubscribed(community.subscribed)
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
color={isSubscribed(community.subscribed)
|
||||
? 'elevatedLow'
|
||||
: 'primary'}
|
||||
class="{isSubscribed(community.subscribed)
|
||||
? 'text-slate-600 dark:text-zinc-400'
|
||||
: ''}
|
||||
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={isSubscribed(community.subscribed) ? Check : Plus}
|
||||
size="16"
|
||||
micro
|
||||
/>
|
||||
{/snippet}
|
||||
<span class="hidden @md:block">
|
||||
{#if isSubscribed(community.subscribed)}
|
||||
{$t('cards.community.subscribed')}
|
||||
{:else}
|
||||
{$t('cards.community.subscribe')}
|
||||
{/if}
|
||||
</span>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Subscribe>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,27 +1,42 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let community: Community
|
||||
|
||||
export let avatar: boolean = false
|
||||
export let name: boolean = true
|
||||
export let avatarSize: number = 24
|
||||
export let showInstance: boolean = $userSettings.showInstances.community
|
||||
export let displayName: boolean = true
|
||||
|
||||
export let badges = {
|
||||
nsfw: false,
|
||||
interface Props {
|
||||
community: Community
|
||||
avatar?: boolean
|
||||
name?: boolean
|
||||
avatarSize?: number
|
||||
showInstance?: boolean
|
||||
displayName?: boolean
|
||||
badges?: any
|
||||
class?: string
|
||||
instanceClass?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
community,
|
||||
avatar = false,
|
||||
name = true,
|
||||
avatarSize = 24,
|
||||
showInstance = settings.showInstances.community,
|
||||
displayName = true,
|
||||
badges = {
|
||||
nsfw: false,
|
||||
},
|
||||
class: clazz = '',
|
||||
instanceClass = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...$$restProps}
|
||||
class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {$$props.class ||
|
||||
''}"
|
||||
{...rest}
|
||||
class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {clazz}"
|
||||
href="/c/{community.name}@{new URL(community.actor_id).hostname}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
@@ -42,7 +57,7 @@
|
||||
{#if showInstance}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 font-normal
|
||||
instance-text flex-shrink {$$props.instanceClass || ''}"
|
||||
instance-text flex-shrink {instanceClass || ''}"
|
||||
>
|
||||
@{new URL(community.actor_id).hostname}
|
||||
</span>
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
|
||||
export let community: Community
|
||||
interface Props {
|
||||
community: Community
|
||||
}
|
||||
|
||||
let { community }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-3 items-center">
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import { profile } from '$lib/auth'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { searchParam } from '$lib/util'
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { searchParam } from '$lib/util.svelte'
|
||||
import { Select } from 'mono-svelte'
|
||||
import {
|
||||
GlobeAmericas,
|
||||
@@ -13,73 +12,56 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import { amModOfAny } from '../moderation/moderation'
|
||||
import { t } from '$lib/translations'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
|
||||
export let selected: string
|
||||
export let navigate: boolean = true
|
||||
export let changeDefault: boolean = false
|
||||
export let showLabel: boolean = true
|
||||
interface Props {
|
||||
selected: string
|
||||
navigate?: boolean
|
||||
changeDefault?: boolean
|
||||
showLabel?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let feed: string = selected
|
||||
$: feed = selected
|
||||
$: changeDefault
|
||||
? ($userSettings.defaultSort.feed = selected as
|
||||
| 'All'
|
||||
| 'Subscribed'
|
||||
| 'Local')
|
||||
: undefined
|
||||
let {
|
||||
selected = $bindable(),
|
||||
navigate = true,
|
||||
changeDefault = false,
|
||||
showLabel = true,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Select
|
||||
{...$$restProps}
|
||||
bind:value={feed}
|
||||
on:change={() => {
|
||||
if (navigate) searchParam($page.url, 'type', feed, 'page', 'cursor')
|
||||
{...rest}
|
||||
bind:value={selected}
|
||||
onchange={() => {
|
||||
if (navigate) searchParam(page.url, 'type', selected, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="label">
|
||||
{#snippet customLabel()}
|
||||
{#if showLabel}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={GlobeAmericas} size="16" micro />
|
||||
{$t('filter.location.label')}
|
||||
</span>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<option value="All">
|
||||
<Icon
|
||||
src={GlobeAmericas}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{/snippet}
|
||||
<Option value="All" icon={GlobeAmericas}>
|
||||
{$t('filter.location.all')}
|
||||
</option>
|
||||
<option value="Local">
|
||||
<Icon
|
||||
src={MapPin}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.location.local')}
|
||||
</option>
|
||||
<option value="Subscribed" disabled={$profile?.jwt == undefined}>
|
||||
<Icon
|
||||
src={Newspaper}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="Local" icon={MapPin}>{$t('filter.location.local')}</Option>
|
||||
<Option
|
||||
value="Subscribed"
|
||||
disabled={profile.data?.jwt == undefined}
|
||||
icon={Newspaper}
|
||||
>
|
||||
{$t('filter.location.subscribed')}
|
||||
</option>
|
||||
<option
|
||||
</Option>
|
||||
<Option
|
||||
value="ModeratorView"
|
||||
disabled={!$profile?.jwt || !amModOfAny($profile?.user)}
|
||||
disabled={!profile.data?.jwt || !amModOfAny(profile.data?.user)}
|
||||
icon={ShieldCheck}
|
||||
>
|
||||
<Icon
|
||||
src={ShieldCheck}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{$t('filter.location.moderator')}
|
||||
</option>
|
||||
</Option>
|
||||
</Select>
|
||||
@@ -1,9 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { page } from '$app/state'
|
||||
import { t } from '$lib/translations'
|
||||
import { searchParam } from '$lib/util.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import { searchParam } from '$lib/util.svelte.js'
|
||||
import { Select } from 'mono-svelte'
|
||||
import {
|
||||
ArrowTrendingDown,
|
||||
@@ -24,215 +22,119 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
|
||||
export let selected: string
|
||||
export let navigate: boolean = true
|
||||
export let changeDefault: boolean = false
|
||||
|
||||
let sort: string = selected?.startsWith('Top') ? 'TopAll' : selected
|
||||
$: if (selected) {
|
||||
sort = selected?.startsWith('Top') ? 'TopAll' : selected
|
||||
interface Props {
|
||||
selected: string
|
||||
navigate?: boolean
|
||||
changeDefault?: boolean
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
selected = $bindable(),
|
||||
navigate = true,
|
||||
changeDefault = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let sort: string = $state(selected?.startsWith('Top') ? 'TopAll' : selected)
|
||||
const setSelected = () => (selected = sort)
|
||||
$: changeDefault
|
||||
? ($userSettings.defaultSort.sort = selected as SortType)
|
||||
: undefined
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row {$$props.class}">
|
||||
<div class="flex flex-row {clazz}">
|
||||
<Select
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class={selected?.startsWith('Top') ? 'rounded-r-none' : ''}
|
||||
bind:value={sort}
|
||||
on:change={(e) => {
|
||||
onchange={() => {
|
||||
setSelected()
|
||||
if (navigate) searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||
if (navigate) searchParam(page.url, 'sort', selected, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
<span slot="label" class="flex items-center gap-1">
|
||||
<Icon src={ChartBar} size="13" micro />
|
||||
{$t('filter.sort.label')}
|
||||
</span>
|
||||
<option value="Active">
|
||||
<Icon
|
||||
src={ArrowTrendingUp}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{#snippet customLabel()}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={ChartBar} size="13" micro />
|
||||
{$t('filter.sort.label')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<Option value="Active" icon={ArrowTrendingUp}>
|
||||
{$t('filter.sort.active')}
|
||||
</option>
|
||||
<option value="Hot">
|
||||
<Icon
|
||||
src={Fire}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="Hot" icon={Fire}>
|
||||
{$t('filter.sort.hot')}
|
||||
</option>
|
||||
<option value="Scaled">
|
||||
<Icon
|
||||
src={Scale}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="Scaled" icon={Scale}>
|
||||
{$t('filter.sort.scaled')}
|
||||
</option>
|
||||
<option value="TopAll">
|
||||
<Icon
|
||||
src={Trophy}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="TopAll" icon={Trophy}>
|
||||
{$t('filter.sort.top.label')}
|
||||
</option>
|
||||
<option value="New">
|
||||
<Icon
|
||||
src={Star}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="New" icon={Star}>
|
||||
{$t('filter.sort.new')}
|
||||
</option>
|
||||
<option value="Old">
|
||||
<Icon
|
||||
src={Clock}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="Old" icon={Clock}>
|
||||
{$t('filter.sort.old')}
|
||||
</option>
|
||||
<option value="Controversial">
|
||||
<Icon
|
||||
src={ArrowTrendingDown}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="Controversial" icon={ArrowTrendingDown}>
|
||||
{$t('filter.sort.controversial')}
|
||||
</option>
|
||||
<option value="MostComments">
|
||||
<Icon
|
||||
src={ChatBubbleOvalLeft}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="MostComments" icon={ChatBubbleOvalLeft}>
|
||||
{$t('filter.sort.mostcomments')}
|
||||
</option>
|
||||
<option value="NewComments">
|
||||
<Icon
|
||||
src={ChatBubbleLeftRight}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="NewComments" icon={ChatBubbleLeftRight}>
|
||||
{$t('filter.sort.newcomments')}
|
||||
</option>
|
||||
</Option>
|
||||
</Select>
|
||||
{#if selected?.startsWith('Top')}
|
||||
<div transition:fly={{ easing: backOut, x: 2 }}>
|
||||
<Select
|
||||
class="border-l-0 rounded-l-none"
|
||||
bind:value={selected}
|
||||
on:change={(e) => {
|
||||
onchange={() => {
|
||||
sort = 'TopAll'
|
||||
if (navigate)
|
||||
searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||
searchParam(page.url, 'sort', selected, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
<span slot="label" class="flex items-center gap-1">
|
||||
<Icon src={Clock} size="15" micro />
|
||||
{$t('filter.sort.top.time.label')}
|
||||
</span>
|
||||
<option value="TopAll">
|
||||
<Icon
|
||||
src={PlusCircle}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.all')}
|
||||
</option>
|
||||
<option value="TopNineMonths">
|
||||
<Icon
|
||||
src={Calendar}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{#snippet customLabel()}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={Clock} size="15" micro />
|
||||
{$t('filter.sort.top.time.label')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<Option value="TopAll" icon={PlusCircle}>
|
||||
{$t('filter.sort.top.time.all')}
|
||||
</Option>
|
||||
<Option value="TopNineMonths" icon={Calendar}>
|
||||
{$t('filter.sort.top.time.9months')}
|
||||
</option>
|
||||
<option value="TopSixMonths">
|
||||
<Icon
|
||||
src={Calendar}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="TopSixMonths" icon={Calendar}>
|
||||
{$t('filter.sort.top.time.6months')}
|
||||
</option>
|
||||
<option value="TopThreeMonths">
|
||||
<Icon
|
||||
src={Calendar}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="TopThreeMonths" icon={Calendar}>
|
||||
{$t('filter.sort.top.time.3months')}
|
||||
</option>
|
||||
<option value="TopMonth">
|
||||
<Icon
|
||||
src={CalendarDays}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.month')}
|
||||
</option>
|
||||
<option value="TopWeek">
|
||||
<Icon
|
||||
src={CalendarDays}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.week')}
|
||||
</option>
|
||||
<option value="TopDay">
|
||||
<Icon
|
||||
src={Sun}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.day')}
|
||||
</option>
|
||||
<option value="TopTwelveHour">
|
||||
<Icon
|
||||
src={Clock}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.12hours')}
|
||||
</option>
|
||||
<option value="TopSixHour">
|
||||
<Icon
|
||||
src={Clock}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.6hours')}
|
||||
</option>
|
||||
<option value="TopHour">
|
||||
<Icon
|
||||
src={Clock}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>{$t('filter.sort.top.time.hour')}
|
||||
</option>
|
||||
</Option>
|
||||
<Option value="TopMonth" icon={CalendarDays}>
|
||||
{$t('filter.sort.top.time.month')}
|
||||
</Option>
|
||||
<Option value="TopWeek" icon={CalendarDays}>
|
||||
{$t('filter.sort.top.time.week')}
|
||||
</Option>
|
||||
<Option value="TopDay" icon={Sun}>
|
||||
{$t('filter.sort.top.time.day')}
|
||||
</Option>
|
||||
<Option value="TopTwelveHour" icon={Clock}>
|
||||
{$t('filter.sort.top.time.12hours')}
|
||||
</Option>
|
||||
<Option value="TopSixHour" icon={Clock}>
|
||||
{$t('filter.sort.top.time.6hours')}
|
||||
</Option>
|
||||
<Option value="TopHour" icon={Clock}>
|
||||
{$t('filter.sort.top.time.hour')}
|
||||
</Option>
|
||||
</Select>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import { Select } from 'mono-svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import {
|
||||
Bars3,
|
||||
Clock,
|
||||
@@ -13,43 +14,27 @@
|
||||
ViewColumns,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let showLabel = true
|
||||
interface Props {
|
||||
showLabel?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { showLabel = true, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Select {...$$restProps} bind:value={$userSettings.view}>
|
||||
<svelte:fragment slot="label">
|
||||
<Select {...rest} bind:value={settings.view}>
|
||||
{#snippet customLabel()}
|
||||
{#if showLabel}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={ViewColumns} size="14" micro />
|
||||
{$t('filter.view.label')}
|
||||
</span>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
<option value="cozy">
|
||||
<Icon
|
||||
src={RectangleGroup}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{/snippet}
|
||||
<Option value="cozy" icon={RectangleGroup}>
|
||||
{$t('filter.view.cozy')}
|
||||
</option>
|
||||
<option value="list">
|
||||
<Icon
|
||||
src={QueueList}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{$t('filter.view.list')}
|
||||
</option>
|
||||
<option value="compact">
|
||||
<Icon
|
||||
src={Bars3}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Option>
|
||||
<Option value="compact" icon={Bars3}>
|
||||
{$t('filter.view.compact')}
|
||||
</option>
|
||||
</Option>
|
||||
</Select>
|
||||
@@ -5,13 +5,17 @@
|
||||
import { flip } from 'svelte/animate'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
|
||||
export let items: {
|
||||
avatar?: string
|
||||
name: string
|
||||
instance?: string
|
||||
id: number
|
||||
url: string
|
||||
}[]
|
||||
interface Props {
|
||||
items: {
|
||||
avatar?: string
|
||||
name: string
|
||||
instance?: string
|
||||
id: number
|
||||
url: string
|
||||
}[]
|
||||
}
|
||||
|
||||
let { items }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#each items.sort((a, b) => a.name.localeCompare(b.name)) as item (item.id)}
|
||||
@@ -31,7 +35,6 @@
|
||||
alt={item.name}
|
||||
title={item.name}
|
||||
width={24}
|
||||
slot="prefix"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col max-w-full break-words">
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||
import type { PrivateMessageView } from 'lemmy-js-client'
|
||||
|
||||
export let message: PrivateMessageView
|
||||
export let meta: boolean = true
|
||||
interface Props {
|
||||
message: PrivateMessageView
|
||||
meta?: boolean
|
||||
style?: string
|
||||
}
|
||||
|
||||
let { message, meta = true, style = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 text-sm" style={$$props.style ?? ''}>
|
||||
<div class="flex flex-col gap-2 text-sm" {style}>
|
||||
{#if meta}
|
||||
<div class="flex flex-row gap-2 items-center flex-wrap">
|
||||
<span class="font-medium text-xs">From</span>
|
||||
@@ -18,7 +24,7 @@
|
||||
avatar
|
||||
avatarSize={20}
|
||||
/>
|
||||
{#if $profile?.user?.local_user_view.person.id != message.recipient.id}
|
||||
{#if profile.data?.user?.local_user_view.person.id != message.recipient.id}
|
||||
to
|
||||
<UserLink
|
||||
showInstance={false}
|
||||
@@ -29,5 +35,10 @@
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<Markdown source={message.private_message.content} />
|
||||
<TextProps wrap="no-wrap">
|
||||
<Markdown
|
||||
rendererOptions={{ autoloadImages: false }}
|
||||
source={message.private_message.content}
|
||||
/>
|
||||
</TextProps>
|
||||
</div>
|
||||
@@ -1,16 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import type { Person } from 'lemmy-js-client'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
|
||||
export let open: boolean = false
|
||||
export let user: Person
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person
|
||||
denying: boolean
|
||||
denyReason?: string
|
||||
}
|
||||
|
||||
export let denying: boolean
|
||||
|
||||
export let denyReason: string = ''
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user,
|
||||
denying = $bindable(),
|
||||
denyReason = $bindable(''),
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
|
||||
@@ -21,10 +30,12 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<h1 class="text-2xl font-bold" slot="title">
|
||||
{$t('routes.admin.applications.modalTitle')}
|
||||
</h1>
|
||||
<form on:submit|preventDefault={() => deny()} class="flex flex-col gap-4">
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">
|
||||
{$t('routes.admin.applications.modalTitle')}
|
||||
</h1>
|
||||
{/snippet}
|
||||
<form onsubmit={preventDefault(() => deny())} class="flex flex-col gap-4">
|
||||
<UserLink avatar {user} />
|
||||
<MarkdownEditor
|
||||
bind:value={denyReason}
|
||||
|
||||
@@ -1,29 +1,38 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import ProgressBar from '$lib/components/ui/ProgressBar.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { t } from '$lib/translations'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { ImageInput, Spinner, toast } from 'mono-svelte'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
export let open: boolean
|
||||
export let image: FileList | null = null
|
||||
export let preview: boolean = true
|
||||
export let multiple: boolean = true
|
||||
let progress = 1
|
||||
interface Props {
|
||||
open: boolean
|
||||
image?: FileList | null
|
||||
preview?: boolean
|
||||
multiple?: boolean
|
||||
onupload?: (urls: string[]) => void
|
||||
}
|
||||
|
||||
$: previewURLs =
|
||||
let {
|
||||
open = $bindable(),
|
||||
image = $bindable(null),
|
||||
preview = true,
|
||||
multiple = true,
|
||||
onupload,
|
||||
}: Props = $props()
|
||||
let progress = $state(1)
|
||||
|
||||
let previewURLs = $derived(
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined
|
||||
|
||||
const dispatcher = createEventDispatcher<{ upload: string[] }>()
|
||||
)
|
||||
|
||||
async function upload() {
|
||||
if (!$profile?.jwt || image == null) return
|
||||
if (!profile.data?.jwt || image == null) return
|
||||
|
||||
progress = 0
|
||||
|
||||
@@ -31,7 +40,7 @@
|
||||
const uploaded = (
|
||||
await Promise.all(
|
||||
Array.from(image).map((i) =>
|
||||
uploadImage(i, $profile.instance, $profile.jwt!)
|
||||
uploadImage(i, profile.data.instance, profile.data.jwt!)
|
||||
.then((uploaded) => {
|
||||
progress += 1 / (image?.length ?? 0)
|
||||
return uploaded
|
||||
@@ -46,7 +55,7 @@
|
||||
|
||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||
|
||||
dispatcher('upload', uploaded)
|
||||
onupload?.(uploaded)
|
||||
progress = 1
|
||||
open = false
|
||||
} catch (err) {
|
||||
@@ -61,13 +70,21 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<div slot="title" class="flex items-center gap-2">Upload image</div>
|
||||
{#snippet customTitle()}
|
||||
<div class="flex items-center gap-2">Upload image</div>
|
||||
{/snippet}
|
||||
{#if progress != 1}
|
||||
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
||||
<ProgressBar {progress} />
|
||||
</div>
|
||||
{/if}
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={upload}>
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
upload()
|
||||
}}
|
||||
>
|
||||
<label
|
||||
for="image-input"
|
||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
||||
@@ -79,10 +96,10 @@
|
||||
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
|
||||
>
|
||||
{#each previewURLs as file}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={file}
|
||||
on:load={() => URL.revokeObjectURL(file)}
|
||||
onload={() => URL.revokeObjectURL(file)}
|
||||
alt={file}
|
||||
class="w-full rounded-md h-full object-cover transition-all
|
||||
border border-slate-200 dark:border-zinc-800 ring-1
|
||||
@@ -91,9 +108,12 @@
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-col justify-center w-full items-center gap-2">
|
||||
<div
|
||||
class="flex flex-col justify-center w-full items-center gap-2
|
||||
text-slate-600 dark:text-zinc-400"
|
||||
>
|
||||
<Icon src={DocumentPlus} size="32" />
|
||||
<span>{$t('form.post.selectFile')}</span>
|
||||
<span class="font-medium text-sm">{$t('form.post.selectFile')}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import type { Person } from 'lemmy-js-client'
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
import { Icon, PaperAirplane } from 'svelte-hero-icons'
|
||||
|
||||
export let open: boolean = false
|
||||
export let user: Person
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person
|
||||
}
|
||||
|
||||
let message = ''
|
||||
let { open = $bindable(false), user }: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let message = $state('')
|
||||
|
||||
let loading = $state(false)
|
||||
|
||||
async function sendMessage() {
|
||||
if (!$profile?.jwt || message == '') return
|
||||
if (!profile.data?.jwt || message == '') return
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -44,8 +50,10 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
||||
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">Message</h1>
|
||||
{/snippet}
|
||||
<form onsubmit={preventDefault(sendMessage)} class="flex flex-col gap-4">
|
||||
<p class="inline-flex flex-row gap-2 items-center">
|
||||
<Icon src={PaperAirplane} size="16" mini />
|
||||
<UserLink avatar {user} />
|
||||
|
||||
@@ -1,65 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import CommunityLink from '../community/CommunityLink.svelte'
|
||||
import Duration from '$lib/components/form/Duration.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
|
||||
export let open = false
|
||||
let item: Person | undefined
|
||||
export { item as user }
|
||||
export let community: Community | undefined
|
||||
export let banned: boolean
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person | undefined
|
||||
community: Community | undefined
|
||||
banned: boolean
|
||||
}
|
||||
|
||||
let reason = ''
|
||||
let deleteData = false
|
||||
let expires = ''
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user: item = $bindable(),
|
||||
community,
|
||||
banned,
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let reason = $state('')
|
||||
let deleteData = $state(false)
|
||||
let expires = $state(-1)
|
||||
let loading = $state(false)
|
||||
|
||||
// hack due to svelte's reactive declarations
|
||||
const resetReason = () => {
|
||||
reason = ''
|
||||
deleteData = false
|
||||
expires = ''
|
||||
expires = -1
|
||||
}
|
||||
|
||||
$: if (item) resetReason()
|
||||
$effect(() => {
|
||||
if (item) resetReason()
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!item || !$profile?.user || !$profile?.jwt) return
|
||||
if (!item || !profile.data?.user || !profile.data?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
let date: number | undefined
|
||||
|
||||
if (expires != '') {
|
||||
date = Date.parse(expires)
|
||||
if (Number.isNaN(date)) {
|
||||
toast({
|
||||
content: $t('toast.invalidDateAbsolute'),
|
||||
type: 'error',
|
||||
})
|
||||
|
||||
loading = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (date < Date.now()) {
|
||||
toast({
|
||||
content: $t('toast.invalidDateBeforeCurrent'),
|
||||
type: 'error',
|
||||
})
|
||||
|
||||
loading = false
|
||||
return
|
||||
}
|
||||
if (expires > 0) {
|
||||
date = Math.floor(Date.now() / 1000) + expires
|
||||
}
|
||||
|
||||
if (community) {
|
||||
@@ -69,7 +62,7 @@
|
||||
person_id: item.id,
|
||||
reason: reason || undefined,
|
||||
remove_data: deleteData,
|
||||
expires: date ? Math.floor(date / 1000) : undefined,
|
||||
expires: date,
|
||||
})
|
||||
} else {
|
||||
await getClient().banPerson({
|
||||
@@ -77,7 +70,7 @@
|
||||
person_id: item.id,
|
||||
reason: reason || undefined,
|
||||
remove_data: deleteData,
|
||||
expires: date ? Math.floor(date / 1000) : undefined,
|
||||
expires: date,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -105,7 +98,7 @@
|
||||
title={banned ? $t('moderation.ban.unbanning') : $t('moderation.ban.banning')}
|
||||
>
|
||||
{#if item}
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={submit}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(submit)}>
|
||||
<div class="flex items-center gap-1">
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<span class="font-bold">{item.name}</span>
|
||||
@@ -121,15 +114,14 @@
|
||||
{#if !banned}
|
||||
<Checkbox bind:checked={deleteData}>
|
||||
{$t('moderation.ban.deleteData')}
|
||||
<svelte:fragment slot="description">
|
||||
{#snippet description()}
|
||||
{$t('moderation.ban.warning')}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</Checkbox>
|
||||
<TextInput
|
||||
bind:value={expires}
|
||||
label={$t('moderation.ban.expires')}
|
||||
placeholder="2024 August 5"
|
||||
/>
|
||||
<div>
|
||||
<SectionTitle>{$t('moderation.ban.expires')}</SectionTitle>
|
||||
<Duration bind:value={expires}></Duration>
|
||||
</div>
|
||||
{/if}
|
||||
<Button submit color="primary" {loading} disabled={loading} size="lg">
|
||||
{$t('form.submit')}
|
||||
|
||||
@@ -9,34 +9,42 @@
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { isCommentView } from '$lib/lemmy/item.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||
<Button
|
||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
slot="target"
|
||||
color="tertiary"
|
||||
{...$$restProps}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
||||
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
{/if}
|
||||
</MenuDivider>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{/snippet}
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
? $t('moderation.restore')
|
||||
@@ -45,14 +53,16 @@
|
||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||
{#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id}
|
||||
<!--Comment made by someone else-->
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{/snippet}
|
||||
{item.creator_banned_from_community
|
||||
? $t('moderation.ban.unbanFromCommunity')
|
||||
: $t('moderation.ban.banFromCommunity')}
|
||||
@@ -61,18 +71,20 @@
|
||||
<!--Comment made by self-->
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
on:click={async () => {
|
||||
if (!$profile.jwt) return
|
||||
onclick={async () => {
|
||||
if (!profile.data.jwt) return
|
||||
item.comment = (
|
||||
await feature(
|
||||
!item.comment.distinguished,
|
||||
item.comment,
|
||||
$profile.jwt
|
||||
profile.data.jwt,
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Megaphone} size="16" micro />
|
||||
{/snippet}
|
||||
{item.comment.distinguished
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
@@ -80,10 +92,12 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { getClient } from '$lib/lemmy'
|
||||
import { getClient } from '$lib/lemmy.svelte'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import { amMod, ban, isAdmin, remove } from './moderation'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
Fire,
|
||||
Icon,
|
||||
LockClosed,
|
||||
@@ -13,20 +14,25 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import ShieldIcon from './ShieldIcon.svelte'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let locking = false
|
||||
let pinning = false
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
|
||||
$: acting = locking || pinning
|
||||
let locking = $state(false)
|
||||
let pinning = $state(false)
|
||||
|
||||
let acting = $derived(locking || pinning)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!$profile?.jwt || !isPostView(item)) return
|
||||
if (!profile.data?.jwt || !isPostView(item)) return
|
||||
locking = true
|
||||
|
||||
try {
|
||||
@@ -47,7 +53,7 @@
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||
if (!$profile?.jwt || !isPostView(item)) return
|
||||
if (!profile.data?.jwt || !isPostView(item)) return
|
||||
|
||||
pinning = true
|
||||
|
||||
@@ -71,19 +77,20 @@
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
<Button
|
||||
class="hover:!text-green-500"
|
||||
slot="target"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...$$restProps}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="hover:!text-green-500"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
||||
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
@@ -91,22 +98,19 @@
|
||||
</MenuDivider>
|
||||
<MenuButton
|
||||
color="warning-subtle"
|
||||
on:click={() => lock(!item.post.locked)}
|
||||
onclick={() => lock(!item.post.locked)}
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
>
|
||||
<Icon
|
||||
src={item.post.locked ? LockOpen : LockClosed}
|
||||
size="16"
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||
{/snippet}
|
||||
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
||||
</MenuButton>
|
||||
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
pin(isPostView(item) ? !item.post.featured_community : false)}
|
||||
loading={pinning}
|
||||
disabled={pinning}
|
||||
@@ -120,12 +124,12 @@
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</span>
|
||||
{#if isAdmin($profile.user)}
|
||||
{#if isAdmin(profile.data.user)}
|
||||
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</MenuButton>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
@@ -135,10 +139,10 @@
|
||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id}
|
||||
{#if profile.data?.user && profile.data.user.local_user_view.person.id != item.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
@@ -148,11 +152,11 @@
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
pin(isPostView(item) ? !item.post.featured_local : false, true)}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" mini />
|
||||
@@ -167,7 +171,7 @@
|
||||
<span class="text-xs opacity-80">{$t('admin.instance')}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item, true)}>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
|
||||
@@ -1,36 +1,49 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { Select, Switch, toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { fullCommunityName } from '$lib/util.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||
import { amMod, isAdmin } from './moderation'
|
||||
import { Button, Checkbox, Modal } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
export let purge: boolean = false
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | undefined
|
||||
purge?: boolean
|
||||
}
|
||||
|
||||
let reason = ''
|
||||
let commentReason: boolean = false
|
||||
let privateMessage: boolean = false
|
||||
let loading = false
|
||||
let preset = $userSettings.moderation.presets[0]?.content ?? ''
|
||||
let {
|
||||
open = $bindable(),
|
||||
item = $bindable(undefined),
|
||||
purge = false,
|
||||
}: Props = $props()
|
||||
|
||||
$: removed = item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false
|
||||
let reason = $state('')
|
||||
let commentReason: boolean = $state(false)
|
||||
let privateMessage: boolean = $state(false)
|
||||
let loading = $state(false)
|
||||
let preset = $state(settings.moderation.presets[0]?.content ?? '')
|
||||
|
||||
let removed = $derived(
|
||||
item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false,
|
||||
)
|
||||
|
||||
const getReplyReason = (reason: string, preset: string) => {
|
||||
if (!item) return `no template`
|
||||
@@ -38,7 +51,7 @@
|
||||
return removalTemplate(preset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id
|
||||
item!.community.actor_id,
|
||||
)}`,
|
||||
postTitle: item.post.name,
|
||||
reason: reason,
|
||||
@@ -46,11 +59,14 @@
|
||||
})
|
||||
}
|
||||
|
||||
$: replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
let replyReason = $state('')
|
||||
$effect(() => {
|
||||
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
})
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
if (!$profile?.jwt) throw new Error('Unauthenticated')
|
||||
if (!profile.data?.jwt) throw new Error('Unauthenticated')
|
||||
|
||||
loading = true
|
||||
|
||||
@@ -147,15 +163,14 @@
|
||||
|
||||
const resetText = () => {
|
||||
reason = ''
|
||||
replyReason = ''
|
||||
commentReason = false
|
||||
}
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
@@ -168,7 +183,7 @@
|
||||
>
|
||||
{#if item}
|
||||
<form
|
||||
on:submit|preventDefault={remove}
|
||||
onsubmit={preventDefault(remove)}
|
||||
class="flex flex-col gap-4 list-none"
|
||||
>
|
||||
{#if isCommentView(item)}
|
||||
@@ -177,7 +192,6 @@
|
||||
children: [],
|
||||
comment_view: item,
|
||||
depth: 1,
|
||||
ui: {},
|
||||
}}
|
||||
postId={item.post.id}
|
||||
actions={false}
|
||||
@@ -193,7 +207,7 @@
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
{#if !removed && $profile?.user && (amMod($profile.user, item.community) || (isAdmin($profile.user) && item.community.local))}
|
||||
{#if !removed && profile.data?.user && (amMod(profile.data.user, item.community) || (isAdmin(profile.data.user) && item.community.local))}
|
||||
<Switch bind:checked={commentReason}>
|
||||
{$t('moderation.removeSubmission.withReason')}
|
||||
</Switch>
|
||||
@@ -212,16 +226,18 @@
|
||||
placeholder={replyReason}
|
||||
rows={3}
|
||||
>
|
||||
<div class="flex justify-between items-end mb-1" slot="label">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each $userSettings.moderation.presets as preset}
|
||||
<option value={preset.content}>
|
||||
{preset.title}
|
||||
</option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{#snippet customLabel()}
|
||||
<div class="flex justify-between items-end mb-1">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each settings.moderation.presets as preset}
|
||||
<Option value={preset.content}>
|
||||
{preset.title}
|
||||
</Option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{/snippet}
|
||||
</MarkdownEditor>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -233,7 +249,9 @@
|
||||
disabled={loading}
|
||||
submit
|
||||
>
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" />
|
||||
{/snippet}
|
||||
{#if purge}
|
||||
{$t('admin.purge')}
|
||||
{:else}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import type {
|
||||
CommentView,
|
||||
PostView,
|
||||
PrivateMessageView,
|
||||
} from 'lemmy-js-client'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { onMount } from 'svelte'
|
||||
@@ -16,27 +18,30 @@
|
||||
import { t } from '$lib/translations'
|
||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | PrivateMessageView | undefined =
|
||||
undefined
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | PrivateMessageView | undefined
|
||||
}
|
||||
|
||||
let { open = $bindable(), item = $bindable() }: Props = $props()
|
||||
|
||||
const isComment = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is CommentView => 'comment' in item
|
||||
|
||||
const isPost = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PostView => !isComment(item) && 'post' in item
|
||||
|
||||
const isPrivateMessage = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
||||
|
||||
let loading = false
|
||||
let reason = ''
|
||||
let loading = $state(false)
|
||||
let reason = $state('')
|
||||
|
||||
async function report() {
|
||||
if (!item || !$profile?.jwt || reason == '') return
|
||||
if (!item || !profile.data?.jwt || reason == '') return
|
||||
loading = true
|
||||
|
||||
try {
|
||||
@@ -70,15 +75,15 @@
|
||||
|
||||
const resetText = () => (reason = '')
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('moderation.reportModal.title')}>
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={report}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(report)}>
|
||||
{#if item}
|
||||
<div class="pointer-events-none list-none">
|
||||
{#if isComment(item)}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let width: number = 16
|
||||
export let filled: boolean = false
|
||||
interface Props {
|
||||
width?: number
|
||||
filled?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { width = 16, filled = false, class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if filled}
|
||||
@@ -10,7 +15,7 @@
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="inline {$$props.class}"
|
||||
class="inline {clazz}"
|
||||
>
|
||||
<path
|
||||
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
|
||||
@@ -24,7 +29,7 @@
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="inline {$$props.class}"
|
||||
class="inline {clazz}"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { client } from '$lib/lemmy'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import type { SubmissionView } from '$lib/lemmy/contentview.js'
|
||||
import type {
|
||||
Comment,
|
||||
@@ -106,7 +106,7 @@ export const removalTemplate = (
|
||||
communityLink?: string
|
||||
username?: string
|
||||
reason?: string
|
||||
}
|
||||
},
|
||||
) => {
|
||||
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
||||
if (content.communityLink)
|
||||
|
||||
@@ -1,65 +1,30 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { isImage, isVideo } from '$lib/ui/image.js'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import PostMeta, {
|
||||
parseTags,
|
||||
type Tag,
|
||||
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import { Badge, Material, toast } from 'mono-svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import {
|
||||
bestImageURL,
|
||||
mediaType,
|
||||
postLink,
|
||||
} from '$lib/components/lemmy/post/helpers.js'
|
||||
import Empty from '$lib/components/helper/Empty.svelte'
|
||||
import { Badge } from 'mono-svelte'
|
||||
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import {
|
||||
ArrowUp,
|
||||
ChatBubbleOvalLeft,
|
||||
Icon,
|
||||
VideoCamera,
|
||||
} from 'svelte-hero-icons'
|
||||
import { ArrowUp, ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
|
||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
||||
import PostBody from './PostBody.svelte'
|
||||
import { profile } from '$lib/auth'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { goto } from '$app/navigation'
|
||||
|
||||
export let post: PostView
|
||||
export let actions: boolean = true
|
||||
export let hideCommunity = false
|
||||
export let view = $userSettings.view
|
||||
|
||||
$: tags = parseTags(post.post.name)
|
||||
$: type = mediaType(post.post.url, view)
|
||||
$: rule = getTagRule(tags.tags)
|
||||
|
||||
$: hideTitle =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
view != 'compact' &&
|
||||
type != 'iframe'
|
||||
|
||||
$: hideBody =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
|
||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||
|
||||
let rule: 'blur' | 'hide' | undefined
|
||||
if ($userSettings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
|
||||
if (settings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
|
||||
rule = 'blur'
|
||||
tagContent.forEach((tag) => {
|
||||
if ($userSettings.tagRules?.[tag])
|
||||
rule = $userSettings.tagRules?.[tag] ?? rule
|
||||
if (settings.tagRules?.[tag]) rule = settings.tagRules?.[tag] ?? rule
|
||||
if (rule == 'hide') return rule
|
||||
})
|
||||
|
||||
@@ -74,6 +39,59 @@
|
||||
goto(postLink(post.post))
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
post: PostView
|
||||
actions?: boolean
|
||||
hideCommunity?: boolean
|
||||
view?: View
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
extraBadges?: import('svelte').Snippet
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let {
|
||||
post: passedPost = $bindable(),
|
||||
actions = true,
|
||||
hideCommunity = false,
|
||||
view = settings.view,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
extraBadges,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
|
||||
let post = $state(passedPost)
|
||||
$effect(() => {
|
||||
passedPost = post
|
||||
})
|
||||
|
||||
let tags = $derived(parseTags(post.post.name))
|
||||
let type = $derived(mediaType(post.post.url, view))
|
||||
let rule = $derived(getTagRule(tags.tags))
|
||||
let hideTitle = $derived(
|
||||
settings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
view != 'compact' &&
|
||||
type != 'iframe',
|
||||
)
|
||||
let hideBody = $derived(
|
||||
settings.posts.deduplicateEmbed &&
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact',
|
||||
)
|
||||
|
||||
let badges = $derived({
|
||||
deleted: post.post.deleted,
|
||||
removed: post.post.removed,
|
||||
locked: post.post.locked,
|
||||
featured: post.post.featured_local || post.post.featured_community,
|
||||
nsfw: post.post.nsfw || post.community.nsfw,
|
||||
saved: post.saved,
|
||||
admin: post.creator_is_admin,
|
||||
moderator: post.creator_is_moderator,
|
||||
})
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -81,44 +99,35 @@
|
||||
This is the sole component for displaying posts.
|
||||
It adapts to all kinds of form factors for different contexts, such as feeds, full post view, and crosspost list.
|
||||
-->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<div
|
||||
class="post relative max-w-full min-w-0 w-full cursor-pointer outline-none
|
||||
group
|
||||
{$userSettings.leftAlign ? 'left-align' : ''}
|
||||
{view == 'compact' ? 'py-3 list-type compact' : ''}
|
||||
{view == 'list' ? 'py-5 list-type' : ''}
|
||||
{view == 'cozy' ? 'py-5 flex flex-col gap-2' : ''}
|
||||
{$$props.class ?? ''}"
|
||||
class={[
|
||||
'post relative max-w-full min-w-0 w-full cursor-pointer outline-none group',
|
||||
settings.leftAlign && 'left-align',
|
||||
view == 'compact' && 'py-3 list-type compact',
|
||||
view == 'cozy' && 'py-5 flex flex-col gap-2',
|
||||
clazz,
|
||||
]}
|
||||
id={post.post.id.toString()}
|
||||
on:click={(e) => {
|
||||
onclick={(e) => {
|
||||
onClick(e)
|
||||
}}
|
||||
on:keydown={(e) => {
|
||||
onkeydown={(e) => {
|
||||
// @ts-ignore
|
||||
if (e.key == 'Enter') onClick(e)
|
||||
}}
|
||||
tabindex="0"
|
||||
style={$$props.style ?? ''}
|
||||
{style}
|
||||
>
|
||||
<PostMeta
|
||||
community={post.community}
|
||||
showCommunity={!hideCommunity}
|
||||
user={post.creator}
|
||||
published={publishedToDate(post.post.published)}
|
||||
badges={{
|
||||
deleted: post.post.deleted,
|
||||
removed: post.post.removed,
|
||||
locked: post.post.locked,
|
||||
featured: post.post.featured_local || post.post.featured_community,
|
||||
nsfw: post.post.nsfw || post.community.nsfw,
|
||||
saved: post.saved,
|
||||
admin: post.creator_is_admin,
|
||||
moderator: post.creator_is_moderator,
|
||||
}}
|
||||
subscribed={$profile?.user?.follows
|
||||
{badges}
|
||||
subscribed={profile.data?.user?.follows
|
||||
.map((c) => c.community.id)
|
||||
.includes(post.community.id)
|
||||
? 'Subscribed'
|
||||
@@ -130,14 +139,10 @@
|
||||
edited={post.post.updated}
|
||||
tags={tags?.tags}
|
||||
{view}
|
||||
>
|
||||
<slot name="badges" slot="badges" />
|
||||
</PostMeta>
|
||||
{extraBadges}
|
||||
/>
|
||||
{#key post.post.url}
|
||||
<div
|
||||
style="grid-area:embed;"
|
||||
class={view == 'list' || view == 'compact' ? '' : 'contents'}
|
||||
>
|
||||
<div style="grid-area:embed;" class={{ contents: view == 'cozy' }}>
|
||||
{#if rule != 'hide'}
|
||||
<PostMedia
|
||||
post={post.post}
|
||||
@@ -147,11 +152,11 @@
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{#if view == 'list' || view == 'compact'}
|
||||
{#if view == 'compact'}
|
||||
<PostMediaCompact
|
||||
post={post.post}
|
||||
{type}
|
||||
class="{$userSettings.leftAlign
|
||||
class="{settings.leftAlign
|
||||
? 'mr-3'
|
||||
: 'ml-3'} flex-shrink no-list-margin"
|
||||
style="grid-area: media;"
|
||||
@@ -170,18 +175,7 @@
|
||||
/>
|
||||
{/if}
|
||||
{#if actions}
|
||||
<PostActions on:hide {post} style="grid-area: actions;" {view} />
|
||||
{:else if view == 'compact'}
|
||||
<div class="flex flex-row items-center gap-2 text-sm">
|
||||
<Badge>
|
||||
<Icon src={ArrowUp} slot="icon" size="14" micro />
|
||||
{post.counts.score}
|
||||
</Badge>
|
||||
<Badge>
|
||||
<Icon src={ChatBubbleOvalLeft} slot="icon" size="14" micro />
|
||||
{post.counts.comments}
|
||||
</Badge>
|
||||
</div>
|
||||
<PostActions {onhide} bind:post style="grid-area: actions;" {view} />
|
||||
{/if}
|
||||
<div
|
||||
class="absolute overflow-hidden inset-0
|
||||
@@ -190,7 +184,7 @@
|
||||
group-hover:inset-y-0.5 group-hover:-inset-x-4 group-hover:sm:-inset-x-5 group-hover:opacity-100
|
||||
group-focus:inset-y-0.5 group-focus:-inset-x-4 group-focus:sm:-inset-x-5 group-focus:opacity-100
|
||||
duration-150"
|
||||
/>
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<style lang="postcss">
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
<script lang="ts">
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import PostVote from './PostVote.svelte'
|
||||
import { getInstance, site } from '$lib/lemmy.js'
|
||||
import { site } from '$lib/lemmy.svelte.js'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
ArrowTopRightOnSquare,
|
||||
Bookmark,
|
||||
BookmarkSlash,
|
||||
BugAnt,
|
||||
ChatBubbleLeftEllipsis,
|
||||
ChatBubbleOvalLeft,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
CheckBadge,
|
||||
Clock,
|
||||
EllipsisHorizontal,
|
||||
Eye,
|
||||
@@ -19,31 +17,27 @@
|
||||
Flag,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
Language,
|
||||
MapPin,
|
||||
Newspaper,
|
||||
Pencil,
|
||||
PencilSquare,
|
||||
ServerStack,
|
||||
Share,
|
||||
Star,
|
||||
Trash,
|
||||
UserCircle,
|
||||
XMark,
|
||||
} from 'svelte-hero-icons'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import {
|
||||
amMod,
|
||||
isAdmin,
|
||||
report,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
|
||||
import { setSessionStorage } from '$lib/session.js'
|
||||
import { goto } from '$app/navigation'
|
||||
import { userSettings, type View } from '$lib/settings.js'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import {
|
||||
Button,
|
||||
Menu,
|
||||
@@ -53,40 +47,49 @@
|
||||
Spinner,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import { fediseer, type Data } from '$lib/fediseer/fediseer'
|
||||
import { t } from '$lib/translations'
|
||||
import { text } from '$lib/components/translate/translation'
|
||||
import { hidePost, postLink } from './helpers'
|
||||
import { feature } from '$lib/version'
|
||||
import Switch from '$lib/components/input/Switch.svelte'
|
||||
import { instanceId, instanceToURL } from '$lib/util'
|
||||
import { instanceId, instanceToURL } from '$lib/util.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||
import { communityLink, userLink } from '$lib/lemmy/generic'
|
||||
import RelativeDate, {
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
|
||||
export let post: PostView
|
||||
export let view: View = 'cozy'
|
||||
export let debug: boolean = false
|
||||
let editing = $state(false)
|
||||
let saving = $state(false)
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
|
||||
let localShare = $state(false)
|
||||
|
||||
let editing = false
|
||||
let saving = false
|
||||
interface Props {
|
||||
post: PostView
|
||||
view?: View
|
||||
debug?: boolean
|
||||
style?: string
|
||||
onedit?: (post: PostView) => void
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let translating = false
|
||||
|
||||
let localShare = false
|
||||
|
||||
$: buttonHeight = view == 'compact' ? 'h-7' : 'h-8'
|
||||
$: buttonSquare = view == 'compact' ? 'w-7 h-7' : 'w-8 h-8'
|
||||
let {
|
||||
post = $bindable(),
|
||||
view = 'cozy',
|
||||
debug = $bindable(false),
|
||||
style = '',
|
||||
onedit,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
<h1 slot="title" class="text-2xl font-bold">Editing post</h1>
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">Editing post</h1>
|
||||
{/snippet}
|
||||
{#await import('./form/PostForm.svelte')}
|
||||
<div class="mx-auto h-96 flex justify-center items-center">
|
||||
<Spinner width={32} />
|
||||
@@ -95,39 +98,33 @@
|
||||
<PostForm
|
||||
edit
|
||||
editingPost={post.post}
|
||||
on:submit={(e) => {
|
||||
onsubmit={(e) => {
|
||||
editing = false
|
||||
post = e.detail
|
||||
dispatcher('edit', e.detail)
|
||||
post = e
|
||||
onedit?.(e)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="formtitle">
|
||||
{#snippet formtitle()}
|
||||
<!-- Have the title not exist at all -->
|
||||
{''}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</PostForm>
|
||||
{/await}
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
{#if translating}
|
||||
{#await import('$lib/components/translate/Translation.svelte') then { default: Translation }}
|
||||
<Translation bind:open={translating} />
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<footer
|
||||
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
|
||||
class:flex-row-reverse={$userSettings.posts.reverseActions}
|
||||
style={$$props.style ?? ''}
|
||||
class:flex-row-reverse={settings.posts.reverseActions}
|
||||
{style}
|
||||
>
|
||||
<PostVote
|
||||
post={post.post}
|
||||
bind:vote={post.my_vote}
|
||||
bind:score={post.counts.score}
|
||||
bind:upvotes={post.counts.upvotes}
|
||||
bind:downvotes={post.counts.downvotes}
|
||||
showCounts={$profile?.user?.local_user_view?.local_user?.show_scores ??
|
||||
bind:post={post.post}
|
||||
vote={post.my_vote}
|
||||
score={post.counts.score}
|
||||
upvotes={post.counts.upvotes}
|
||||
downvotes={post.counts.downvotes}
|
||||
showCounts={profile.data?.user?.local_user_view?.local_user?.show_scores ??
|
||||
true}
|
||||
/>
|
||||
|
||||
@@ -137,7 +134,7 @@
|
||||
class="!text-inherit h-full px-3 relative"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
target={$userSettings.openLinksInNewTab ? '_blank' : ''}
|
||||
target={settings.openLinksInNewTab ? '_blank' : ''}
|
||||
title={$t('post.actions.comments')}
|
||||
animations={{ scale: true, large: false }}
|
||||
>
|
||||
@@ -150,16 +147,16 @@
|
||||
/>
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Button>
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
|
||||
{#if $userSettings.debugInfo}
|
||||
{#if settings.debugInfo}
|
||||
{#if debug}
|
||||
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
|
||||
<DebugObject object={post} bind:open={debug} />
|
||||
{/await}
|
||||
{/if}
|
||||
<Button
|
||||
on:click={() => (debug = true)}
|
||||
onclick={() => (debug = true)}
|
||||
title="Debug"
|
||||
size="custom"
|
||||
color="ghost"
|
||||
@@ -167,10 +164,12 @@
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon src={BugAnt} micro size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
|
||||
{#if profile.data?.user && (amMod(profile.data.user, post.community) || isAdmin(profile.data.user))}
|
||||
<ModerationMenu
|
||||
size="custom"
|
||||
color="ghost"
|
||||
@@ -181,12 +180,12 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<Button
|
||||
on:click={async () => {
|
||||
if (!$profile?.jwt) return
|
||||
onclick={async () => {
|
||||
if (!profile.data?.jwt) return
|
||||
saving = true
|
||||
post.saved = await save(post, !post.saved, $profile?.jwt)
|
||||
post.saved = await save(post, !post.saved, profile.data?.jwt)
|
||||
saving = false
|
||||
}}
|
||||
size="custom"
|
||||
@@ -198,12 +197,9 @@
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon
|
||||
src={post.saved ? BookmarkSlash : Bookmark}
|
||||
size="16"
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
@@ -214,21 +210,26 @@
|
||||
targetClass="h-full"
|
||||
title={$t('post.actions.more.label')}
|
||||
>
|
||||
<Button
|
||||
slot="target"
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} width={16} micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
|
||||
<div class="flex flex-row gap-1 items-center">
|
||||
<MenuButton class="flex-1">
|
||||
<Icon src={Clock} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Clock} size="16" micro />
|
||||
{/snippet}
|
||||
<span>
|
||||
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
|
||||
dateStyle: 'short',
|
||||
@@ -240,10 +241,12 @@
|
||||
publishedToDate(post.post.updated),
|
||||
{
|
||||
style: 'long',
|
||||
}
|
||||
},
|
||||
)}
|
||||
<MenuButton class="flex-1" aria-label={editedTime}>
|
||||
<Icon src={Pencil} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Pencil} size="16" micro />
|
||||
{/snippet}
|
||||
<RelativeDate date={publishedToDate(post.post.updated)} />
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -254,7 +257,9 @@
|
||||
<MenuButton
|
||||
aria-label={$t('aria.vote.score', { default: post.counts.score })}
|
||||
>
|
||||
<Icon src={ArrowsUpDown} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowsUpDown} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.vote.score')}
|
||||
•
|
||||
<FormattedNumber
|
||||
@@ -274,25 +279,17 @@
|
||||
{/if}
|
||||
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||
<MenuButton link href={userLink(post.creator)}>
|
||||
<Icon
|
||||
src={UserCircle}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} size="16" micro class="flex-shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.creator.name}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuButton link href={communityLink(post.community)}>
|
||||
<Icon
|
||||
src={Newspaper}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro class="flex-shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.community.title}
|
||||
</TextProps>
|
||||
@@ -300,51 +297,61 @@
|
||||
<MenuDivider>
|
||||
{$t('post.actions.more.actions')}
|
||||
</MenuDivider>
|
||||
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton on:click={() => (editing = true)}>
|
||||
<Icon src={PencilSquare} size="16" micro slot="prefix" />
|
||||
{#if profile.data?.user && profile.data?.jwt && profile.data.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton onclick={() => (editing = true)}>
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile?.jwt}
|
||||
{#if profile.data?.jwt}
|
||||
<MenuButton
|
||||
on:click={async () => {
|
||||
if ($profile?.jwt)
|
||||
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
post.read = await markAsRead(
|
||||
post.post,
|
||||
!post.read,
|
||||
profile.data.jwt,
|
||||
)
|
||||
}}
|
||||
>
|
||||
<Icon slot="prefix" src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
navigator.share?.({
|
||||
url: localShare
|
||||
? `${instanceToURL(getInstance())}/post/${post.post.id}`
|
||||
? `${instanceToURL(instance.data)}/post/${post.post.id}`
|
||||
: post.post.ap_id,
|
||||
}) ??
|
||||
navigator.clipboard.writeText(
|
||||
localShare
|
||||
? `${instanceToURL(getInstance())}/post/${post.post.id}`
|
||||
: post.post.ap_id
|
||||
? `${instanceToURL(instance.data)}/post/${post.post.id}`
|
||||
: post.post.ap_id,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="flex-1 !py-0"
|
||||
>
|
||||
<Icon src={Share} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
{#if !post.post.local}
|
||||
<div class="flex">
|
||||
<Button
|
||||
color={!localShare ? 'primary' : 'secondary'}
|
||||
size="square-md"
|
||||
roundingSide="left"
|
||||
on:click={() => (localShare = false)}
|
||||
onclick={() => (localShare = false)}
|
||||
title={$t('filter.location.global')}
|
||||
>
|
||||
<Icon src={GlobeAmericas} size="16" micro />
|
||||
@@ -353,7 +360,7 @@
|
||||
color={localShare ? 'primary' : 'secondary'}
|
||||
size="square-md"
|
||||
roundingSide="right"
|
||||
on:click={() => (localShare = true)}
|
||||
onclick={() => (localShare = true)}
|
||||
title={$t('filter.location.local')}
|
||||
>
|
||||
<Icon src={MapPin} size="16" micro />
|
||||
@@ -361,24 +368,12 @@
|
||||
</div>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if post.post.body && $userSettings.translator}
|
||||
{#if profile.data?.jwt}
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
// @ts-ignore
|
||||
text.set(post.post.body)
|
||||
translating = !translating
|
||||
}}
|
||||
>
|
||||
<Icon src={Language} size="16" micro slot="prefix" />
|
||||
{$t('post.actions.more.translate')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile?.jwt}
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
setSessionStorage('postDraft', {
|
||||
body: `${
|
||||
$userSettings.crosspostOriginalLink
|
||||
settings.crosspostOriginalLink
|
||||
? `cross-posted from: ${post.post.ap_id}`
|
||||
: ``
|
||||
}\n${
|
||||
@@ -397,52 +392,58 @@
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
>
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
|
||||
{#if profile.data.user && post.creator.id == profile.data.user.local_user_view.person.id}
|
||||
<MenuButton
|
||||
on:click={async () => {
|
||||
if ($profile?.jwt)
|
||||
onclick={async () => {
|
||||
if (profile.data?.jwt)
|
||||
post.post.deleted = await deleteItem(
|
||||
post,
|
||||
!post.post.deleted,
|
||||
$profile.jwt
|
||||
profile.data.jwt,
|
||||
)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
<Icon src={Trash} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if $profile.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if feature('hidePosts', $site?.version)}
|
||||
{#if profile.data.user?.local_user_view.person.id != post.creator.id}
|
||||
{#if feature('hidePosts', site.data?.version)}
|
||||
<MenuButton
|
||||
on:click={async () => {
|
||||
if (!$profile?.jwt) return
|
||||
onclick={async () => {
|
||||
if (!profile.data?.jwt) return
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
$profile?.jwt
|
||||
profile.data?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) {
|
||||
dispatcher('hide', hidden)
|
||||
}
|
||||
if (hidden) onhide?.(hidden)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
<Icon slot="prefix" src={XMark} size="16" micro />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
||||
<Icon src={Flag} width={16} micro slot="prefix" />
|
||||
<MenuButton onclick={() => report(post)} color="danger-subtle">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} width={16} micro />
|
||||
{/snippet}
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,51 +1,60 @@
|
||||
<script lang="ts">
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import type { View } from '$lib/settings'
|
||||
import type { View } from '$lib/settings.svelte'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let body: string
|
||||
export let view: View = 'cozy'
|
||||
export let clickThrough = false
|
||||
let htmlElement = 'div'
|
||||
const MAX_HEIGHT = 192
|
||||
|
||||
export { htmlElement as element }
|
||||
let element = $state<Element>()
|
||||
|
||||
let expanded = false
|
||||
let element: Element
|
||||
function isOverflown(element: Element) {
|
||||
if (!element) return false
|
||||
|
||||
function isOverflown(element: Element, body: string = '') {
|
||||
if (!element) return
|
||||
let overflows =
|
||||
element.scrollHeight > element.clientHeight ||
|
||||
element.scrollWidth > element.clientWidth
|
||||
|
||||
if (!overflows) expanded = true
|
||||
else expanded = false
|
||||
|
||||
return overflows
|
||||
return element.scrollHeight > MAX_HEIGHT
|
||||
}
|
||||
|
||||
$: overflows = isOverflown(element, body)
|
||||
interface Props {
|
||||
body: string
|
||||
view?: View
|
||||
clickThrough?: boolean
|
||||
element?: string
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
body,
|
||||
view = 'cozy',
|
||||
clickThrough = false,
|
||||
element: htmlElement = 'div',
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let overflows = $derived(element ? isOverflown(element) : false)
|
||||
|
||||
let expanded = $state(false)
|
||||
$effect(() => {
|
||||
expanded = !overflows
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={htmlElement}
|
||||
style={$$props.style ?? ''}
|
||||
{style}
|
||||
class="{!expanded
|
||||
? ` overflow-hidden
|
||||
bg-gradient-to-b text-transparent from-slate-600 via-slate-600
|
||||
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0
|
||||
${view == 'list' ? `max-h-24` : 'max-h-48'}`
|
||||
: 'text-slate-600 dark:text-zinc-400 max-h-full'} text-base {$$props.class ??
|
||||
''}"
|
||||
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36`
|
||||
: 'text-slate-600 dark:text-zinc-400 max-h-full'} text-base {clazz}"
|
||||
class:pointer-events-none={!clickThrough}
|
||||
bind:this={element}
|
||||
>
|
||||
<Markdown inline={!expanded} source={expanded ? body : body.slice(0, 1000)} />
|
||||
{#if overflows}
|
||||
<Button
|
||||
on:click={() => (expanded = !expanded)}
|
||||
onclick={() => (expanded = !expanded)}
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
class="text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0 {expanded
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export interface Tag {
|
||||
content: string
|
||||
color?: string
|
||||
@@ -12,7 +12,7 @@
|
||||
])
|
||||
|
||||
export const parseTags = (
|
||||
title?: string
|
||||
title?: string,
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
if (!title) return { tags: [] }
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
content: content,
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
return ''
|
||||
@@ -61,43 +61,61 @@
|
||||
Trash,
|
||||
PaperAirplane,
|
||||
} from 'svelte-hero-icons'
|
||||
import { getInstance } from '$lib/lemmy.js'
|
||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||
import { userSettings, type View } from '$lib/settings'
|
||||
import { settings, type View } from '$lib/settings.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { Pencil, type IconSource } from 'svelte-hero-icons'
|
||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
|
||||
export let community: Community | undefined = undefined
|
||||
export let showCommunity: boolean = true
|
||||
export let subscribed: SubscribedType | undefined = undefined
|
||||
|
||||
export let user: Person | undefined = undefined
|
||||
export let published: Date | undefined = undefined
|
||||
export let title: string | undefined = undefined
|
||||
export let id: number | undefined = undefined
|
||||
export let read: boolean = false
|
||||
export let edited: string | undefined = undefined
|
||||
|
||||
export let view: View = 'cozy'
|
||||
|
||||
// Badges
|
||||
export let badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
interface Props {
|
||||
community?: Community | undefined
|
||||
showCommunity?: boolean
|
||||
subscribed?: SubscribedType | undefined
|
||||
user?: Person | undefined
|
||||
published?: Date | undefined
|
||||
title?: string | undefined
|
||||
id?: number | undefined
|
||||
read?: boolean
|
||||
edited?: string | undefined
|
||||
view?: View
|
||||
// Badges
|
||||
badges?: any
|
||||
tags?: Tag[]
|
||||
style?: string
|
||||
titleClass?: string
|
||||
extraBadges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let tags: Tag[] = []
|
||||
|
||||
let popoverOpen = false
|
||||
let {
|
||||
community = $bindable(undefined),
|
||||
showCommunity = true,
|
||||
subscribed = $bindable(undefined),
|
||||
user = undefined,
|
||||
published = undefined,
|
||||
title = undefined,
|
||||
id = undefined,
|
||||
read = false,
|
||||
edited = undefined,
|
||||
view = 'cozy',
|
||||
badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
},
|
||||
tags = [],
|
||||
style = '',
|
||||
titleClass = '',
|
||||
extraBadges,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -109,34 +127,33 @@
|
||||
? 'grid-rows-2'
|
||||
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
||||
class:compact={view == 'compact'}
|
||||
style={$$props.style ?? ''}
|
||||
{style}
|
||||
>
|
||||
{#if showCommunity && community && subscribed && showCommunity}
|
||||
<Popover bind:open={popoverOpen} manual>
|
||||
<button
|
||||
on:click={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
slot="target"
|
||||
>
|
||||
<Avatar
|
||||
url={community.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div
|
||||
slot="popover"
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
on:click|stopPropagation={() => {}}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{#if showCommunity && community}
|
||||
<Popover autoClose={false} popoverClass="backdrop-blur-xl rounded-2xl">
|
||||
{#snippet target()}
|
||||
<button
|
||||
class="row-span-2 flex-shrink-0 mr-2 self-center group/btn bg-slate-200 dark:bg-zinc-800 rounded-full"
|
||||
>
|
||||
<Avatar
|
||||
url={community?.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community?.name}
|
||||
class="group-hover/btn:scale-90 group-active/btn:scale-[.85] transition-transform"
|
||||
/>
|
||||
</button>
|
||||
{/snippet}
|
||||
{#snippet popover()}
|
||||
{#if community && subscribed}
|
||||
<div
|
||||
class="bg-white/80 dark:bg-zinc-900/90 border border-slate-200 dark:border-zinc-800 rounded-2xl shadow-xl p-4
|
||||
max-w-2xl w-full max-h-[32rem] overflow-auto"
|
||||
>
|
||||
<CommunityHeader {community} {subscribed} />
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Popover>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
{/if}
|
||||
{#if showCommunity && community}
|
||||
<CommunityLink
|
||||
@@ -171,14 +188,14 @@
|
||||
avatar={!showCommunity}
|
||||
class="flex-shrink "
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet extraBadges()}
|
||||
{#if badges.moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
{/if}
|
||||
{#if badges.admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
</address>
|
||||
{/if}
|
||||
@@ -210,13 +227,13 @@
|
||||
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
||||
>
|
||||
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
||||
<svelte:fragment slot="icon">
|
||||
{#snippet icon()}
|
||||
{#if tag.icon}
|
||||
<Icon src={tag.icon} micro size="14" />
|
||||
{:else}
|
||||
<Icon src={Tag} micro size="14" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
{tag.content}
|
||||
</Badge>
|
||||
</a>
|
||||
@@ -224,7 +241,9 @@
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={ExclamationTriangle} size="14" micro slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={ExclamationTriangle} size="14" micro />
|
||||
{/snippet}
|
||||
{$t('post.badges.nsfw')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -234,7 +253,9 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Bookmark} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Bookmark} micro size="14" />
|
||||
{/snippet}
|
||||
{$t('post.badges.saved')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -244,19 +265,25 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={LockClosed} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={LockClosed} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.removed}
|
||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.deleted}
|
||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -266,34 +293,38 @@
|
||||
color="green-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Megaphone} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Megaphone} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
<slot name="badges" />
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
{#if title && id}
|
||||
<a
|
||||
href="/post/{getInstance()}/{id}"
|
||||
href="/post/{encodeURIComponent(instance.data)}/{id}"
|
||||
class="inline hover:underline
|
||||
hover:text-primary-900 hover:dark:text-primary-100 transition-colors max-[480px]:!mt-0
|
||||
{$userSettings.font == 'satoshi/nunito'
|
||||
{settings.font == 'satoshi/nunito'
|
||||
? 'font-display font-semibold'
|
||||
: 'font-medium'} {$$props.titleClass ?? ''}"
|
||||
class:text-slate-600={$userSettings.markReadPosts && read}
|
||||
class:dark:text-zinc-400={$userSettings.markReadPosts && read}
|
||||
: 'font-medium'} {titleClass}"
|
||||
class:text-slate-600={settings.markReadPosts && read}
|
||||
class:dark:text-zinc-400={settings.markReadPosts && read}
|
||||
class:text-base={view == 'compact'}
|
||||
class:text-lg={view != 'compact'}
|
||||
style="grid-area: title;"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
<Markdown
|
||||
source={title}
|
||||
inline
|
||||
noStyle
|
||||
class={view == 'compact' ? '' : 'leading-[1.3]'}
|
||||
></Markdown>
|
||||
{#if title}
|
||||
<Markdown
|
||||
source={title}
|
||||
inline
|
||||
noStyle
|
||||
class={view == 'compact' ? '' : 'leading-[1.3]'}
|
||||
></Markdown>
|
||||
{/if}
|
||||
</a>
|
||||
{:else}
|
||||
<div style="grid-area: title; margin: 0;"></div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" context="module">
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
<script lang="ts" module>
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
export const voteColor = (vote: number, border: boolean = false) =>
|
||||
vote == 1
|
||||
? `bg-gradient-to-br from-blue-500 to-indigo-500 dark:from-blue-400 dark:to-indigo-500 text-slate-50 dark:text-zinc-900`
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
export const shouldShowVoteColor = (
|
||||
vote: number,
|
||||
type: 'upvotes' | 'downvotes'
|
||||
type: 'upvotes' | 'downvotes',
|
||||
): string =>
|
||||
(vote == -1 && type == 'downvotes') || (vote == 1 && type == 'upvotes')
|
||||
? voteColor(vote)
|
||||
@@ -20,36 +20,48 @@
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { vote as voteItem } from '$lib/lemmy/contentview.js'
|
||||
import { Button, Popover, buttonColor, toast } from 'mono-svelte'
|
||||
import { site } from '$lib/lemmy.js'
|
||||
import { site } from '$lib/lemmy.svelte.js'
|
||||
import { fade, fly } from 'svelte/transition'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { t } from '$lib/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
|
||||
export let post: Post
|
||||
export let vote: number = 0
|
||||
export let score: number
|
||||
export let upvotes: number = 0
|
||||
export let downvotes: number = 0
|
||||
interface Props {
|
||||
post: Post
|
||||
vote?: number
|
||||
score: number
|
||||
upvotes?: number
|
||||
downvotes?: number
|
||||
showCounts?: boolean
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
export let showCounts: boolean = true
|
||||
let {
|
||||
post = $bindable(),
|
||||
vote = $bindable(0),
|
||||
score = $bindable(),
|
||||
upvotes = $bindable(0),
|
||||
downvotes = $bindable(0),
|
||||
showCounts = true,
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let loading = $state(false)
|
||||
|
||||
let oldScore = score
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!$profile?.jwt) {
|
||||
if (!profile.data?.jwt) {
|
||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||
return
|
||||
}
|
||||
loading = true
|
||||
oldScore = score
|
||||
vote = newVote
|
||||
const res = await voteItem(post, newVote, $profile.jwt).catch((e) => {
|
||||
const res = await voteItem(post, newVote, profile.data.jwt).catch((e) => {
|
||||
toast({ content: errorMessage(e), type: 'error' })
|
||||
return { upvotes: 0, downvotes: 0, score: 0 }
|
||||
})
|
||||
@@ -58,7 +70,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot {vote} {score}>
|
||||
{#if children}{@render children({ vote, score })}{:else}
|
||||
<div
|
||||
class="{buttonColor.ghost} rounded-full h-full font-medium flex items-center *:p-2
|
||||
hover:bg-white hover:dark:bg-zinc-900 overflow-hidden transition-colors flex-shrink-0
|
||||
@@ -70,7 +82,7 @@
|
||||
aria-label={$t('aria.vote.group')}
|
||||
>
|
||||
<button
|
||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||
onclick={() => castVote(vote == 1 ? 0 : 1)}
|
||||
class="flex items-center gap-0.5 transition-colors relative z-0
|
||||
{vote == 1
|
||||
? shouldShowVoteColor(vote, 'upvotes')
|
||||
@@ -94,9 +106,9 @@
|
||||
</span>
|
||||
{/if}
|
||||
</button>
|
||||
{#if $site?.site_view.local_site.enable_downvotes ?? true}
|
||||
{#if site.data?.site_view.local_site.enable_downvotes ?? true}
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
onclick={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex items-center flex-row-reverse gap-0.5 transition-colors
|
||||
{vote == -1
|
||||
? shouldShowVoteColor(vote, 'downvotes')
|
||||
@@ -122,4 +134,4 @@
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</slot>
|
||||
{/if}
|
||||
@@ -1,28 +1,30 @@
|
||||
<script lang="ts">
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Badge, Button } from 'mono-svelte'
|
||||
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { combineCrossposts } from './crosspost'
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
export let feedData: any
|
||||
let etc = $$restProps
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
community?: boolean
|
||||
feedData: any
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: combinedPosts = combineCrossposts(posts)
|
||||
|
||||
let viewPost: number = -1
|
||||
let {
|
||||
posts = $bindable(),
|
||||
community = false,
|
||||
feedData,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none {$userSettings.view == 'card'
|
||||
? 'gap-3 md:gap-4'
|
||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
||||
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
@@ -32,77 +34,30 @@
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
{:else}
|
||||
{#each combinedPosts as post, index}
|
||||
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
|
||||
<li class="relative post-container">
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
view={(post.post.featured_community || post.post.featured_local) &&
|
||||
$userSettings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: $userSettings.view}
|
||||
{post}
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#if post.withCrossposts}
|
||||
<button
|
||||
on:click={() => {
|
||||
if (viewPost == post.post.id) viewPost = -1
|
||||
else viewPost = post.post.id
|
||||
}}
|
||||
>
|
||||
<Badge
|
||||
class="z-10 backdrop-blur-xl hover:brightness-110 cursor-pointer transition-all"
|
||||
color="gray-subtle"
|
||||
>
|
||||
{#if viewPost == post.post.id}
|
||||
<Icon mini src={Minus} size="14" />
|
||||
{:else}
|
||||
<Icon mini src={Plus} size="14" />
|
||||
{/if}
|
||||
{post.crossposts.length} crosspost{post.crossposts.length ==
|
||||
1
|
||||
? ''
|
||||
: 's'}
|
||||
</Badge>
|
||||
</button>{/if}
|
||||
</svelte:fragment>
|
||||
</Post>
|
||||
{#if post.withCrossposts && viewPost == post.post.id}
|
||||
<div
|
||||
transition:slide|global={{
|
||||
axis: 'y',
|
||||
duration: 500,
|
||||
easing: expoOut,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
class="text-sm flex flex-row gap-2 items-center"
|
||||
class:my-4={$userSettings.view == 'card'}
|
||||
>
|
||||
Crossposts <hr class="w-full dark:border-zinc-800" />
|
||||
{post.crossposts.length}
|
||||
</span>
|
||||
{#each post.crossposts as crosspost, index}
|
||||
<div class="w-full transition-all mb-4">
|
||||
<Post post={crosspost} view={$userSettings.view} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</li>
|
||||
{/if}
|
||||
{#each posts as post, index (post.post.id)}
|
||||
<li class="relative post-container">
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
view={(post.post.featured_community || post.post.featured_local) &&
|
||||
settings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: settings.view}
|
||||
{post}
|
||||
class="transition-all duration-250"
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
/>
|
||||
</li>
|
||||
{/each}
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
@@ -1,81 +1,53 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import type {
|
||||
GetPostsResponse,
|
||||
ListingType,
|
||||
PostView,
|
||||
SortType,
|
||||
} from 'lemmy-js-client'
|
||||
import { Badge, Button } from 'mono-svelte'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import {
|
||||
postFeeds,
|
||||
type PostFeed,
|
||||
type PostFeedID,
|
||||
} from '$lib/lemmy/postfeed.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { onMount, tick, untrack } from 'svelte'
|
||||
import {
|
||||
ArchiveBox,
|
||||
ChevronDoubleUp,
|
||||
ExclamationTriangle,
|
||||
Icon,
|
||||
Minus,
|
||||
Plus,
|
||||
} from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { browser } from '$app/environment'
|
||||
import { afterUpdate, onMount, tick, type SvelteComponent } from 'svelte'
|
||||
import {
|
||||
createVirtualizer,
|
||||
createWindowVirtualizer,
|
||||
type SvelteVirtualizer,
|
||||
} from '@tanstack/svelte-virtual'
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
||||
import { combineCrossposts } from './crosspost'
|
||||
import { client } from '$lib/lemmy'
|
||||
import {
|
||||
postFeeds,
|
||||
type PostFeed,
|
||||
type PostFeedID,
|
||||
} from '$lib/lemmy/postfeed'
|
||||
import { t } from '$lib/translations'
|
||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||
import type { Readable } from 'svelte/motion'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
export let feedId: PostFeedID
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
let virtualListEl: HTMLElement | undefined = undefined
|
||||
|
||||
const virtualizer = createWindowVirtualizer({
|
||||
count: posts.length,
|
||||
estimateSize: () => 150,
|
||||
overscan: 5,
|
||||
measureElement: (element, entry, instance) => {
|
||||
return element.scrollHeight
|
||||
},
|
||||
})
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
|
||||
$: if (virtualItemEls.length) {
|
||||
virtualItemEls.forEach($virtualizer.measureElement)
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
community?: boolean
|
||||
feedId: PostFeedID
|
||||
feedData: PostFeed['data']
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
$: if (posts.length && virtualListEl)
|
||||
$virtualizer.setOptions({
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
count: posts.length,
|
||||
})
|
||||
let {
|
||||
posts = $bindable(),
|
||||
community = false,
|
||||
feedId,
|
||||
feedData = $bindable(),
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
|
||||
})
|
||||
let listEl = $state<HTMLUListElement>()
|
||||
let listComp = $state<{
|
||||
scrollToIndex: (index: number, window?: boolean) => void
|
||||
}>()
|
||||
|
||||
export let feedData: PostFeed['data']
|
||||
|
||||
let error: any = undefined
|
||||
let loading = false
|
||||
let hasMore = true
|
||||
let error: any = $state(undefined)
|
||||
let loading = $state(false)
|
||||
let hasMore = $state(true)
|
||||
|
||||
async function loadMore() {
|
||||
if (!hasMore || loading) return
|
||||
@@ -106,11 +78,9 @@
|
||||
hasMore = newPosts.posts.length != 0
|
||||
|
||||
feedData.cursor.next = newPosts.next_page
|
||||
feedData.posts.posts = [...feedData.posts.posts, ...newPosts.posts]
|
||||
feedData.posts.posts.push(...newPosts.posts)
|
||||
|
||||
postFeeds.updateFeed(feedId, {
|
||||
data: feedData,
|
||||
})
|
||||
postFeeds.value[feedId].data = feedData
|
||||
|
||||
loading = false
|
||||
} catch (e) {
|
||||
@@ -128,127 +98,112 @@
|
||||
|
||||
if (!id) return
|
||||
|
||||
postFeeds.updateFeed(feedId, {
|
||||
lastSeen: Number(id),
|
||||
})
|
||||
postFeeds.value[feedId].lastSeen = Number(id)
|
||||
|
||||
observer.unobserve(element)
|
||||
})
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const observer = new IntersectionObserver(callback, {
|
||||
root: null,
|
||||
rootMargin: '0px',
|
||||
threshold: 0.5,
|
||||
})
|
||||
|
||||
const elements = document.querySelectorAll('.post-container')
|
||||
elements.forEach((el) => observer.observe(el))
|
||||
const observePost = (node: Node) => {
|
||||
if (
|
||||
node instanceof HTMLElement &&
|
||||
node.classList.contains('post-container')
|
||||
)
|
||||
observer.observe(node)
|
||||
}
|
||||
|
||||
const postContainer = document.querySelector('#feed')
|
||||
if (postContainer) {
|
||||
const mutationObserver = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'childList') {
|
||||
mutation.addedNodes.forEach((node) => {
|
||||
if (
|
||||
node instanceof HTMLElement &&
|
||||
node.classList.contains('post-container')
|
||||
) {
|
||||
observer.observe(node)
|
||||
}
|
||||
})
|
||||
mutation.removedNodes.forEach((node) => {
|
||||
if (
|
||||
node instanceof HTMLElement &&
|
||||
node.classList.contains('post-container')
|
||||
) {
|
||||
observer.unobserve(node)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
const unobservePost = (node: Node) => {
|
||||
if (
|
||||
node instanceof HTMLElement &&
|
||||
node.classList.contains('post-container')
|
||||
)
|
||||
observer.unobserve(node)
|
||||
}
|
||||
|
||||
document.querySelectorAll('.post-container').forEach(observePost)
|
||||
|
||||
const feed = document.getElementById('feed')
|
||||
if (!feed) return
|
||||
|
||||
new MutationObserver((mutations) => {
|
||||
mutations.forEach(({ addedNodes, removedNodes }) => {
|
||||
addedNodes.forEach(observePost)
|
||||
removedNodes.forEach(unobservePost)
|
||||
})
|
||||
}).observe(feed, { childList: true, subtree: false })
|
||||
})
|
||||
|
||||
mutationObserver.observe(postContainer, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
$effect(() => {
|
||||
if (listComp) {
|
||||
untrack(() => {
|
||||
if (postFeeds.value[feedId].lastSeen != 0) {
|
||||
listComp?.scrollToIndex(postFeeds.value[feedId].lastSeen, true)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
onMount(async () => {
|
||||
await tick()
|
||||
$virtualizer.measure()
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none {$userSettings.view == 'card'
|
||||
? 'gap-3 md:gap-4'
|
||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={ArchiveBox}
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
style="position:relative; height: {browser
|
||||
? `${$virtualizer.getTotalSize()}px`
|
||||
: '100%'}; width: 100%;"
|
||||
bind:this={virtualListEl}
|
||||
>
|
||||
<div
|
||||
style="position: absolute; top: 0; left: 0; width: 100%; transform: translateY({items?.[0]
|
||||
? items?.[0]?.start - $virtualizer.options.scrollMargin
|
||||
: 0}px);"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900"
|
||||
id="feed"
|
||||
>
|
||||
{#each items as row, index (posts[row.index]?.post.id)}
|
||||
{#if posts[row.index]}
|
||||
{@const post = posts?.[row.index]}
|
||||
<li
|
||||
bind:this={virtualItemEls[index]}
|
||||
data-index={row.index}
|
||||
style={row.index < 7 ? `--anim-delay: ${index * 100}ms` : ''}
|
||||
class="relative post-container {row.index < 7
|
||||
? 'pop-in opacity-0'
|
||||
: ''} -mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||
>
|
||||
<Post
|
||||
hideCommunity={community}
|
||||
view={(posts[row.index]?.post.featured_community ||
|
||||
posts[row.index]?.post.featured_local) &&
|
||||
$userSettings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: $userSettings.view}
|
||||
{post}
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
}}
|
||||
></Post>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
<ul class="flex flex-col list-none" bind:this={listEl}>
|
||||
{#key posts}
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={ArchiveBox}
|
||||
title="No posts"
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<VirtualList
|
||||
id="feed"
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
items={posts}
|
||||
initialOffset={listEl?.offsetTop}
|
||||
overscan={500}
|
||||
bind:restore={postFeeds.value[feedId].clientData}
|
||||
bind:this={listComp}
|
||||
>
|
||||
{#snippet item(_, row, __)}
|
||||
<li
|
||||
data-index={row}
|
||||
style={row < 7 ? `--anim-delay: ${row * 100}ms` : ''}
|
||||
class="relative post-container {row < 7
|
||||
? 'pop-in opacity-0'
|
||||
: ''} -mx-4 sm:-mx-6 px-4 sm:px-6"
|
||||
>
|
||||
<Post
|
||||
bind:post={posts[row]}
|
||||
hideCommunity={community}
|
||||
view={(posts[row]?.post.featured_community ||
|
||||
posts[row]?.post.featured_local) &&
|
||||
settings.posts.compactFeatured
|
||||
? 'compact'
|
||||
: settings.view}
|
||||
class="transition-all duration-250"
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(row, 1)
|
||||
}}
|
||||
></Post>
|
||||
</li>
|
||||
{/snippet}
|
||||
</VirtualList>
|
||||
{/if}
|
||||
{/key}
|
||||
|
||||
{#if $userSettings.infiniteScroll && browser}
|
||||
{#if settings.infiniteScroll && browser}
|
||||
{#if error}
|
||||
<div
|
||||
class="flex flex-col justify-center items-center
|
||||
@@ -263,18 +218,20 @@
|
||||
color="primary"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
on:click={() => loadMore()}
|
||||
onclick={() => loadMore()}
|
||||
>
|
||||
{$t('message.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
{:else if hasMore}
|
||||
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
||||
<div class="w-96 max-w-full h-8"></div>
|
||||
<div class="w-full h-48"></div>
|
||||
<div class="w-full flex flex-col gap-2 animate-pulse pt-6">
|
||||
<div
|
||||
class="w-96 max-w-full h-8 bg-slate-100 dark:bg-zinc-800 rounded-md"
|
||||
></div>
|
||||
<div class="w-full h-48 bg-slate-100 dark:bg-zinc-800 rounded-md"></div>
|
||||
<div class="!bg-transparent h-8 flex justify-between">
|
||||
<div class="w-48 h-8"></div>
|
||||
<div class="w-24 h-8"></div>
|
||||
<div class="w-48 h-8 bg-slate-100 dark:bg-zinc-800 rounded-md"></div>
|
||||
<div class="w-24 h-8 bg-slate-100 dark:bg-zinc-800 rounded-md"></div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -284,23 +241,23 @@
|
||||
// @ts-ignore
|
||||
community_name: feedData.community_name ?? 'undefined',
|
||||
})}
|
||||
<Button slot="action" color="tertiary">
|
||||
<Icon src={ChevronDoubleUp} size="16" micro slot="prefix" />
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{#snippet action()}
|
||||
<Button color="tertiary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronDoubleUp} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</div>
|
||||
{/if}
|
||||
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
|
||||
<style lang="postcss">
|
||||
.skeleton * {
|
||||
@apply bg-slate-100 dark:bg-zinc-800 rounded-md;
|
||||
}
|
||||
|
||||
@keyframes popIn {
|
||||
from {
|
||||
transform: translateY(24px);
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
import { userSettings } from "$lib/settings"
|
||||
import type { PostView } from "lemmy-js-client"
|
||||
import { get } from "svelte/store"
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
@@ -29,8 +29,8 @@ export const combineCrossposts = (
|
||||
posts?.forEach((post) => {
|
||||
if (
|
||||
!post ||
|
||||
(get(userSettings).hidePosts.deleted && post.post.deleted) ||
|
||||
(get(userSettings).hidePosts.removed && post.post.removed)
|
||||
(settings.hidePosts.deleted && post.post.deleted) ||
|
||||
(settings.hidePosts.removed && post.post.removed)
|
||||
)
|
||||
return
|
||||
if (!post?.post?.url) {
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
import { client, site } from '$lib/lemmy.js'
|
||||
import { client, site } from '$lib/lemmy.svelte.js'
|
||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||
import { Select, Spinner, Switch, toast } from 'mono-svelte'
|
||||
import {
|
||||
@@ -14,9 +16,9 @@
|
||||
Link,
|
||||
XMark,
|
||||
} from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { placeholders, uploadImage } from '$lib/util.js'
|
||||
import { placeholders, uploadImage } from '$lib/util.svelte.js'
|
||||
import { Checkbox, TextInput } from 'mono-svelte'
|
||||
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
||||
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
||||
@@ -32,49 +34,63 @@
|
||||
} from '$lib/components/error/ErrorContainer.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
|
||||
export let edit = false
|
||||
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
export let editingPost: Post | undefined = undefined
|
||||
|
||||
export let passedCommunity: Community | undefined = undefined
|
||||
|
||||
export let data: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
} = {
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
interface Props {
|
||||
edit?: boolean
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
editingPost?: Post | undefined
|
||||
passedCommunity?: Community | undefined
|
||||
passedData?: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number | string
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
onsubmit?: (post: PostView) => void
|
||||
}
|
||||
|
||||
let {
|
||||
edit = false,
|
||||
editingPost = undefined,
|
||||
passedCommunity = undefined,
|
||||
passedData = {
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
},
|
||||
formtitle,
|
||||
onsubmit,
|
||||
}: Props = $props()
|
||||
|
||||
let data = $state(passedData)
|
||||
|
||||
// weird select menu language handling
|
||||
// @ts-ignore
|
||||
$: if (data.language_id === '') data.language_id = undefined
|
||||
$effect(() => {
|
||||
if (data.language_id === '') data.language_id = undefined
|
||||
})
|
||||
|
||||
let saveDraft = edit ? false : true
|
||||
let communitySearch = passedCommunity?.name ?? ''
|
||||
let communitySearch = $state(passedCommunity?.name ?? '')
|
||||
|
||||
let communities: Community[] = []
|
||||
|
||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
||||
let communities: Community[] = $state([])
|
||||
|
||||
onMount(async () => {
|
||||
if (editingPost) {
|
||||
@@ -117,7 +133,7 @@
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!data.title || !$profile?.jwt) return
|
||||
if (!data.title || !profile.data?.jwt) return
|
||||
if (data.url && data.url != '') {
|
||||
try {
|
||||
new URL(data.url)
|
||||
@@ -153,7 +169,7 @@
|
||||
|
||||
console.log(`Edited post ${post?.post_view.post.id}`)
|
||||
|
||||
dispatcher('submit', post.post_view)
|
||||
onsubmit?.(post.post_view)
|
||||
} else {
|
||||
const post = await client().createPost({
|
||||
community_id: data.community!.id,
|
||||
@@ -171,7 +187,7 @@
|
||||
console.log(`Uploaded post ${post?.post_view.post.id}`)
|
||||
|
||||
saveDraft = false
|
||||
dispatcher('submit', post.post_view)
|
||||
onsubmit?.(post.post_view)
|
||||
}
|
||||
} catch (err) {
|
||||
pushError({ message: errorMessage(err as any), scope: 'post-form' })
|
||||
@@ -179,7 +195,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let uploadingImage = $state(false)
|
||||
|
||||
const generateTitle = async (url: string | undefined) => {
|
||||
if (!url) return
|
||||
@@ -224,15 +240,17 @@
|
||||
return true
|
||||
}
|
||||
|
||||
let generation = {
|
||||
let generation = $state({
|
||||
loading: false,
|
||||
generatable: false,
|
||||
title: '',
|
||||
}
|
||||
})
|
||||
|
||||
let addAltText = false
|
||||
let addAltText = $state(false)
|
||||
|
||||
$: generation.generatable = canGenerateTitle(data.url)
|
||||
run(() => {
|
||||
generation.generatable = canGenerateTitle(data.url)
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage}
|
||||
@@ -240,32 +258,32 @@
|
||||
<UploadModal
|
||||
bind:open={uploadingImage}
|
||||
multiple={false}
|
||||
on:upload={(e) => {
|
||||
if (e.detail) data.url = e.detail[0]
|
||||
onupload={(e) => {
|
||||
if (e) data.url = e[0]
|
||||
uploadingImage = false
|
||||
}}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
||||
<slot name="formtitle">
|
||||
<form onsubmit={preventDefault(submit)} class="flex flex-col gap-4 h-full">
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header class="font-bold text-xl">
|
||||
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
||||
</Header>
|
||||
</slot>
|
||||
{/if}
|
||||
<ErrorContainer scope="post-form" />
|
||||
{#if !edit && data}
|
||||
{#if !data.community}
|
||||
<ObjectAutocomplete
|
||||
bind:q={communitySearch}
|
||||
bind:items={communities}
|
||||
jwt={$profile?.jwt}
|
||||
items={communities}
|
||||
jwt={profile.data?.jwt}
|
||||
listing_type="All"
|
||||
label={$t('form.post.community')}
|
||||
required
|
||||
on:select={(e) => {
|
||||
const c = e.detail
|
||||
onselect={(e) => {
|
||||
const c = e
|
||||
if (!c) {
|
||||
data.community = null
|
||||
return
|
||||
@@ -281,16 +299,17 @@
|
||||
<span class="font-medium text-sm">{$t('form.post.community')}</span>
|
||||
<Button
|
||||
class="w-full !bg-white dark:!bg-black h-[38px]"
|
||||
on:click={() => (data.community = null)}
|
||||
onclick={() => (data.community = null)}
|
||||
alignment="left"
|
||||
size="sm"
|
||||
>
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Avatar
|
||||
url={data?.community?.icon}
|
||||
alt={data.community?.name}
|
||||
width={24}
|
||||
/>
|
||||
{/snippet}
|
||||
<div class="flex flex-col gap-0">
|
||||
<span class="text-xs">{data.community.name}</span>
|
||||
<span class="text-[10px] leading-3">
|
||||
@@ -311,7 +330,7 @@
|
||||
<MarkdownEditor
|
||||
label={$t('form.post.body')}
|
||||
bind:value={data.body}
|
||||
placeholder={placeholders.get('post')}
|
||||
placeholder={placeholders.get('body')}
|
||||
previewButton
|
||||
/>
|
||||
{#if data.url !== undefined}
|
||||
@@ -324,46 +343,47 @@
|
||||
/>
|
||||
<div class="flex items-center gap-2 actions">
|
||||
<div
|
||||
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center"
|
||||
class="border border-slate-100 dark:border-zinc-800 dark:text-zinc-400 text-slate-600 rounded-xl h-6 w-6 grid place-items-center"
|
||||
>
|
||||
<Icon src={Plus} size="16" micro slot="prefix" />
|
||||
<Icon src={Plus} size="16" micro />
|
||||
</div>
|
||||
{#if data.url}
|
||||
<Button
|
||||
on:click={() => (addAltText = !addAltText)}
|
||||
onclick={() => (addAltText = !addAltText)}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon
|
||||
src={ChatBubbleBottomCenterText}
|
||||
size="15"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>{$t('form.post.altText')}
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||
{/snippet}{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
onclick={() => (uploadingImage = !uploadingImage)}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Photo} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
<Button
|
||||
on:click={() => generateTitle(data.url)}
|
||||
onclick={() => generateTitle(data.url)}
|
||||
loading={generation.loading}
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Sparkles} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
@@ -373,7 +393,7 @@
|
||||
<div class="flex flex-row gap-2 flex-wrap">
|
||||
{#if data.url === undefined}
|
||||
<Button
|
||||
on:click={async () => {
|
||||
onclick={async () => {
|
||||
data.url = ''
|
||||
try {
|
||||
const url = new URL(await navigator.clipboard.readText())
|
||||
@@ -388,7 +408,7 @@
|
||||
{$t('form.post.addUrl')}
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
data.url = ''
|
||||
uploadingImage = true
|
||||
}}
|
||||
@@ -400,7 +420,7 @@
|
||||
</Button>
|
||||
{/if}
|
||||
{#if data.language_id === undefined}
|
||||
<Button size="sm" rounding="pill" on:click={() => (data.language_id = 0)}>
|
||||
<Button size="sm" rounding="pill" onclick={() => (data.language_id = 0)}>
|
||||
<Icon src={Language} size="16" micro />
|
||||
{$t('form.post.setLanguage')}
|
||||
</Button>
|
||||
@@ -413,18 +433,18 @@
|
||||
{/if}
|
||||
<Switch bind:checked={data.nsfw}>{$t('form.post.nsfw')}</Switch>
|
||||
{#if data.language_id !== undefined}
|
||||
{#if $site}
|
||||
{#if site.data}
|
||||
<Select
|
||||
class="w-max"
|
||||
label={$t('settings.app.lang.title')}
|
||||
bind:value={data.language_id}
|
||||
>
|
||||
<option value={undefined}>
|
||||
<Option value={undefined}>
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{$t('form.post.unset')}
|
||||
</option>
|
||||
{#each $site?.all_languages as language}
|
||||
<option value={language.id.toString()}>{language.name}</option>
|
||||
</Option>
|
||||
{#each site.data?.all_languages as language}
|
||||
<Option value={language.id.toString()}>{language.name}</Option>
|
||||
{/each}
|
||||
</Select>
|
||||
{:else}
|
||||
@@ -433,7 +453,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="mt-auto" />
|
||||
<div class="mt-auto"></div>
|
||||
<div class="flex flex-row items-center gap-2 w-full">
|
||||
<Button
|
||||
submit
|
||||
@@ -448,7 +468,7 @@
|
||||
|
||||
{#if !edit}
|
||||
<Button
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
toast({ content: $t('toast.restoredFromDraft') })
|
||||
const draft = getSessionStorage('postDraft')
|
||||
if (draft && !edit) {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { client, getInstance } from '$lib/lemmy.js'
|
||||
import type { View } from '$lib/settings'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { instance } from '$lib/instance.svelte'
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import type { View } from '$lib/settings.svelte'
|
||||
import { isImage, isVideo } from '$lib/ui/image'
|
||||
import { canParseUrl, findClosestNumber } from '$lib/util'
|
||||
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
|
||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
me.person.id == comment.creator.id
|
||||
@@ -10,17 +13,18 @@ export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
export const bestImageURL = (
|
||||
post: Post,
|
||||
compact: boolean = true,
|
||||
width: number = 1024
|
||||
width: number = 1024,
|
||||
) => {
|
||||
if (post.thumbnail_url) return optimizeImageURL(post.thumbnail_url, width)
|
||||
else if (post.url) return optimizeImageURL(post.url, width)
|
||||
if (post.url) return optimizeImageURL(post.url, width)
|
||||
else if (post.thumbnail_url)
|
||||
return optimizeImageURL(post.thumbnail_url, width)
|
||||
|
||||
return post.url ?? ''
|
||||
}
|
||||
|
||||
export const optimizeImageURL = (
|
||||
urlStr: string,
|
||||
width: number = 1024
|
||||
width: number = 1024,
|
||||
): string => {
|
||||
try {
|
||||
const url = new URL(urlStr)
|
||||
@@ -32,8 +36,8 @@ export const optimizeImageURL = (
|
||||
'thumbnail',
|
||||
findClosestNumber(
|
||||
[128, 196, 256, 512, 728, 1024, 1536],
|
||||
width
|
||||
).toString()
|
||||
width,
|
||||
).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,7 +61,8 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
||||
return url?.match?.(YOUTUBE_REGEX)
|
||||
}
|
||||
|
||||
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
||||
export const postLink = (post: Post) =>
|
||||
`/post/${encodeURIComponent(instance.data)}/${post.id}`
|
||||
|
||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||
export type IframeType = 'youtube' | 'video' | 'none'
|
||||
@@ -82,7 +87,7 @@ export const iframeType = (url: string): IframeType => {
|
||||
export async function hidePost(
|
||||
id: number,
|
||||
hide: boolean,
|
||||
jwt: string
|
||||
jwt: string,
|
||||
): Promise<boolean> {
|
||||
const res = await client({ auth: jwt }).hidePost({
|
||||
hide: hide,
|
||||
|
||||
@@ -8,18 +8,28 @@
|
||||
Link as LinkIcon,
|
||||
} from 'svelte-hero-icons'
|
||||
import { optimizeImageURL } from '../helpers'
|
||||
import PostLinkSources from './PostLinkSources.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import type { View } from '$lib/settings'
|
||||
import type { View } from '$lib/settings.svelte'
|
||||
|
||||
export let url: string
|
||||
export let thumbnail_url: string | undefined = undefined
|
||||
export let nsfw: boolean = false
|
||||
export let embed_title: string | undefined = undefined
|
||||
export let embed_description: string | undefined = undefined
|
||||
export let view: View = 'cozy'
|
||||
interface Props {
|
||||
url: string
|
||||
thumbnail_url?: string | undefined
|
||||
nsfw?: boolean
|
||||
embed_title?: string | undefined
|
||||
embed_description?: string | undefined
|
||||
view?: View
|
||||
}
|
||||
|
||||
$: richURL = parseURL(url)
|
||||
let {
|
||||
url,
|
||||
thumbnail_url = undefined,
|
||||
nsfw = false,
|
||||
embed_title = undefined,
|
||||
embed_description = undefined,
|
||||
view = 'cozy',
|
||||
}: Props = $props()
|
||||
|
||||
let richURL = $derived(parseURL(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -27,55 +37,38 @@
|
||||
For embed-type posts. Displays embed card or a compact link.
|
||||
-->
|
||||
{#if embed_title && view != 'compact'}
|
||||
<Material
|
||||
color="distinct"
|
||||
class="flex flex-col-reverse sm:flex-row
|
||||
<a target="_blank" href={url} class="group/link">
|
||||
<Material
|
||||
color="distinct"
|
||||
class="flex flex-col-reverse sm:flex-row
|
||||
overflow-hidden gap-4 embed-card z-0 relative
|
||||
dark:border-t-zinc-800 border-opacity-80 max-w-full"
|
||||
rounding="xl"
|
||||
element="article"
|
||||
>
|
||||
{#if thumbnail_url}
|
||||
<img
|
||||
src={optimizeImageURL(thumbnail_url, 64)}
|
||||
alt=""
|
||||
class="-z-10 absolute w-full object-cover h-full opacity-10 brightness-150
|
||||
dark:brightness-90 dark:opacity-20 blur-2xl
|
||||
-inset-px"
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col gap-2 mb-2">
|
||||
{#if richURL}
|
||||
<Link
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs"
|
||||
dark:border-t-zinc-800 border-opacity-80 max-w-full
|
||||
dark:bg-zinc-950 group-hover/link:bg-slate-50 group-hover/link:dark:bg-zinc-900 transition-colors"
|
||||
rounding="2xl"
|
||||
element="article"
|
||||
>
|
||||
{#if thumbnail_url}
|
||||
<img
|
||||
src={optimizeImageURL(thumbnail_url, 64)}
|
||||
alt=""
|
||||
class="-z-10 absolute w-full object-cover h-full opacity-10 brightness-150
|
||||
dark:brightness-90 dark:opacity-20 blur-2xl -inset-px"
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col gap-2">
|
||||
{#if richURL}
|
||||
<div
|
||||
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs font-medium"
|
||||
>
|
||||
{richURL.hostname}
|
||||
</div>
|
||||
{/if}
|
||||
<p class="font-medium text-base">{embed_title}</p>
|
||||
</div>
|
||||
{#if thumbnail_url}
|
||||
<picture
|
||||
class="-m-4 mb-auto sm:-mb-4 sm:ml-auto flex-shrink-0 sm:w-1/3 sm:max-w-60"
|
||||
>
|
||||
{richURL.hostname}
|
||||
</Link>
|
||||
{/if}
|
||||
<a
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="font-medium text-base hover:underline"
|
||||
>
|
||||
{embed_title}
|
||||
</a>
|
||||
{#if embed_description}
|
||||
<p class="text-sm">
|
||||
{embed_description.slice(0, 300)}{embed_description.length > 300
|
||||
? '...'
|
||||
: ''}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
{#if thumbnail_url}
|
||||
<a
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="-m-4 mb-auto sm:-mb-4 sm:ml-auto flex-shrink-0 sm:w-1/3 sm:min-h-40 sm:max-w-60"
|
||||
>
|
||||
<picture>
|
||||
<source
|
||||
srcset={optimizeImageURL(thumbnail_url, 256)}
|
||||
media="(max-width: 256px)"
|
||||
@@ -90,82 +83,41 @@
|
||||
/>
|
||||
<img
|
||||
src={optimizeImageURL(thumbnail_url, -1)}
|
||||
class="object-cover w-full sm:max-w-96 h-48 sm:min-h-40 sm:h-full bg-slate-200 dark:bg-zinc-800"
|
||||
class="object-cover w-full sm:max-w-96 h-32 sm:min-h-16 bg-slate-200 dark:bg-zinc-800"
|
||||
width={600}
|
||||
height={400}
|
||||
alt={embed_title}
|
||||
alt=" "
|
||||
class:blur-3xl={nsfw}
|
||||
/>
|
||||
</picture>
|
||||
</a>
|
||||
{/if}
|
||||
</Material>
|
||||
<div
|
||||
class="bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800
|
||||
rounded-full flex p-1 relative -top-7 min-[384px]:mx-3 mt-8 min-[384px]:mt-0 mx-auto -mb-7 w-max max-w-full overflow-auto"
|
||||
>
|
||||
<PostLinkSources {url}>
|
||||
<Button
|
||||
color="tertiary"
|
||||
slot="target"
|
||||
size="sm"
|
||||
class="w-max text-slate-600 dark:text-zinc-400 block
|
||||
text-xs flex-shrink-0"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon
|
||||
src={LinkIcon}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{$t('post.actions.link.actions')}
|
||||
</Button>
|
||||
</PostLinkSources>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex space-x-1">
|
||||
<PostLinkSources {url}>
|
||||
<Button
|
||||
color="ghost"
|
||||
slot="target"
|
||||
size="xs"
|
||||
rounding="pill"
|
||||
class="p-0.5 px-1 w-max mt-auto text-slate-600 dark:text-zinc-400 block
|
||||
text-xs"
|
||||
>
|
||||
<div class="mr-0.5" style="width: 8px;">
|
||||
<Icon src={LinkIcon} size="16" micro slot="prefix" />
|
||||
</div>
|
||||
<div class="mr-1" style="width: 8px;">
|
||||
<Icon src={ChevronDown} size="16" micro slot="suffix" />
|
||||
</div>
|
||||
</Button>
|
||||
</PostLinkSources>
|
||||
<Button
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="text-slate-900 dark:text-zinc-300 items-center
|
||||
text-xs overflow-hidden max-w-full block flex-shrink"
|
||||
size="xs"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
>
|
||||
{#if richURL}
|
||||
<div class="flex max-w-full overflow-hidden font-medium">
|
||||
{richURL.hostname}
|
||||
{#if richURL.pathname != '/'}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 whitespace-nowrap font-normal"
|
||||
>
|
||||
{richURL.pathname}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{url}
|
||||
{/if}
|
||||
</Button>
|
||||
</div>
|
||||
</Material>
|
||||
</a>
|
||||
{:else}
|
||||
<Button
|
||||
href={url}
|
||||
target="_blank"
|
||||
class="text-slate-900 dark:text-zinc-300 items-center
|
||||
text-xs overflow-hidden max-w-full block flex-shrink self-start w-max"
|
||||
size="xs"
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
>
|
||||
{#if richURL}
|
||||
<div
|
||||
class="flex max-w-full overflow-hidden font-medium self-start justify-self-start w-max"
|
||||
>
|
||||
{richURL.hostname}
|
||||
{#if richURL.pathname != '/'}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 whitespace-nowrap font-normal"
|
||||
>
|
||||
{richURL.pathname}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{url}
|
||||
{/if}
|
||||
</Button>
|
||||
{/if}
|
||||
@@ -1,72 +0,0 @@
|
||||
<script lang="ts" context="module">
|
||||
const sources: {
|
||||
getLink: (url: string) => string
|
||||
name: string
|
||||
type: MediaType
|
||||
}[] = [
|
||||
{
|
||||
getLink: (url: string) =>
|
||||
`https://archive.ph/${encodeURIComponent(url.split('?')[0])}`,
|
||||
name: 'Archive Today',
|
||||
type: 'embed',
|
||||
},
|
||||
{
|
||||
getLink: (url: string) =>
|
||||
`https://ghostarchive.org/search?term=${encodeURIComponent(url.split('?')[0])}`,
|
||||
name: 'Ghost Archive',
|
||||
type: 'embed',
|
||||
},
|
||||
{
|
||||
getLink: (url: string) =>
|
||||
`https://12ft.io/proxy?q=${encodeURIComponent(url.split('?')[0])}`,
|
||||
name: '12ft.io',
|
||||
type: 'embed',
|
||||
},
|
||||
{
|
||||
getLink: (url: string) =>
|
||||
`https://ground.news/find?url=${encodeURIComponent(url.split('?')[0])}`,
|
||||
name: 'Ground News',
|
||||
type: 'embed',
|
||||
},
|
||||
{
|
||||
getLink: (url: string) =>
|
||||
`https://spinscore.io/?url=${encodeURIComponent(url.split('?')[0])}`,
|
||||
name: 'spinscore.io',
|
||||
type: 'embed',
|
||||
},
|
||||
]
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/translations'
|
||||
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import type { MediaType } from '../helpers'
|
||||
import { Icon, Share } from 'svelte-hero-icons'
|
||||
|
||||
export let url: string
|
||||
export let type: MediaType = 'embed'
|
||||
</script>
|
||||
|
||||
<Menu {...$$restProps}>
|
||||
<slot name="target" slot="target" />
|
||||
|
||||
<MenuDivider>{$t('post.actions.link.title')}</MenuDivider>
|
||||
{#each sources as source}
|
||||
{#if source.type == type}
|
||||
<MenuButton target="_blank" href={source.getLink(url)}>
|
||||
{source.name}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/each}
|
||||
<MenuDivider>{$t('post.actions.link.actions')}</MenuDivider>
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
navigator?.share?.({ url: url }) ?? navigator?.clipboard?.writeText?.(url)
|
||||
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
>
|
||||
<Icon src={Share} size="16" micro slot="prefix" />
|
||||
{$t('post.actions.more.share')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -1,14 +1,14 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
const youtubeDomain = (place: 'youtube' | 'invidious' | 'piped') => {
|
||||
switch (place) {
|
||||
case 'youtube': {
|
||||
return 'www.youtube-nocookie.com'
|
||||
}
|
||||
case 'invidious': {
|
||||
return get(userSettings).embeds.invidious || 'yewtu.be'
|
||||
return settings.embeds.invidious || 'yewtu.be'
|
||||
}
|
||||
case 'piped': {
|
||||
return get(userSettings).embeds.piped || 'piped.video'
|
||||
return settings.embeds.piped || 'piped.video'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,15 +34,9 @@
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import { optimizeImageURL, type IframeType, type MediaType } from '../helpers'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export let type: IframeType = 'none'
|
||||
export let thumbnail: string | undefined = undefined
|
||||
export let url: string
|
||||
export let opened = !$userSettings.embeds.clickToView
|
||||
export let autoplay: boolean = $userSettings.embeds.clickToView
|
||||
|
||||
const urlToEmbed = (inputUrl: string) => {
|
||||
if (type == 'video') {
|
||||
return inputUrl
|
||||
@@ -56,7 +50,7 @@
|
||||
if (autoplay) url.searchParams.set('autoplay', '1')
|
||||
|
||||
return `https://${youtubeDomain(
|
||||
$userSettings.embeds.youtube
|
||||
settings.embeds.youtube,
|
||||
)}/embed/${videoID}?${url.searchParams.toString()}`
|
||||
}
|
||||
|
||||
@@ -64,7 +58,7 @@
|
||||
}
|
||||
|
||||
const typeData = (
|
||||
type: IframeType
|
||||
type: IframeType,
|
||||
): {
|
||||
icon: IconSource
|
||||
text: string
|
||||
@@ -91,8 +85,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = typeData(type)
|
||||
$: embedUrl = urlToEmbed(url)
|
||||
interface Props {
|
||||
type?: IframeType
|
||||
thumbnail?: string | undefined
|
||||
url: string
|
||||
opened?: any
|
||||
autoplay?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
type = 'none',
|
||||
thumbnail = undefined,
|
||||
url,
|
||||
opened = $bindable(!settings.embeds.clickToView),
|
||||
autoplay = settings.embeds.clickToView,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let data = $derived(typeData(type))
|
||||
let embedUrl = $derived(urlToEmbed(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -101,8 +113,8 @@
|
||||
-->
|
||||
{#if opened}
|
||||
{#if type == 'video'}
|
||||
<!-- svelte-ignore a11y-media-has-caption -->
|
||||
<video {autoplay} controls class="rounded-xl aspect-video {$$props.class}">
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video {autoplay} controls class="rounded-xl aspect-video {clazz}">
|
||||
<source src={url} />
|
||||
</video>
|
||||
{:else}
|
||||
@@ -112,12 +124,12 @@
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
allowfullscreen
|
||||
class="aspect-video rounded-xl dark:bg-zinc-900 {$$props.class ?? ''}"
|
||||
/>
|
||||
class="aspect-video rounded-xl dark:bg-zinc-900 {clazz ?? ''}"
|
||||
></iframe>
|
||||
{/if}
|
||||
{:else}
|
||||
<button
|
||||
on:click={() => (opened = true)}
|
||||
onclick={() => (opened = true)}
|
||||
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white"
|
||||
>
|
||||
{#if thumbnail}
|
||||
@@ -129,7 +141,7 @@
|
||||
{:else}
|
||||
<div
|
||||
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-gradient-to-br from-green-800 via-blue-900 via-20% to-red-700"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<Icon src={data.icon} solid size="48" />
|
||||
<h1 class="font-bold text-xl">{data.text}</h1>
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { userSettings, type View } from '$lib/settings'
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import { settings, type View } from '$lib/settings.svelte'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { bestImageURL, postLink } from '../helpers'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { Button, modal } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let post: Post
|
||||
export let blur: boolean = false
|
||||
interface Props {
|
||||
post: Post
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let imageLoaded: boolean | null = null
|
||||
let { post, blur = false }: Props = $props()
|
||||
|
||||
let imageLoaded: boolean | null = $state(null)
|
||||
|
||||
onMount(() => {
|
||||
imageLoaded = false
|
||||
@@ -18,16 +24,16 @@
|
||||
|
||||
<!--disabled preloads here since most people will hover over every image while scrolling-->
|
||||
<svelte:element
|
||||
this={$userSettings.expandImages ? 'button' : 'a'}
|
||||
this={settings.expandImages ? 'button' : 'a'}
|
||||
href={postLink(post)}
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
on:click={() => showImage(bestImageURL(post, false, -1))}
|
||||
onclick={() => showImage(bestImageURL(post, false, -1))}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
loading="lazy"
|
||||
fetchpriority="auto"
|
||||
@@ -37,22 +43,18 @@
|
||||
/>
|
||||
<picture class="max-h-[inherit]">
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 256)}
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
media="(max-width: 256px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 512)}
|
||||
srcset={bestImageURL(post, false, 1024)}
|
||||
media="(max-width: 512px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 1024)}
|
||||
srcset={bestImageURL(post, false, 1536)}
|
||||
media="(max-width: 1024px)"
|
||||
/>
|
||||
<source
|
||||
srcset={bestImageURL(post, false, 1512)}
|
||||
media="(max-width: 1512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, -1)}
|
||||
loading="lazy"
|
||||
@@ -63,20 +65,20 @@
|
||||
height={300}
|
||||
class:blur-[64px]={blur}
|
||||
alt={post.alt_text ?? ''}
|
||||
on:load={() => (imageLoaded = true)}
|
||||
onload={() => (imageLoaded = true)}
|
||||
/>
|
||||
</picture>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
||||
rounded-full ml-auto w-max m-2 p-0 gap-1
|
||||
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900"
|
||||
on:click|stopPropagation={() => {}}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Button
|
||||
on:click={(e) => {
|
||||
onclick={(e) => {
|
||||
e.stopPropagation()
|
||||
modal({
|
||||
title: 'Alt',
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import ExpandableImage, {
|
||||
showImage,
|
||||
} from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import PostIframe from './PostIframe.svelte'
|
||||
import { Button, Material, modal } from 'mono-svelte'
|
||||
@@ -18,11 +18,21 @@
|
||||
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import PostImage from './PostImage.svelte'
|
||||
|
||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let opened: boolean | undefined = undefined
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
interface Props {
|
||||
view?: View
|
||||
post: Post
|
||||
type?: MediaType
|
||||
opened?: boolean | undefined
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
view = 'cozy',
|
||||
post,
|
||||
type = 'none',
|
||||
opened = undefined,
|
||||
blur = post.nsfw && settings.nsfwBlur,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -31,9 +41,9 @@
|
||||
- A media item (pictures, videos) (large form factor posts only)
|
||||
- Embed link/card.
|
||||
-->
|
||||
{#if type == 'image' && (view == 'cozy' || view == 'card')}
|
||||
{#if type == 'image' && view == 'cozy'}
|
||||
<PostImage {post} {blur} />
|
||||
{:else if (type == 'iframe' || type == 'video') && (view == 'cozy' || view == 'card') && post.url}
|
||||
{:else if (type == 'iframe' || type == 'video') && view == 'cozy' && post.url}
|
||||
<PostIframe
|
||||
thumbnail={post.thumbnail_url}
|
||||
type={iframeType(post.url)}
|
||||
@@ -43,7 +53,7 @@
|
||||
{:else if type == 'embed' && post.url}
|
||||
<PostLink
|
||||
url={post.url}
|
||||
thumbnail_url={view != 'list' ? post.thumbnail_url : undefined}
|
||||
thumbnail_url={post.thumbnail_url}
|
||||
nsfw={post.nsfw}
|
||||
embed_description={post.embed_description}
|
||||
embed_title={post.embed_title}
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
type MediaType,
|
||||
} from '$lib/components/lemmy/post/helpers.js'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { userSettings, type View } from '$lib/settings.js'
|
||||
import { settings, type View } from '$lib/settings.svelte.js'
|
||||
import { t } from '$lib/translations'
|
||||
import { isImage } from '$lib/ui/image'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { Material, Popover } from 'mono-svelte'
|
||||
import { Material, modal, Popover } from 'mono-svelte'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import {
|
||||
DocumentText,
|
||||
Icon,
|
||||
@@ -18,48 +20,48 @@
|
||||
ExclamationTriangle,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let view: View = 'cozy'
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
|
||||
const thumbnailSize = (view: View) =>
|
||||
view == 'compact' ? 'w-22 h-22 sm:w-28' : 'w-24 h-24 sm:w-32'
|
||||
|
||||
$: size = thumbnailSize(view)
|
||||
interface Props {
|
||||
post: Post
|
||||
type?: MediaType
|
||||
view?: View
|
||||
blur?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
post,
|
||||
type = 'none',
|
||||
view = 'cozy',
|
||||
blur = post.nsfw && settings.nsfwBlur,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let size = $derived(thumbnailSize(view))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@component
|
||||
Thumbnails for compact and list view posts.
|
||||
-->
|
||||
<div
|
||||
class="{size} relative group/media {$$props.class ?? ''}"
|
||||
style={$$props.style ?? ''}
|
||||
>
|
||||
<div class="{size} relative group/media {clazz ?? ''}" {style}>
|
||||
{#if post.alt_text}
|
||||
<Popover
|
||||
openOnHover
|
||||
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
|
||||
<Button
|
||||
rounding="pill"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
onclick={() => modal({ title: 'Alt', body: post.alt_text ?? '' })}
|
||||
>
|
||||
<Material
|
||||
slot="target"
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
<div class="max-w-sm">
|
||||
{post.alt_text}
|
||||
</div>
|
||||
</Popover>
|
||||
ALT
|
||||
</Button>
|
||||
{/if}
|
||||
<svelte:element
|
||||
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
this={!settings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
href={postLink(post)}
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (type == 'image') {
|
||||
showImage(bestImageURL(post, false, -1))
|
||||
}
|
||||
@@ -69,19 +71,19 @@
|
||||
>
|
||||
{#if post.thumbnail_url || isImage(post.url)}
|
||||
<div class="relative overflow-hidden rounded-xl">
|
||||
<picture class="relative">
|
||||
<picture>
|
||||
<img
|
||||
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
|
||||
loading="lazy"
|
||||
class="object-cover overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl
|
||||
class="object-cover relative overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl
|
||||
transition-colors {size}"
|
||||
alt={post.name}
|
||||
alt={post.alt_text ?? ' '}
|
||||
class:blur-xl={blur}
|
||||
/>
|
||||
{#if type != 'image'}
|
||||
<div
|
||||
class="absolute w-8 h-8 bottom-0 left-0 m-1 rounded-xl text-slate-800 dark:text-zinc-200
|
||||
backdrop-blur-sm bg-slate-25/75 dark:bg-zinc-900/75 border border-slate-200/75 dark:border-zinc-700/75
|
||||
class="absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200
|
||||
bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700
|
||||
grid place-items-center"
|
||||
>
|
||||
<Icon
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import type { Community, ListingType, Person } from 'lemmy-js-client'
|
||||
import { MenuButton, Search } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, XCircle } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let q: string = ''
|
||||
interface Props {
|
||||
q?: string
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
onselect?: (e: any) => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let instance: string | undefined = undefined
|
||||
export let listing_type: ListingType = 'Subscribed'
|
||||
export let showWhenEmpty: boolean = false
|
||||
let {
|
||||
q = $bindable(''),
|
||||
instance = undefined,
|
||||
listing_type = 'Subscribed',
|
||||
showWhenEmpty = false,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: Person | undefined }>()
|
||||
</script>
|
||||
@@ -29,34 +40,34 @@
|
||||
return results.users.map((c) => c.person)
|
||||
}}
|
||||
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...$$restProps}
|
||||
let:item
|
||||
let:select
|
||||
{...rest}
|
||||
>
|
||||
<div class="w-full h-full" slot="noresults">
|
||||
{#if showWhenEmpty}
|
||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
<span>{item.name}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.name}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
@@ -11,15 +11,24 @@
|
||||
import { userLink } from '$lib/lemmy/generic'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
|
||||
export let user: PersonView
|
||||
export let view: 'cozy' | 'compact' = 'compact'
|
||||
export let showCounts: boolean = true
|
||||
interface Props {
|
||||
user: PersonView
|
||||
view?: 'cozy' | 'compact'
|
||||
showCounts?: boolean
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
user,
|
||||
view = 'compact',
|
||||
showCounts = true,
|
||||
class: clazz = 'py-4 flex flex-col gap-4 text-sm max-w-full relative',
|
||||
icon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={$$props.class ??
|
||||
'py-4 flex flex-col gap-4 text-sm max-w-full relative'}
|
||||
>
|
||||
<div class={clazz}>
|
||||
<div
|
||||
class="flex
|
||||
{view == 'cozy'
|
||||
@@ -32,9 +41,9 @@
|
||||
? 'flex-col gap-2'
|
||||
: 'flex-row'} gap-2 items-center"
|
||||
>
|
||||
<slot name="icon">
|
||||
{#if icon}{@render icon()}{:else}
|
||||
<Avatar url={user.person.avatar} width={32} alt={user.person.name} />
|
||||
</slot>
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<div class="font-medium text-base">
|
||||
{user.person.display_name ?? user.person.name}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { env } from '$env/dynamic/public'
|
||||
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
@@ -18,7 +18,7 @@
|
||||
const badges = parseBadge()
|
||||
|
||||
const getEnvBadge = (
|
||||
actor_id: string
|
||||
actor_id: string,
|
||||
):
|
||||
| {
|
||||
classes: string
|
||||
@@ -50,30 +50,48 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import Logo from '$lib/components/ui/Logo.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { Person } from 'lemmy-js-client'
|
||||
import { Icon, Language, NoSymbol } from 'svelte-hero-icons'
|
||||
|
||||
export let user: Person
|
||||
export let avatar: boolean = false
|
||||
export let avatarSize: number = 24
|
||||
export let badges: boolean = true
|
||||
export let inComment: boolean = false
|
||||
export let showInstance: boolean =
|
||||
$userSettings.showInstances.user ||
|
||||
($userSettings.showInstances.comments && inComment)
|
||||
export let displayName = $userSettings.displayNames
|
||||
interface Props {
|
||||
user: Person
|
||||
avatar?: boolean
|
||||
avatarSize?: number
|
||||
badges?: boolean
|
||||
inComment?: boolean
|
||||
showInstance?: boolean
|
||||
displayName?: any
|
||||
instanceClass?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
extraBadges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
$: envBadge = getEnvBadge(user.actor_id)
|
||||
let {
|
||||
user,
|
||||
avatar = false,
|
||||
avatarSize = 24,
|
||||
badges = true,
|
||||
inComment = false,
|
||||
showInstance = settings.showInstances.user ||
|
||||
(settings.showInstances.comments && inComment),
|
||||
displayName = settings.displayNames,
|
||||
instanceClass = '',
|
||||
class: clazz = '',
|
||||
children,
|
||||
extraBadges,
|
||||
}: Props = $props()
|
||||
|
||||
let envBadge = $derived(getEnvBadge(user.actor_id))
|
||||
</script>
|
||||
|
||||
<a
|
||||
class="items-center flex flex-row gap-1 hover:underline max-w-full min-w-0 {$$props.class ??
|
||||
''}"
|
||||
class="items-center flex flex-row gap-1 hover:underline max-w-full min-w-0 {clazz}"
|
||||
href="/u/{user.name}@{new URL(user.actor_id).hostname}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
{#if avatar}
|
||||
<Avatar
|
||||
url={user.avatar}
|
||||
@@ -94,7 +112,7 @@
|
||||
</span>
|
||||
{#if showInstance}
|
||||
<span
|
||||
class="text-slate-500 dark:text-zinc-500 font-normal instance-text flex-shrink {$$props.instanceClass ??
|
||||
class="text-slate-500 dark:text-zinc-500 font-normal instance-text flex-shrink {instanceClass ??
|
||||
''}"
|
||||
>
|
||||
@{new URL(user.actor_id).hostname}
|
||||
@@ -122,7 +140,7 @@
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
<slot name="badges" />
|
||||
{@render extraBadges?.()}
|
||||
{/if}
|
||||
</a>
|
||||
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { t } from '$lib/translations'
|
||||
import { TextInput } from 'mono-svelte'
|
||||
|
||||
let query: string = ''
|
||||
let loading = false
|
||||
let query: string = $state('')
|
||||
let loading = $state(false)
|
||||
|
||||
function search() {
|
||||
loading = true
|
||||
goto(`/search?q=${query}`).then(() => (loading = false))
|
||||
}
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<form on:submit|preventDefault={search} class="w-full h-full {$$props.class}">
|
||||
<form onsubmit={preventDefault(search)} class="w-full h-full {clazz}">
|
||||
<TextInput
|
||||
bind:value={query}
|
||||
class="w-full h-full {$$props.class}"
|
||||
class="w-full h-full {clazz}"
|
||||
placeholder={$t('nav.search')}
|
||||
autofocus
|
||||
/>
|
||||
</form>
|
||||
<slot {search} {loading} />
|
||||
{@render children?.({ search, loading })}
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { marked } from 'marked'
|
||||
import {
|
||||
MdCode,
|
||||
@@ -19,6 +19,7 @@
|
||||
MdListItem,
|
||||
MdSubscript,
|
||||
MdSuperscript,
|
||||
MdText,
|
||||
} from './renderers/index'
|
||||
import { linkify, subSupscriptExtension } from './renderers/plugins'
|
||||
import containerExtension from './renderers/spoiler/spoiler'
|
||||
@@ -85,30 +86,74 @@
|
||||
subscript: MdSubscript,
|
||||
superscript: MdSuperscript,
|
||||
}
|
||||
|
||||
export const inlineRenderers = {
|
||||
heading: MdText,
|
||||
image: MdText,
|
||||
link: MdText,
|
||||
blockquote: MdText,
|
||||
hr: MdText,
|
||||
html: MdText,
|
||||
code: MdText,
|
||||
list: MdText,
|
||||
// @ts-ignore
|
||||
spoiler: MdText,
|
||||
table: MdText,
|
||||
tablebody: MdText,
|
||||
tablecell: MdText,
|
||||
tablehead: MdText,
|
||||
tablerow: MdTableRow,
|
||||
paragraph: MdParagraph,
|
||||
listitem: MdText,
|
||||
subscript: MdSubscript,
|
||||
superscript: MdSuperscript,
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
import { setContext } from 'svelte'
|
||||
|
||||
export let source: string = ''
|
||||
export let inline: boolean = false
|
||||
interface RendererOptions {
|
||||
autoloadImages: boolean
|
||||
}
|
||||
|
||||
interface Props {
|
||||
source?: string
|
||||
inline?: boolean
|
||||
noStyle?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
rendererOptions?: RendererOptions
|
||||
}
|
||||
|
||||
let {
|
||||
source = '',
|
||||
inline = false,
|
||||
noStyle = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
rendererOptions = {
|
||||
autoloadImages: true,
|
||||
},
|
||||
}: Props = $props()
|
||||
|
||||
setContext('options', rendererOptions)
|
||||
|
||||
options.inline = inline
|
||||
|
||||
export let noStyle: boolean = false
|
||||
|
||||
$: tokens = marked.lexer(source)
|
||||
let tokens = $derived.by(() => marked.lexer(source))
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="{noStyle
|
||||
? ''
|
||||
: 'break-words flex flex-col gap-2 leading-[1.5]'} {$$props.class}"
|
||||
style={$$props.style}
|
||||
: 'break-words flex flex-col gap-2 leading-[1.5]'} {clazz}"
|
||||
{style}
|
||||
>
|
||||
<SvelteMarkdown
|
||||
bind:source={tokens}
|
||||
{renderers}
|
||||
source={tokens}
|
||||
renderers={inline ? inlineRenderers : renderers}
|
||||
{options}
|
||||
isInline={inline || undefined}
|
||||
/>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { uploadImage } from '$lib/util.js'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { ImageInput, toast } from 'mono-svelte'
|
||||
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
||||
import { createEventDispatcher, tick } from 'svelte'
|
||||
@@ -21,20 +23,10 @@
|
||||
Strikethrough,
|
||||
} from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
||||
import type { HTMLTextareaAttributes } from 'svelte/elements'
|
||||
import type { TextAreaProps } from 'mono-svelte/forms/TextArea.svelte'
|
||||
|
||||
export let images: boolean = true
|
||||
export let value: string = ''
|
||||
export let label: string | undefined = undefined
|
||||
export let previewButton: boolean = true
|
||||
export let tools: boolean = true
|
||||
export let disabled: boolean = false
|
||||
export let rows: number = 2
|
||||
|
||||
export let beforePreview: (input: string) => string = (input) => input
|
||||
|
||||
const dispatcher = createEventDispatcher<{ confirm: string }>()
|
||||
|
||||
let textArea: HTMLTextAreaElement
|
||||
let textArea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
function replaceTextAtIndices(
|
||||
str: string,
|
||||
@@ -46,6 +38,7 @@
|
||||
}
|
||||
|
||||
function wrapSelection(start: string, end: string) {
|
||||
if (!textArea) return
|
||||
const startPos = textArea.selectionStart
|
||||
const endPos = textArea.selectionEnd
|
||||
|
||||
@@ -66,10 +59,8 @@
|
||||
value = textArea.value
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let image: any
|
||||
|
||||
export let previewing = false
|
||||
let uploadingImage = $state(false)
|
||||
let image = $state<any>(null)
|
||||
|
||||
const shortcuts = {
|
||||
KeyB: () => wrapSelection('**', '**'),
|
||||
@@ -78,9 +69,9 @@
|
||||
KeyH: () => wrapSelection('\n# ', ''),
|
||||
KeyK: () => wrapSelection('[](', ')'),
|
||||
Enter: (e: any) => {
|
||||
dispatcher('confirm', value)
|
||||
onconfirm?.(value)
|
||||
const newEvent = new Event('submit', { cancelable: true })
|
||||
e.target.form.dispatchEvent(newEvent)
|
||||
e?.target?.form?.dispatchEvent(newEvent)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -92,15 +83,50 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: if (!previewing && value) adjustHeight()
|
||||
interface Props extends TextAreaProps {
|
||||
images?: boolean
|
||||
value?: string
|
||||
label?: string | undefined
|
||||
previewButton?: boolean
|
||||
tools?: boolean
|
||||
disabled?: boolean
|
||||
rows?: number
|
||||
beforePreview?: (input: string) => string
|
||||
previewing?: boolean
|
||||
class?: string
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
onconfirm?: (value: string) => void
|
||||
}
|
||||
|
||||
let {
|
||||
images = true,
|
||||
value = $bindable(''),
|
||||
label = undefined,
|
||||
previewButton = true,
|
||||
tools = true,
|
||||
disabled = false,
|
||||
rows = 2,
|
||||
beforePreview = (input) => input,
|
||||
previewing = $bindable(false),
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
children,
|
||||
onconfirm,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (!previewing && value) adjustHeight()
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage && images}
|
||||
<ImageUploadModal
|
||||
bind:open={uploadingImage}
|
||||
bind:image
|
||||
on:upload={(e) => {
|
||||
e.detail.forEach((i) => {
|
||||
onupload={(e) => {
|
||||
e.forEach((i) => {
|
||||
wrapSelection(`\n\n`, '')
|
||||
})
|
||||
}}
|
||||
@@ -108,12 +134,12 @@
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
{#if label || $$slots.label}
|
||||
{#if label || customLabel}
|
||||
<Label>
|
||||
{#if label}
|
||||
{label}
|
||||
{:else if $$slots.label}
|
||||
<slot name="label" />
|
||||
{:else if customLabel}
|
||||
{@render customLabel?.()}
|
||||
{/if}
|
||||
</Label>
|
||||
{/if}
|
||||
@@ -121,7 +147,7 @@
|
||||
class="flex flex-col border border-slate-200 border-b-slate-300 dark:border-t-zinc-700/70 dark:border-zinc-800
|
||||
focus-within:border-primary-900 focus-within:dark:border-primary-100 focus-within:ring ring-slate-300
|
||||
dark:ring-zinc-700 rounded-xl
|
||||
overflow-hidden transition-colors {$$props.class}"
|
||||
overflow-hidden transition-colors {clazz}"
|
||||
class:mt-1={label}
|
||||
>
|
||||
{#if previewing}
|
||||
@@ -135,68 +161,68 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
<!--Toolbar-->
|
||||
<div
|
||||
class="[&>*]:flex-shrink-0 flex flex-row overflow-auto p-1.5 gap-1.5 border-b
|
||||
border-slate-200 dark:border-zinc-900 {$$props.disabled
|
||||
border-slate-200 dark:border-zinc-900 {disabled
|
||||
? 'opacity-60 pointer-events-none'
|
||||
: ''}"
|
||||
>
|
||||
<Button
|
||||
on:click={() => wrapSelection('**', '**')}
|
||||
onclick={() => wrapSelection('**', '**')}
|
||||
title="Bold"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Bold} size="16" mini />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('*', '*')}
|
||||
onclick={() => wrapSelection('*', '*')}
|
||||
title="Italic"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Italic} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('[', '](https://example.com)')}
|
||||
onclick={() => wrapSelection('[', '](https://example.com)')}
|
||||
title="Link"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Link} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n# ', '')}
|
||||
onclick={() => wrapSelection('\n# ', '')}
|
||||
title="Header"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={H1} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('~~', '~~')}
|
||||
onclick={() => wrapSelection('~~', '~~')}
|
||||
title="Strikethrough"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Strikethrough} size="16" micro />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n> ', '')}
|
||||
onclick={() => wrapSelection('\n> ', '')}
|
||||
title="Quote"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold font-serif text-lg">"</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n- ', '')}
|
||||
onclick={() => wrapSelection('\n- ', '')}
|
||||
title="List"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ListBullet} micro size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('`', '`')}
|
||||
onclick={() => wrapSelection('`', '`')}
|
||||
title="Code"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={CodeBracket} micro size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() =>
|
||||
onclick={() =>
|
||||
wrapSelection('::: spoiler <spoiler title>\n', '\n:::')}
|
||||
title="Spoiler"
|
||||
size="square-md"
|
||||
@@ -204,7 +230,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
<Icon src={ExclamationTriangle} micro size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('~', '~')}
|
||||
onclick={() => wrapSelection('~', '~')}
|
||||
title="Subscript"
|
||||
size="square-md"
|
||||
>
|
||||
@@ -214,7 +240,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('^', '^')}
|
||||
onclick={() => wrapSelection('^', '^')}
|
||||
title="Superscript"
|
||||
size="square-md"
|
||||
>
|
||||
@@ -225,7 +251,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
</Button>
|
||||
{#if images}
|
||||
<Button
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
onclick={() => (uploadingImage = !uploadingImage)}
|
||||
title="Image"
|
||||
size="square-md"
|
||||
>
|
||||
@@ -239,7 +265,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
class="bg-inherit z-0 border-0 rounded-none !ring-0 focus:!ring-transparent !transition-none resize-none"
|
||||
bind:value
|
||||
bind:element={textArea}
|
||||
on:keydown={(e) => {
|
||||
onkeydown={(e) => {
|
||||
if (disabled) return
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
// @ts-ignore
|
||||
@@ -250,9 +276,8 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
}
|
||||
}
|
||||
}}
|
||||
on:input={adjustHeight}
|
||||
on:focus
|
||||
on:paste={(e) => {
|
||||
oninput={adjustHeight}
|
||||
onpaste={(e) => {
|
||||
if (!e.clipboardData?.files) return
|
||||
const files = Array.from(e.clipboardData.files)
|
||||
if (files[0]?.type.startsWith('image/')) {
|
||||
@@ -261,7 +286,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
}
|
||||
}}
|
||||
{rows}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -276,7 +301,7 @@ overflow-hidden transition-colors {$$props.class}"
|
||||
optionNames={[$t('form.edit'), $t('form.preview')]}
|
||||
/>
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Icon, ClipboardDocument } from 'svelte-hero-icons'
|
||||
|
||||
export let raw: string
|
||||
interface Props {
|
||||
raw: string
|
||||
}
|
||||
|
||||
let { raw }: Props = $props()
|
||||
|
||||
function parseCodeblock(src: string): {
|
||||
code: string
|
||||
@@ -21,7 +25,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: codeblock = parseCodeblock(raw)
|
||||
let codeblock = $derived(parseCodeblock(raw))
|
||||
</script>
|
||||
|
||||
<Material
|
||||
@@ -36,7 +40,7 @@
|
||||
<Button
|
||||
size="square-sm"
|
||||
color="tertiary"
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText(codeblock.code)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
<script lang="ts">
|
||||
export let depth: number = 0
|
||||
export let raw: string | undefined = undefined
|
||||
interface Props {
|
||||
depth?: number
|
||||
raw?: string | undefined
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { depth = 0, raw = undefined, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if depth === 1}
|
||||
<h1 class="font-bold text-4xl"><slot></slot></h1>
|
||||
<h1 class="font-bold text-4xl">{@render children?.()}</h1>
|
||||
{:else if depth === 2}
|
||||
<h2 class="font-bold text-3xl"><slot></slot></h2>
|
||||
<h2 class="font-bold text-3xl">{@render children?.()}</h2>
|
||||
{:else if depth === 3}
|
||||
<h3 class="font-bold text-2xl"><slot></slot></h3>
|
||||
<h3 class="font-bold text-2xl">{@render children?.()}</h3>
|
||||
{:else if depth === 4}
|
||||
<h4 class="font-semibold text-xl"><slot></slot></h4>
|
||||
<h4 class="font-semibold text-xl">{@render children?.()}</h4>
|
||||
{:else if depth === 5}
|
||||
<h5 class="font-semibold text-lg"><slot></slot></h5>
|
||||
<h5 class="font-semibold text-lg">{@render children?.()}</h5>
|
||||
{:else if depth === 6}
|
||||
<h6 class="font-semibold text-base"><slot></slot></h6>
|
||||
<h6 class="font-semibold text-base">{@render children?.()}</h6>
|
||||
{:else}
|
||||
{raw}
|
||||
{/if}
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -6,36 +6,64 @@
|
||||
optimizeImageURL,
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
import { getContext } from 'svelte'
|
||||
import { ArrowDown, ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let href: string
|
||||
export let title: string | undefined = undefined
|
||||
export let text: string = ''
|
||||
let loaded: boolean = $state(
|
||||
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
|
||||
true,
|
||||
)
|
||||
|
||||
$: type = mediaType(href, 'cozy')
|
||||
interface Props {
|
||||
href: string
|
||||
title?: string | undefined
|
||||
text?: string
|
||||
}
|
||||
|
||||
let { href, title = undefined, text = '' }: Props = $props()
|
||||
|
||||
let type = $derived(mediaType(href, 'cozy'))
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
|
||||
inline-block"
|
||||
>
|
||||
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
||||
<PostIframe
|
||||
type={iframeType(href)}
|
||||
url={href}
|
||||
opened={true}
|
||||
autoplay={false}
|
||||
class="w-auto h-auto max-h-80 inline-block rounded-lg"
|
||||
/>
|
||||
{#if loaded}
|
||||
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
||||
<PostIframe
|
||||
type={iframeType(href)}
|
||||
url={href}
|
||||
opened={true}
|
||||
autoplay={false}
|
||||
class="w-auto h-auto max-h-80 inline-block rounded-lg"
|
||||
/>
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
onclick={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
{title}
|
||||
alt={text}
|
||||
width={300}
|
||||
height={300}
|
||||
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
on:click={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
onclick={() => (loaded = true)}
|
||||
class="w-40 h-40 flex flex-col justify-center items-center gap-4 p-2 group"
|
||||
title={$t('common.download')}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
{title}
|
||||
alt={text}
|
||||
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
|
||||
<Icon
|
||||
src={ArrowDownTray}
|
||||
size="24"
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { photonify } from './plugins'
|
||||
|
||||
export let href = ''
|
||||
export let title = undefined
|
||||
interface Props {
|
||||
href?: string
|
||||
title?: any
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { href = '', title = undefined, children }: Props = $props()
|
||||
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
@@ -12,7 +17,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: photonified = photonify(href)
|
||||
let photonified = $derived(photonify(href))
|
||||
</script>
|
||||
|
||||
<a
|
||||
@@ -20,5 +25,5 @@
|
||||
{title}
|
||||
class="hover:underline text-sky-600 dark:text-sky-500"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</a>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let ordered: boolean
|
||||
export let start: number
|
||||
interface Props {
|
||||
ordered: boolean
|
||||
start: number
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { ordered, start, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if ordered}
|
||||
@@ -8,12 +13,12 @@
|
||||
{start}
|
||||
class="pl-5 list-decimal *:marker:font-medium *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ol>
|
||||
{:else}
|
||||
<ul
|
||||
class="list-disc pl-4 *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
{/if}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
export let tokens
|
||||
let { tokens, children } = $props()
|
||||
</script>
|
||||
|
||||
<li>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</li>
|
||||
@@ -1,9 +1,16 @@
|
||||
<script>
|
||||
import { options } from '../Markdown.svelte'
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<p class="leading-[1.5] {options.inline ? '' : 'max-w'}">
|
||||
<slot />
|
||||
<p class="leading-[1.5] break-words {options.inline ? '' : 'max-w'}">
|
||||
{@render children?.()}
|
||||
</p>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<blockquote class="border-l-2 dark:border-zinc-700 border-slate-300 p-1 px-3">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</blockquote>
|
||||
@@ -6,7 +6,11 @@
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
|
||||
export let raw: string
|
||||
interface Props {
|
||||
raw: string
|
||||
}
|
||||
|
||||
let { raw }: Props = $props()
|
||||
|
||||
function extractTitle(text: string) {
|
||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||
@@ -25,12 +29,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = extractTitle(raw)
|
||||
let data = $derived(extractTitle(raw))
|
||||
</script>
|
||||
|
||||
<Expandable class="border-y border-slate-200 dark:border-zinc-800 py-2">
|
||||
<div slot="title" class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
{#snippet title()}
|
||||
<div class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
{/snippet}
|
||||
<SvelteMarkdown source={data.content} {renderers} {options} />
|
||||
</Expandable>
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<sub>{text}</sub>
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<sup>{text}</sup>
|
||||
@@ -1 +1,11 @@
|
||||
<slot />
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
{@render children?.()}
|
||||
@@ -16,6 +16,7 @@ import MdParagraph from './MdParagraph.svelte'
|
||||
import MdListItem from './MdListItem.svelte'
|
||||
import MdSubscript from './MdSubscript.svelte'
|
||||
import MdSuperscript from './MdSuperscript.svelte'
|
||||
import MdText from './MdText.svelte'
|
||||
|
||||
export {
|
||||
MdCode,
|
||||
@@ -36,4 +37,5 @@ export {
|
||||
MdListItem,
|
||||
MdSubscript,
|
||||
MdSuperscript,
|
||||
MdText,
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export const linkify = markedLinkifyIt(
|
||||
|
||||
if (!self.re.community) {
|
||||
self.re.community = new RegExp(
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i,
|
||||
)
|
||||
}
|
||||
if (self.re.community.test(tail)) {
|
||||
@@ -63,7 +63,7 @@ export const linkify = markedLinkifyIt(
|
||||
|
||||
if (!self.re.user) {
|
||||
self.re.user = new RegExp(
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i,
|
||||
)
|
||||
}
|
||||
if (self.re.user.test(tail)) {
|
||||
@@ -86,7 +86,7 @@ export const linkify = markedLinkifyIt(
|
||||
},
|
||||
{
|
||||
fuzzyEmail: false,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const regexes = {
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<table class="overflow-auto w-full table-fixed rounded-xl">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</table>
|
||||
@@ -1 +1,11 @@
|
||||
<tbody><slot /></tbody>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<tbody>{@render children?.()}</tbody>
|
||||
@@ -1,13 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let header: boolean
|
||||
export let align:
|
||||
| 'left'
|
||||
| 'center'
|
||||
| 'right'
|
||||
| 'justify'
|
||||
| 'char'
|
||||
| null
|
||||
| undefined = undefined
|
||||
interface Props {
|
||||
header: boolean
|
||||
align?: 'left' | 'center' | 'right' | 'justify' | 'char' | null | undefined
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { header, align = undefined, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if header}
|
||||
@@ -15,13 +13,13 @@
|
||||
class="bg-slate-50 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||
{align}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</th>
|
||||
{:else}
|
||||
<td
|
||||
class="bg-slate-25 dark:bg-zinc-950 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||
{align}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</td>
|
||||
{/if}
|
||||
@@ -1 +1,11 @@
|
||||
<thead><slot /></thead>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<thead>{@render children?.()}</thead>
|
||||
@@ -1 +1,11 @@
|
||||
<tr><slot /></tr>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<tr>{@render children?.()}</tr>
|
||||
@@ -0,0 +1,186 @@
|
||||
<script lang="ts" generics="T">
|
||||
import { browser } from '$app/environment'
|
||||
import { debounce } from 'mono-svelte/util/time'
|
||||
import { onDestroy, tick, untrack, type Snippet } from 'svelte'
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
import { innerHeight } from 'svelte/reactivity/window'
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||
items: T[]
|
||||
estimatedHeight?: number
|
||||
overscan?: number
|
||||
item: Snippet<[T, number, Function]>
|
||||
restore?: {
|
||||
itemHeights: (number | null)[]
|
||||
}
|
||||
initialOffset?: number
|
||||
}
|
||||
|
||||
let {
|
||||
items,
|
||||
estimatedHeight = 100,
|
||||
overscan = 5,
|
||||
item: itemSnippet,
|
||||
initialOffset = 0,
|
||||
restore = $bindable(),
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
export function scrollToIndex(index: number, useWindow: boolean = false) {
|
||||
scrollPosition = cumulativeItemHeights[index] - initialOffset || 0
|
||||
if (useWindow && browser)
|
||||
window.scrollTo({ behavior: 'instant', top: scrollPosition })
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
restore = {
|
||||
itemHeights: itemHeights,
|
||||
}
|
||||
})
|
||||
|
||||
let virtualListEl = $state<HTMLElement>()
|
||||
|
||||
let itemHeights = $state<(number | null)[]>([
|
||||
...(restore?.itemHeights ?? Array(items.length).fill(null)),
|
||||
])
|
||||
let cumulativeItemHeights = $derived.by(() => {
|
||||
let cumulation = new Array(itemHeights.length)
|
||||
let sum = 0
|
||||
|
||||
for (let i = 0; i < itemHeights.length; i++) {
|
||||
const height = itemHeights[i] || estimatedHeight
|
||||
sum += height
|
||||
cumulation[i] = sum
|
||||
}
|
||||
|
||||
return cumulation
|
||||
})
|
||||
|
||||
let scrollPosition = $state(0)
|
||||
let viewportHeight = $state(0)
|
||||
let visibleItems = $state<{ index: number; offset: number }[]>([])
|
||||
|
||||
$effect.pre(() => {
|
||||
if (virtualListEl) {
|
||||
untrack(() => {
|
||||
visibleItems = updateVisibleItems()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
$effect.pre(() => {
|
||||
if (items.length > itemHeights.length) {
|
||||
const missing = items.length - itemHeights.length
|
||||
itemHeights = [...itemHeights, ...Array(missing).fill(null)]
|
||||
}
|
||||
})
|
||||
|
||||
function findFirstVisibleIndex(
|
||||
scrollTop: number,
|
||||
cumulativeHeights: number[],
|
||||
): number {
|
||||
let low = 0
|
||||
let high = cumulativeHeights.length - 1
|
||||
let mid = 0
|
||||
|
||||
while (low <= high) {
|
||||
mid = Math.floor((low + high) / 2)
|
||||
|
||||
if (cumulativeHeights[mid] <= scrollTop) low = mid + 1
|
||||
else high = mid - 1
|
||||
}
|
||||
|
||||
return low
|
||||
}
|
||||
|
||||
function updateVisibleItems() {
|
||||
if (!virtualListEl) return []
|
||||
|
||||
viewportHeight = innerHeight?.current ?? 1000
|
||||
const scrollTop = scrollPosition - initialOffset
|
||||
|
||||
let newVisibleItems: { index: number; offset: number }[] = []
|
||||
|
||||
const firstIndex = findFirstVisibleIndex(scrollTop, cumulativeItemHeights)
|
||||
|
||||
let i = firstIndex
|
||||
let offset = i == 0 ? 0 : cumulativeItemHeights[i - 1]
|
||||
|
||||
while (i < items.length && offset < scrollTop + viewportHeight + overscan) {
|
||||
newVisibleItems.push({ index: i, offset: offset })
|
||||
const height = itemHeights[i] || estimatedHeight
|
||||
offset += height
|
||||
i++
|
||||
}
|
||||
|
||||
return newVisibleItems ?? []
|
||||
}
|
||||
|
||||
function resizeObserver(node: HTMLElement) {
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const indexAttr = node.getAttribute('data-index')
|
||||
if (indexAttr === null) continue
|
||||
const index = Number(indexAttr)
|
||||
if (isNaN(index)) continue
|
||||
|
||||
const newHeight = entry.contentRect.height
|
||||
if (itemHeights[index] !== newHeight) {
|
||||
itemHeights[index] = newHeight
|
||||
visibleItems = updateVisibleItems()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
observer.observe(node)
|
||||
|
||||
onDestroy(() => {
|
||||
observer.disconnect()
|
||||
})
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
observer.disconnect()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
let oldScroll = $state(0)
|
||||
$effect(() => {
|
||||
if (Math.abs(scrollPosition - oldScroll) > estimatedHeight) {
|
||||
visibleItems = updateVisibleItems()
|
||||
oldScroll = scrollPosition
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:window bind:scrollY={scrollPosition} />
|
||||
|
||||
<div
|
||||
bind:this={virtualListEl}
|
||||
style="position: relative; height: {cumulativeItemHeights[
|
||||
visibleItems?.[visibleItems.length - 1]?.index
|
||||
]}px;"
|
||||
{...rest}
|
||||
id="feed"
|
||||
>
|
||||
<div
|
||||
style="height: {cumulativeItemHeights[visibleItems?.[0]?.index - 1] ||
|
||||
0}px; border: 0 !important;"
|
||||
></div>
|
||||
{#each visibleItems as item (item.index)}
|
||||
<div
|
||||
data-index={item.index}
|
||||
class="post-container fix-divide"
|
||||
use:resizeObserver
|
||||
>
|
||||
{@render itemSnippet(items[item.index], item.index, () => {})}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.fix-divide:nth-child(2) {
|
||||
border-top: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,113 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { Button, Modal, Select, Spinner, TextArea } from 'mono-svelte'
|
||||
import { text } from './translation'
|
||||
import { locale, t } from '$lib/translations'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { ArrowRight, Icon } from 'svelte-hero-icons'
|
||||
import MarkdownEditor from '../markdown/MarkdownEditor.svelte'
|
||||
|
||||
interface TranslateResponse {
|
||||
translatedText: string
|
||||
}
|
||||
|
||||
export let open: boolean = false
|
||||
let error = false
|
||||
|
||||
const opened = () => translate($text)
|
||||
|
||||
$: if (open) opened()
|
||||
|
||||
let result: Promise<TranslateResponse> | undefined = undefined
|
||||
let from = 'auto'
|
||||
let to = $locale
|
||||
|
||||
async function translate(text: string) {
|
||||
const url = $userSettings.translator
|
||||
|
||||
if (!url) {
|
||||
return
|
||||
}
|
||||
|
||||
error = false
|
||||
|
||||
const requestURL = new URL(`https://${url}/translate`)
|
||||
requestURL.searchParams.set('q', text)
|
||||
requestURL.searchParams.set('source', from)
|
||||
requestURL.searchParams.set('target', to)
|
||||
|
||||
result = fetch(requestURL.toString(), {
|
||||
method: 'POST',
|
||||
}).then(async (res) => {
|
||||
if (!res.ok) {
|
||||
error = true
|
||||
throw new Error(`${res.status} ${res.statusText}`)
|
||||
return {
|
||||
translatedText: `${res.status} ${res.statusText}`,
|
||||
}
|
||||
}
|
||||
|
||||
return await res.json()
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal title={$t('post.actions.more.translate')} bind:open>
|
||||
<TextArea bind:value={$text} rows={2}>
|
||||
<Button on:click={() => translate($text)} slot="suffix" color="primary">
|
||||
{$t('post.actions.more.translate')}
|
||||
</Button>
|
||||
</TextArea>
|
||||
<div class="flex items-center gap-2 w-full">
|
||||
<Select bind:value={from} class="flex-1">
|
||||
<option value="auto">Auto</option>
|
||||
</Select>
|
||||
<Icon src={ArrowRight} mini size="20" />
|
||||
<Select on:change={() => translate($text)} bind:value={to} class="flex-1">
|
||||
<option value="en">English</option>
|
||||
<option value="ar">Arabic</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="sv">Swedish</option>
|
||||
</Select>
|
||||
</div>
|
||||
{#if result}
|
||||
{#await result}
|
||||
<div
|
||||
style="height: 226px; width:100%;"
|
||||
class="flex items-center justify-center"
|
||||
>
|
||||
<Spinner width={32} />
|
||||
</div>
|
||||
{:then result}
|
||||
<MarkdownEditor
|
||||
previewButton={false}
|
||||
previewing
|
||||
tools={false}
|
||||
rows={8}
|
||||
value={result.translatedText || 'Failed to translate'}
|
||||
disabled
|
||||
></MarkdownEditor>
|
||||
{:catch err}
|
||||
<MarkdownEditor
|
||||
previewButton={false}
|
||||
previewing
|
||||
tools={false}
|
||||
disabled
|
||||
rows={8}
|
||||
value="Failed to translate: {err}"
|
||||
class="!border-red-500 !ring-red-500 !text-red-500"
|
||||
></MarkdownEditor>
|
||||
{/await}
|
||||
{:else}
|
||||
<TextArea disabled />
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -1,3 +0,0 @@
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
export let text = writable<string>(undefined)
|
||||
@@ -1,21 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { findClosestNumber } from '$lib/util.js'
|
||||
import { findClosestNumber } from '$lib/util.svelte.js'
|
||||
import { createAvatar } from '@dicebear/core'
|
||||
import * as initials from '@dicebear/initials'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
const sizes = [16, 24, 32, 48, 64, 96, 128, 256, 512]
|
||||
|
||||
export let url: string | undefined
|
||||
export let alt: string = ''
|
||||
export let title: string = ''
|
||||
export let circle: boolean = true
|
||||
|
||||
export let width: number
|
||||
export let res: number | undefined = undefined
|
||||
|
||||
const optimizeUrl = (
|
||||
url: string | undefined,
|
||||
res: number
|
||||
res: number,
|
||||
): string | undefined => {
|
||||
if (url === undefined) return
|
||||
|
||||
@@ -25,7 +18,7 @@
|
||||
if (res > -1) {
|
||||
urlObj.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber(sizes, res).toString()
|
||||
findClosestNumber(sizes, res).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,29 +28,53 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: optimizedURLs = [2, 3, 6, -1].map((n) =>
|
||||
optimizeUrl(url, (res || width) * n)
|
||||
interface Props {
|
||||
url: string | undefined
|
||||
alt?: string
|
||||
title?: string
|
||||
circle?: boolean
|
||||
width: number
|
||||
res?: number | undefined
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
url,
|
||||
alt = '',
|
||||
title = '',
|
||||
circle = true,
|
||||
width,
|
||||
res = undefined,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let optimizedURLs = $derived(
|
||||
[2, 3, 6, -1].map((n) => optimizeUrl(url, (res || width) * n)),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if optimizedURLs[0] != undefined}
|
||||
<img
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
loading="lazy"
|
||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||
src={optimizedURLs[0]}
|
||||
{alt}
|
||||
{width}
|
||||
{title}
|
||||
class="aspect-square object-cover overflow-hidden {$$props.class} flex-shrink-0"
|
||||
style="width: {width}px; height: {width}px; {$$props.style || undefined}"
|
||||
class={['aspect-square object-cover overflow-hidden flex-shrink-0', clazz]}
|
||||
style="width: {width}px; height: {width}px; {style}"
|
||||
class:rounded-full={circle}
|
||||
class:rounded-md={!circle}
|
||||
/>
|
||||
{:else}
|
||||
<div
|
||||
style="width: {width}px; height: {width}px;"
|
||||
class="aspect-square object-cover overflow-hidden {$$props.class} flex-shrink-0"
|
||||
class={['aspect-square object-cover overflow-hidden flex-shrink-0', clazz]}
|
||||
class:rounded-full={circle}
|
||||
class:rounded-md={!circle}
|
||||
>
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
action?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { class: clazz = '', children, action }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="flex flex-row items-center
|
||||
text-sm text-slate-600 dark:text-zinc-400 gap-2 flex-wrap {$$props.class ||
|
||||
''}"
|
||||
text-sm text-slate-600 dark:text-zinc-400 gap-2 flex-wrap {clazz}"
|
||||
>
|
||||
<span class="font-medium text-left">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
<hr class="border-slate-200 flex-1 w-full dark:border-zinc-800" />
|
||||
<slot name="action" />
|
||||
{@render action?.()}
|
||||
</div>
|
||||
@@ -1,15 +1,25 @@
|
||||
<script lang="ts">
|
||||
import Avatar from './Avatar.svelte'
|
||||
|
||||
export let name: string
|
||||
export let label: string | undefined = undefined
|
||||
export let icon: string | undefined = undefined
|
||||
interface Props {
|
||||
name: string
|
||||
label?: string | undefined
|
||||
icon?: string | undefined
|
||||
customIcon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
name,
|
||||
label = undefined,
|
||||
icon = undefined,
|
||||
customIcon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<slot name="icon">
|
||||
{#if customIcon}{@render customIcon()}{:else}
|
||||
<Avatar url={icon} width={32} />
|
||||
</slot>
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<span class="font-semibold text-base">{name}</span>
|
||||
<span class="text-sm">{label}</span>
|
||||
|
||||
@@ -5,50 +5,58 @@
|
||||
import LabelStat from './LabelStat.svelte'
|
||||
import { optimizeImageURL } from '../lemmy/post/helpers'
|
||||
import FormattedNumber from '../util/FormattedNumber.svelte'
|
||||
import Expandable from './Expandable.svelte'
|
||||
import { Icon, InformationCircle } from 'svelte-hero-icons'
|
||||
import { t } from '$lib/translations'
|
||||
import Markdown from '../markdown/Markdown.svelte'
|
||||
import EndPlaceholder from './EndPlaceholder.svelte'
|
||||
|
||||
export let avatar: string | undefined = undefined
|
||||
export let name: string
|
||||
export let bio: string | undefined = undefined
|
||||
export let banner: string | undefined = undefined
|
||||
export let url: string | undefined = undefined
|
||||
export let stats: {
|
||||
interface Props {
|
||||
avatar?: string | undefined
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[] = []
|
||||
bio?: string | undefined
|
||||
banner?: string | undefined
|
||||
url?: string | undefined
|
||||
stats?: {
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[]
|
||||
center?: boolean
|
||||
class?: string
|
||||
nameDetail?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let center: boolean = false
|
||||
let {
|
||||
avatar = undefined,
|
||||
name,
|
||||
bio = undefined,
|
||||
banner = undefined,
|
||||
url = undefined,
|
||||
stats = [],
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
nameDetail,
|
||||
actions,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Material
|
||||
color="transparent"
|
||||
padding="none"
|
||||
rounding="xl"
|
||||
{...$$restProps}
|
||||
class="z-10 relative border-slate-200 dark:border-zinc-700 {$$props.class}"
|
||||
>
|
||||
{#if banner || avatar}
|
||||
<div class="max-h-36 overflow-visible">
|
||||
<img
|
||||
src={banner ?? avatar}
|
||||
class="w-full object-cover h-48 rounded-t-xl bg-white dark:bg-zinc-900 banner-mask"
|
||||
class:blur-3xl={!banner}
|
||||
height="192"
|
||||
alt="User banner"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="absolute top-0 left-0 -z-10 object-cover h-full w-full rounded-xl
|
||||
overflow-hidden"
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(banner ?? avatar ?? '', 64)}
|
||||
alt=""
|
||||
class="opacity-10 blur-2xl h-full w-full saturate-200"
|
||||
/>
|
||||
</div>
|
||||
<div {...rest} class="z-10 relative text-sm contents {clazz}">
|
||||
{#if banner}
|
||||
<img
|
||||
src={banner}
|
||||
class="w-full object-cover h-48 rounded-t-xl bg-white dark:bg-zinc-900 rounded-xl"
|
||||
class:blur-3xl={!banner}
|
||||
height="192"
|
||||
alt="User banner"
|
||||
/>
|
||||
{/if}
|
||||
<div class="p-4 flex flex-col gap-4">
|
||||
<div class="py-4 flex flex-col gap-4">
|
||||
<div class="flex-1 flex flex-row items-center text-left gap-4">
|
||||
<Avatar
|
||||
width={64}
|
||||
@@ -60,7 +68,7 @@
|
||||
<svelte:element
|
||||
this={url ? 'a' : 'span'}
|
||||
href={url}
|
||||
class="text-2xl font-semibold {url
|
||||
class="text-xl font-semibold {url
|
||||
? 'hover:underline hover:text-primary-900 hover:dark:text-primary-100'
|
||||
: ''}"
|
||||
>
|
||||
@@ -69,39 +77,59 @@
|
||||
<span
|
||||
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
|
||||
>
|
||||
<slot name="nameDetail" />
|
||||
{@render nameDetail?.()}
|
||||
</span>
|
||||
|
||||
{#if $$slots.actions}
|
||||
{#if actions}
|
||||
<div class="flex flex-col mt-2">
|
||||
<slot name="actions" />
|
||||
{@render actions?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{#if bio}
|
||||
<div class="relative w-full {center ? 'text-center' : 'text-left'}">
|
||||
<div
|
||||
class="p-4 relative bg-white/30 dark:bg-zinc-900/30 border border-slate-300
|
||||
dark:border-zinc-800 border-opacity-50 rounded-xl
|
||||
max-w-full w-full"
|
||||
>
|
||||
<PostBody class="text-sm" view="list" body={bio} clickThrough />
|
||||
</div>
|
||||
<Expandable class="py-2">
|
||||
{#snippet title(open)}
|
||||
{#if bio.split('\n')?.[0]?.startsWith('#') || open}
|
||||
{$t('nav.menu.about')}
|
||||
{:else}
|
||||
<div
|
||||
class={[
|
||||
'overflow-hidden whitespace-nowrap',
|
||||
'bg-gradient-to-r from-slate-700 via-slate-700 to-slate-700/0',
|
||||
'dark:from-zinc-400 dark:via-zinc-400 dark:to-zinc-400/0',
|
||||
'text-transparent bg-clip-text',
|
||||
'max-w-[50%] overflow-hidden',
|
||||
]}
|
||||
>
|
||||
{bio.split('\n')?.[0].slice(0, 75)}
|
||||
</div>
|
||||
{/if}
|
||||
<hr class="flex-1 border-slate-200 dark:border-zinc-800 mx-2" />
|
||||
<div class="mr-2 text-primary-900 dark:text-primary-100">
|
||||
{$t('form.post.readMore')}
|
||||
</div>
|
||||
{/snippet}
|
||||
<Markdown source={bio} class="font-normal" />
|
||||
</Expandable>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="space-y-3 p-4 pt-0">
|
||||
<div class="space-y-3 py-4 pt-0">
|
||||
{#if stats.length > 0}
|
||||
<div class="text-sm flex flex-row flex-wrap gap-3 mx-auto">
|
||||
<div
|
||||
class="text-sm flex flex-row flex-wrap mx-auto rounded-lg
|
||||
overflow-hidden gap-4"
|
||||
>
|
||||
{#each stats as stat}
|
||||
<div
|
||||
class="min-w-36 p-3 px-4 rounded-xl flex-1 bg-white/30 dark:bg-zinc-900/30 border border-slate-300 dark:border-zinc-800 border-opacity-50"
|
||||
>
|
||||
<div class="text-primary-900 dark:text-primary-100">
|
||||
<div class="">
|
||||
<div
|
||||
class="text-primary-900 dark:text-primary-100 text-xs font-medium"
|
||||
>
|
||||
{stat.name}
|
||||
</div>
|
||||
<div class="text-xl font-semibold">
|
||||
<div class="text-lg font-semibold">
|
||||
{#if stat.format ?? true}
|
||||
<FormattedNumber
|
||||
number={Number(stat.value)}
|
||||
@@ -115,9 +143,9 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</Material>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.banner-mask {
|
||||
|
||||
@@ -1,41 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { Disclosure } from 'mono-svelte'
|
||||
import { Minus, Plus, Icon } from 'svelte-hero-icons'
|
||||
export let open: boolean = false
|
||||
export let icon: boolean = true
|
||||
interface Props {
|
||||
open?: boolean
|
||||
icon?: boolean
|
||||
class?: string
|
||||
title?: import('svelte').Snippet<[boolean | undefined]>
|
||||
extended?: import('svelte').Snippet
|
||||
content?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
icon = true,
|
||||
class: clazz = '',
|
||||
title,
|
||||
extended,
|
||||
content,
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Disclosure
|
||||
bind:open
|
||||
class="items-start justify-items-start gap-2 {$$props.class}"
|
||||
>
|
||||
<div
|
||||
slot="summary"
|
||||
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
<slot name="title" />
|
||||
</div>
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={open ? Minus : Plus}
|
||||
size="16"
|
||||
micro
|
||||
class="{open
|
||||
? ''
|
||||
: 'rotate-90'} transition-transform duration-300 ease-out"
|
||||
/>
|
||||
{/if}
|
||||
<Disclosure {extended} bind:open class=" gap-2 {clazz}">
|
||||
{#snippet summary()}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
/>
|
||||
</div>
|
||||
<slot name="extended" slot="extended" />
|
||||
<slot name="content">
|
||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||
<slot />
|
||||
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
{@render title?.(open)}
|
||||
</div>
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={open ? Minus : Plus}
|
||||
size="16"
|
||||
micro
|
||||
class="{open
|
||||
? ''
|
||||
: 'rotate-90'} transition-transform duration-300 ease-out"
|
||||
/>
|
||||
{/if}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
></div>
|
||||
</div>
|
||||
</slot>
|
||||
{/snippet}
|
||||
{#if content}{@render content()}{:else}
|
||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</Disclosure>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { pushState } from '$app/navigation'
|
||||
|
||||
export function showImage(url: string, alt: string = '') {
|
||||
@@ -9,7 +9,7 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores'
|
||||
import { page } from '$app/state'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import {
|
||||
ArrowDownTray,
|
||||
@@ -24,128 +24,81 @@
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
export let alt: string = ''
|
||||
|
||||
let zoomed = false
|
||||
let sharing = false
|
||||
|
||||
async function downloadImage(url: string) {
|
||||
sharing = true
|
||||
const response = await fetch(url)
|
||||
|
||||
const blob = await response.blob()
|
||||
|
||||
const file = new File([blob], `photon_image.webp`, { type: blob.type })
|
||||
|
||||
sharing = false
|
||||
return file
|
||||
interface Props {
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
alt?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { alt = '', class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if $page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-positive-tabindex -->
|
||||
{#if page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||
<div
|
||||
class="fixed top-0 left-0 w-screen h-[100svh] overflow-auto bg-white/50 dark:bg-black/50
|
||||
flex flex-col z-[100] backdrop-blur-sm"
|
||||
transition:fade={{ duration: 150 }}
|
||||
on:click={() => history.back()}
|
||||
on:keydown={(e) => {
|
||||
onclick={() => history.back()}
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') history.back()
|
||||
}}
|
||||
use:focusTrap
|
||||
>
|
||||
<img
|
||||
width={400}
|
||||
height={400}
|
||||
src={$page.state.openImage}
|
||||
class="{zoomed
|
||||
? 'object-cover'
|
||||
: 'object-contain'} max-w-max mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900"
|
||||
class:max-w-screen-md={!zoomed}
|
||||
class:w-full={!zoomed}
|
||||
class:min-h-screen={zoomed}
|
||||
class:min-w-screen={zoomed}
|
||||
class:w-max={zoomed}
|
||||
width={800}
|
||||
height={800}
|
||||
src={page.state.openImage}
|
||||
class={[
|
||||
'max-w-full mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900',
|
||||
]}
|
||||
transition:scale={{ start: 0.95, easing: expoOut, duration: 250 }}
|
||||
{alt}
|
||||
/>
|
||||
<div
|
||||
class="sticky z-10 bottom-4 left-1/2 -translate-x-1/2 w-max"
|
||||
transition:fly={{ duration: 350, y: 14, easing: backOut }}
|
||||
>
|
||||
<div class="sticky z-10 bottom-4 left-1/2 -translate-x-1/2 w-max">
|
||||
<Material
|
||||
class="gap-1 p-2 flex flex-row items-center dark:bg-zinc-950"
|
||||
class="gap-1 p-0.5 px-1 flex flex-row items-center dark:bg-zinc-950/50 border-opacity-50"
|
||||
rounding="full"
|
||||
padding="none"
|
||||
color="uniform"
|
||||
on:click={(e) => e.stopPropagation()}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
download
|
||||
href={$page.state.openImage}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
title={$t('routes.profile.media.download')}
|
||||
>
|
||||
<Icon src={ArrowDownTray} size="20" micro />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={async () => {
|
||||
if (navigator.share) {
|
||||
const file = await downloadImage($page.state.openImage)
|
||||
|
||||
navigator?.share?.({
|
||||
files: [file],
|
||||
})
|
||||
} else {
|
||||
navigator.clipboard.writeText($page.state.openImage)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(page.state.openImage)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
title={$t('post.actions.more.share')}
|
||||
loading={sharing}
|
||||
>
|
||||
<Icon src={Share} size="20" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
zoomed = !zoomed
|
||||
}}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
title={zoomed ? $t('post.image.zoomOut') : $t('post.image.zoomIn')}
|
||||
>
|
||||
<Icon
|
||||
src={zoomed ? MagnifyingGlassMinus : MagnifyingGlassPlus}
|
||||
size="20"
|
||||
micro
|
||||
/>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => history.back()}
|
||||
onclick={() => history.back()}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
title={$t('post.image.close')}
|
||||
>
|
||||
<Icon src={XMark} size="20" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</Material>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button on:click={() => history.back()} class="contents {$$props.class}">
|
||||
<slot />
|
||||
<button onclick={() => history.back()} class="contents {clazz}">
|
||||
{@render children?.()}
|
||||
</button>
|
||||
Loaded 100 of 304 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user