Merge pull request #467 from Xyphyn/svelte-5
Photon v2.0.0: Update to Svelte 5
This commit is contained in:
304 files changed
+10150
-9309
No files matched your search
@@ -4,7 +4,6 @@ about: Create a report to help us improve
|
|||||||
title: ''
|
title: ''
|
||||||
labels: bug
|
labels: bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Describe the bug**
|
**Describe the bug**
|
||||||
@@ -12,6 +11,7 @@ A clear and concise description of what the bug is.
|
|||||||
|
|
||||||
**To Reproduce** (if applicable)
|
**To Reproduce** (if applicable)
|
||||||
Steps to reproduce the behavior:
|
Steps to reproduce the behavior:
|
||||||
|
|
||||||
1. Go to '...'
|
1. Go to '...'
|
||||||
2. Click on '....'
|
2. Click on '....'
|
||||||
3. Scroll down to '....'
|
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.
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
**Versions**
|
**Versions**
|
||||||
|
|
||||||
- Browser: Firefox
|
- Browser: Firefox
|
||||||
- Photon version: 0.5.1
|
- Photon version: 0.5.1
|
||||||
- check in the bottom of the main menu.
|
- check in the bottom of the main menu.
|
||||||
@@ -4,7 +4,6 @@ about: Suggest an idea for this project
|
|||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
**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.localesPaths": ["src/lib/i18n"],
|
||||||
"i18n-ally.keystyle": "nested"
|
"i18n-ally.keystyle": "nested",
|
||||||
|
"prettier.prettierPath": "",
|
||||||
|
"search.searchOnTypeDebouncePeriod": 0
|
||||||
}
|
}
|
||||||
@@ -1,150 +1,78 @@
|
|||||||
# Photon
|
# 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:
|
Jump to:
|
||||||
|
|
||||||
- [Self-hosting](#self-hosting)
|
- [Self-hosting](#self-hosting)
|
||||||
- [Public Instances](#public-instances)
|
- [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
|
## Screenshots
|
||||||
|
|
||||||

|

|
||||||

|
|
||||||
|

|
||||||
|
|
||||||
## Self-hosting
|
## Self-hosting
|
||||||
|
|
||||||
Put Photon on your own domain for easier onboarding.
|
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
|
```sh
|
||||||
# Use the env var PUBLIC_INSTANCE_URL to set the default instance URL.
|
# 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
|
docker run -p 8080:3000 -e PUBLIC_INSTANCE_URL=example.com ghcr.io/xyphyn/photon:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### Running from repo
|
If you'd like to run from a repo, you can:
|
||||||
|
|
||||||
**More unstable but latest features**
|
|
||||||
|
|
||||||
Clone the repo:
|
|
||||||
|
|
||||||
```sh
|
```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
|
### 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_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_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.
|
- `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.
|
||||||
These are the most important environment variables that you can change:
|
- `PUBLIC_THEME`: Export the JSON of a theme made in Photon and set it here to make it the default for all users.
|
||||||
|
|
||||||
| 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 |
|
|
||||||
|
|
||||||
There are more options available that you can see at `src/lib/settings.ts`, by looking at the `defaultSettings` object.
|
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
|
## 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.
|
[phtn.app](https://phtn.app) is the official instance and will get updates instantly.
|
||||||
|
|
||||||
| Instance | Location | Contact |
|
| Instance | Location | Contact |
|
||||||
| --------------------------------------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------- |
|
| ------------------------------------------------------ | ------------ | --------------------------------------------------------- |
|
||||||
| [phtn.app (Official)](https://phtn.app) | 🇺🇸 US West | [photon@xylight.dev](mailto:photon@xylight.dev) |
|
| [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) |
|
| [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.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 | (???) |
|
||||||
| [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) |
|
||||||
| [~~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) |
|
|
||||||
|
|
||||||
## Donate
|
## 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>
|
<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",
|
"name": "photon-lemmy",
|
||||||
"version": "1.31.5",
|
"version": "2.0.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@catdadcode/svelte-adapter-bun": "^0.5.7",
|
"@catdadcode/svelte-adapter-bun": "^0.5.7",
|
||||||
"@dicebear/core": "^8.0.1",
|
"@dicebear/core": "^8.0.1",
|
||||||
"@dicebear/initials": "^8.0.1",
|
"@dicebear/initials": "^8.0.1",
|
||||||
"@sveltejs/adapter-auto": "^3.2.1",
|
"@svelte-put/qr": "^2.0.0",
|
||||||
"@sveltejs/adapter-node": "^2.0.0",
|
"@sveltejs/adapter-auto": "^3.3.1",
|
||||||
"@sveltejs/adapter-vercel": "^5.1.0",
|
"@sveltejs/adapter-node": "^5.2.9",
|
||||||
"@sveltejs/kit": "^2.5.20",
|
"@sveltejs/adapter-vercel": "^5.4.6",
|
||||||
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
"@sveltejs/kit": "^2.17.1",
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
||||||
"@tailwindcss/container-queries": "^0.1.1",
|
"@tailwindcss/container-queries": "^0.1.1",
|
||||||
"@tanstack/svelte-virtual": "^3.8.1",
|
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
"@types/ua-parser-js": "^0.7.39",
|
"@types/ua-parser-js": "^0.7.39",
|
||||||
"autoprefixer": "^10.4.16",
|
"autoprefixer": "^10.4.16",
|
||||||
@@ -22,9 +22,11 @@
|
|||||||
"marked-linkify-it": "^3.1.10",
|
"marked-linkify-it": "^3.1.10",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"postcss": "^8.4.30",
|
"postcss": "^8.4.30",
|
||||||
|
"prettier": "^3.3.3",
|
||||||
|
"prettier-plugin-svelte": "^3.2.7",
|
||||||
"rollup-plugin-visualizer": "^5.9.2",
|
"rollup-plugin-visualizer": "^5.9.2",
|
||||||
"svelte": "^4.2.18",
|
"svelte": "^5.19.7",
|
||||||
"svelte-check": "^3.0.1",
|
"svelte-check": "^4.0.0",
|
||||||
"svelte-floating-ui": "^1.5.9",
|
"svelte-floating-ui": "^1.5.9",
|
||||||
"svelte-focus-trap": "^1.2.0",
|
"svelte-focus-trap": "^1.2.0",
|
||||||
"svelte-hero-icons": "^5.2.0",
|
"svelte-hero-icons": "^5.2.0",
|
||||||
@@ -33,11 +35,14 @@
|
|||||||
"sveltekit-i18n": "^2.4.2",
|
"sveltekit-i18n": "^2.4.2",
|
||||||
"tailwindcss": "^3.3.3",
|
"tailwindcss": "^3.3.3",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.5.0",
|
||||||
"ua-parser-js": "^1.0.38",
|
"ua-parser-js": "^1.0.38",
|
||||||
"vite": "^5.0.0",
|
"vite": "^5.4.14",
|
||||||
"vitest": "^1.0.0"
|
"vitest": "^1.0.0"
|
||||||
},
|
},
|
||||||
|
"overrides": {
|
||||||
|
"svelte": "^5.19.7"
|
||||||
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
@@ -47,11 +52,12 @@
|
|||||||
"start": "node build/index.js",
|
"start": "node build/index.js",
|
||||||
"bunstart": "bun build/index.js",
|
"bunstart": "bun build/index.js",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"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",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@svelte-put/qr": "^1.2.1",
|
|
||||||
"install": "^0.13.0"
|
"install": "^0.13.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// See https://kit.svelte.dev/docs/types#app
|
// 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'
|
import type { ComponentType, SvelteComponent } from 'svelte'
|
||||||
|
|
||||||
// for information about these interfaces
|
// for information about these interfaces
|
||||||
|
|||||||
+15
-14
@@ -27,7 +27,21 @@
|
|||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<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
|
<svg
|
||||||
width="40"
|
width="40"
|
||||||
height="40"
|
height="40"
|
||||||
@@ -73,18 +87,5 @@
|
|||||||
.animate-spin {
|
.animate-spin {
|
||||||
animation: spin 0.9s linear infinite;
|
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>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
@@ -3,10 +3,10 @@ import {
|
|||||||
isAdmin,
|
isAdmin,
|
||||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.svelte.js'
|
||||||
import { client, getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.svelte.js'
|
||||||
import { site } from './lemmy'
|
import { site } from './lemmy.svelte'
|
||||||
import { instanceToURL, moveItem } from '$lib/util.js'
|
import { instanceToURL, moveItem } from '$lib/util.svelte'
|
||||||
import {
|
import {
|
||||||
type GetSiteResponse,
|
type GetSiteResponse,
|
||||||
type MyUserInfo,
|
type MyUserInfo,
|
||||||
@@ -27,7 +27,7 @@ import { t } from './translations'
|
|||||||
|
|
||||||
const getDefaultProfile = (): Profile => ({
|
const getDefaultProfile = (): Profile => ({
|
||||||
id: -1,
|
id: -1,
|
||||||
instance: get(profileData)?.defaultInstance ?? get(instance),
|
instance: profileData.defaultInstance ?? DEFAULT_INSTANCE_URL,
|
||||||
})
|
})
|
||||||
|
|
||||||
function getFromStorage<T>(key: string): T | undefined {
|
function getFromStorage<T>(key: string): T | undefined {
|
||||||
@@ -83,7 +83,7 @@ const getCookie = (key: string): string | undefined => {
|
|||||||
?.split('=')?.[1]
|
?.split('=')?.[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
export let profileData = writable<ProfileData>(
|
export let profileData = $state<ProfileData>(
|
||||||
getFromStorage<ProfileData>('profileData') ?? {
|
getFromStorage<ProfileData>('profileData') ?? {
|
||||||
profiles: [
|
profiles: [
|
||||||
{
|
{
|
||||||
@@ -94,91 +94,57 @@ export let profileData = writable<ProfileData>(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
profile: 1,
|
profile: 1,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
let fetchUser = {
|
class CurrentProfile {
|
||||||
loading: false,
|
#data = $derived(
|
||||||
prevProfile: -1,
|
profileData.profiles.find((i) => i.id == profileData.profile) ??
|
||||||
}
|
getDefaultProfile(),
|
||||||
|
)
|
||||||
|
|
||||||
function profileStore(
|
get data() {
|
||||||
data: Writable<ProfileData>,
|
return this.#data
|
||||||
fn: (
|
}
|
||||||
values: ProfileData,
|
set data(value) {
|
||||||
set: (value: Profile) => void,
|
if (!value) return
|
||||||
update: (fn: Updater<Profile>) => void
|
const index = profileData.profiles.findIndex((i) => i.id == value?.id)
|
||||||
) => any
|
profileData.profiles[index] = value
|
||||||
) {
|
|
||||||
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
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export let profile: Readable<Profile> & { set: (v: Profile) => void } =
|
export let profile = new CurrentProfile()
|
||||||
profileStore(profileData, (pd, set, update) => {
|
|
||||||
const profile =
|
|
||||||
pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile()
|
|
||||||
|
|
||||||
instance.set(profile.instance)
|
async function fetchUserData(profile: CurrentProfile) {
|
||||||
set(profile)
|
if (profile.data.jwt) {
|
||||||
|
site.data = undefined
|
||||||
|
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
||||||
|
|
||||||
if (profile?.jwt) {
|
const res = await userFromJwt(profile.data.jwt, profile.data.instance)
|
||||||
if (profile.id != fetchUser.prevProfile && !fetchUser.loading) {
|
if (!res?.user)
|
||||||
site.set(undefined)
|
toast({
|
||||||
|
content:
|
||||||
|
"Your account's instance did not return your user data. Your login may have expired.",
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
|
||||||
fetchUser.loading = true
|
site.data = res?.site
|
||||||
|
profile.data.user = res?.user
|
||||||
notifications.set({ applications: 0, inbox: 0, reports: 0 })
|
if (profile.data.user) {
|
||||||
|
profile.data.avatar = res?.user?.local_user_view.person.avatar
|
||||||
userFromJwt(profile.jwt, profile.instance)
|
profile.data.username = res?.user?.local_user_view.person.name
|
||||||
.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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
|
if (browser) {
|
||||||
|
site.data = undefined
|
||||||
|
client({ instanceURL: profile.data.instance })
|
||||||
|
.getSite()
|
||||||
|
.then((res) => (site.data = res))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return profile
|
||||||
|
}
|
||||||
|
|
||||||
export let notifications = writable<Notifications>({
|
export let notifications = writable<Notifications>({
|
||||||
applications: 0,
|
applications: 0,
|
||||||
@@ -186,35 +152,37 @@ export let notifications = writable<Notifications>({
|
|||||||
reports: 0,
|
reports: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
profileData.subscribe(async (pd) => {
|
$effect.root(() => {
|
||||||
const serialized: ProfileData = {
|
$effect(() => {
|
||||||
...pd,
|
const serialized = {
|
||||||
profiles: pd.profiles.map((p) => serializeUser(p)),
|
...profileData,
|
||||||
}
|
profiles: profileData.profiles.map((p) => serializeUser(p)),
|
||||||
|
}
|
||||||
|
|
||||||
setFromStorage('profileData', serialized)
|
setFromStorage('profileData', serialized)
|
||||||
|
if (serialized.profiles.length == 0) {
|
||||||
if (serialized.profile == -1) {
|
profileData.profiles = [
|
||||||
instance?.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL)
|
|
||||||
}
|
|
||||||
if (serialized.profiles.length == 0) {
|
|
||||||
profileData.update((pd) => ({
|
|
||||||
...pd,
|
|
||||||
profiles: [
|
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: DEFAULT_INSTANCE_URL,
|
||||||
username: t.get('account.guest') || 'Guest',
|
username: t.get('account.guest') || 'Guest',
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
profile: 1,
|
profileData.profile = 1
|
||||||
}))
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (profile.data.id || profileData)
|
||||||
|
fetchUserData(profile).then((res) => {
|
||||||
|
checkInbox()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (
|
if (
|
||||||
env.PUBLIC_MIGRATE_COOKIE &&
|
env.PUBLIC_MIGRATE_COOKIE &&
|
||||||
get(profileData).profiles.length == 0 &&
|
profileData.profiles.length == 0 &&
|
||||||
env.PUBLIC_INSTANCE_URL
|
env.PUBLIC_INSTANCE_URL
|
||||||
) {
|
) {
|
||||||
const jwt = getCookie('jwt')
|
const jwt = getCookie('jwt')
|
||||||
@@ -226,7 +194,7 @@ if (
|
|||||||
const result = await setUser(
|
const result = await setUser(
|
||||||
jwt,
|
jwt,
|
||||||
env.PUBLIC_INSTANCE_URL ?? '',
|
env.PUBLIC_INSTANCE_URL ?? '',
|
||||||
user?.user?.local_user_view.person.name
|
user?.user?.local_user_view.person.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
@@ -258,24 +226,14 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.set(inst)
|
const id = Math.max(...profileData.profiles.map((p) => p.id)) + 1
|
||||||
|
profileData.profile = id
|
||||||
profileData.update((pd) => {
|
profileData.profiles.push({
|
||||||
// too lazy to make a decent system
|
id: id,
|
||||||
const id = Math.max(...pd.profiles.map((p) => p.id)) + 1
|
instance: inst,
|
||||||
|
jwt: jwt,
|
||||||
const newProfile: Profile = {
|
username: user?.user?.local_user_view.person.name,
|
||||||
id: id,
|
avatar: user?.user?.local_user_view.person.avatar,
|
||||||
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],
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return user
|
return user
|
||||||
@@ -283,7 +241,7 @@ export async function setUser(jwt: string, inst: string, username?: string) {
|
|||||||
|
|
||||||
async function userFromJwt(
|
async function userFromJwt(
|
||||||
jwt: string,
|
jwt: string,
|
||||||
instance: string
|
instance: string,
|
||||||
): Promise<
|
): Promise<
|
||||||
{ user: PersonData | undefined; site: GetSiteResponse } | undefined
|
{ user: PersonData | undefined; site: GetSiteResponse } | undefined
|
||||||
> {
|
> {
|
||||||
@@ -296,7 +254,7 @@ async function userFromJwt(
|
|||||||
type: 'warning',
|
type: 'warning',
|
||||||
loading: true,
|
loading: true,
|
||||||
}),
|
}),
|
||||||
5000
|
5000,
|
||||||
)
|
)
|
||||||
|
|
||||||
const site = await sitePromise
|
const site = await sitePromise
|
||||||
@@ -326,20 +284,15 @@ async function userFromJwt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resetProfile() {
|
export function resetProfile() {
|
||||||
profileData.update((p) => ({ ...p, profile: -1 }))
|
profileData.profile = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteProfile(id: number) {
|
export function deleteProfile(id: number) {
|
||||||
profileData.update((pd) => {
|
profileData.profiles.splice(
|
||||||
const index = pd.profiles.findIndex((p) => p.id == id)
|
profileData.profiles.findIndex((p) => p.id == id),
|
||||||
if (index <= -1) return pd
|
1,
|
||||||
|
)
|
||||||
pd.profiles.splice(index, 1)
|
if (id == profileData.profile) resetProfile()
|
||||||
|
|
||||||
if (id == pd.profile) resetProfile()
|
|
||||||
|
|
||||||
return pd
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeUser(user: Profile): Profile {
|
function serializeUser(user: Profile): Profile {
|
||||||
@@ -350,71 +303,70 @@ function serializeUser(user: Profile): Profile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function setUserID(id: number) {
|
export async function setUserID(id: number) {
|
||||||
profileData.update((p) => ({ ...p, profile: id }))
|
if (!profileData.profiles.find((p) => p.id == id)) return -1
|
||||||
return get(profile)
|
profileData.profile = id
|
||||||
|
return profile
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveProfile(id: number, up: boolean) {
|
export function moveProfile(id: number, up: boolean) {
|
||||||
const pd = get(profileData)
|
|
||||||
try {
|
try {
|
||||||
const index = pd.profiles.findIndex((i) => i.id == id)
|
const index = profileData.profiles.findIndex((i) => i.id == id)
|
||||||
|
profileData.profiles = moveItem(
|
||||||
profileData.set({
|
profileData.profiles,
|
||||||
...pd,
|
index,
|
||||||
profiles: moveItem(pd.profiles, index, index + (up ? -1 : 1)),
|
index + (up ? -1 : 1),
|
||||||
})
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// we dont care
|
// we dont care
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) {
|
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
|
const reportsPromise = mod
|
||||||
let applications: number = 0
|
? 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) {
|
const applicationsPromise = admin
|
||||||
try {
|
? getClient()
|
||||||
const reportRes = await getClient().getReportCount({})
|
.getUnreadRegistrationApplicationCount()
|
||||||
|
.then((res) => res.registration_applications)
|
||||||
|
.catch(() => 0)
|
||||||
|
: new Promise<number>((res) => res(0))
|
||||||
|
|
||||||
reports =
|
const [unreads, reports, applications] = await Promise.all([
|
||||||
reportRes.comment_reports +
|
unreadsPromise,
|
||||||
reportRes.post_reports +
|
reportsPromise,
|
||||||
(reportRes.private_message_reports ?? 0)
|
applicationsPromise,
|
||||||
} catch (e) {
|
])
|
||||||
// doesn't matter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (admin) {
|
|
||||||
try {
|
|
||||||
const applicationRes =
|
|
||||||
await getClient().getUnreadRegistrationApplicationCount()
|
|
||||||
|
|
||||||
applications = applicationRes.registration_applications
|
|
||||||
} catch (e) {
|
|
||||||
// doesn't matter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
unreads: unreads.mentions + unreads.private_messages + unreads.replies,
|
unreads: unreads,
|
||||||
reports: reports,
|
reports: reports,
|
||||||
applications: applications,
|
applications: applications,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkInbox() {
|
async function checkInbox() {
|
||||||
if (!get(profile)) return
|
const { user, jwt } = profile.data
|
||||||
|
|
||||||
const { user, jwt } = get(profile)!
|
|
||||||
if (!jwt || !user) return
|
if (!jwt || !user) return
|
||||||
|
|
||||||
const notifs = await getNotificationCount(
|
const notifs = await getNotificationCount(
|
||||||
jwt,
|
jwt,
|
||||||
amModOfAny(user) ?? false,
|
amModOfAny(user) ?? false,
|
||||||
user ? isAdmin(user) : false
|
user ? isAdmin(user) : false,
|
||||||
)
|
)
|
||||||
|
|
||||||
notifications.set({
|
notifications.set({
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" module>
|
||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
interface PageScopedError {
|
interface PageScopedError {
|
||||||
@@ -6,14 +6,14 @@
|
|||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export let errors = writable<PageScopedError[]>([])
|
let errors = $state<PageScopedError[]>([])
|
||||||
|
|
||||||
export function pushError(args: { scope: string; message: string }) {
|
export function pushError(args: { scope: string; message: string }) {
|
||||||
errors.update((e) => [...e, args])
|
errors.push(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearErrorScope(scope: string | null | undefined) {
|
export function clearErrorScope(scope: string | null | undefined) {
|
||||||
errors.update((errors) => errors.filter((error) => error.scope != scope))
|
errors = errors.filter((error) => error.scope != scope)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -24,20 +24,24 @@
|
|||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { onDestroy } from 'svelte'
|
import { onDestroy } from 'svelte'
|
||||||
|
|
||||||
export let scope: string | undefined | null = undefined
|
|
||||||
|
|
||||||
$: scopedErrors = $errors.filter(
|
|
||||||
(e) => e.scope == scope || e.scope == 'global'
|
|
||||||
)
|
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
clearErrorScope(scope)
|
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>
|
</script>
|
||||||
|
|
||||||
{#if scopedErrors.length > 0}
|
{#if scopedErrors.length > 0}
|
||||||
<div
|
<div
|
||||||
class={$$props.class}
|
class={clazz}
|
||||||
in:slide={{ duration: 400, easing: expoOut }}
|
in:slide={{ duration: 400, easing: expoOut }}
|
||||||
out:slide={{ duration: 400, delay: 400, easing: expoOut }}
|
out:slide={{ duration: 400, delay: 400, easing: expoOut }}
|
||||||
>
|
>
|
||||||
@@ -60,7 +64,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => clearErrorScope(scope)}
|
onclick={() => clearErrorScope(scope)}
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
size="square-sm"
|
size="square-sm"
|
||||||
class="ml-auto"
|
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">
|
<script lang="ts">
|
||||||
|
import { run } from 'svelte/legacy'
|
||||||
|
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { tick } from 'svelte'
|
import { tick } from 'svelte'
|
||||||
|
|
||||||
export let label: string | undefined = undefined
|
let textarea: HTMLTextAreaElement | undefined = $state()
|
||||||
export let value: string
|
|
||||||
export let required: boolean = false
|
|
||||||
|
|
||||||
let textarea: HTMLTextAreaElement
|
|
||||||
|
|
||||||
$: adjustHeight(value)
|
|
||||||
async function adjustHeight(value: string) {
|
async function adjustHeight(value: string) {
|
||||||
await tick()
|
await tick()
|
||||||
if (textarea) {
|
if (textarea) {
|
||||||
@@ -16,6 +13,25 @@
|
|||||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
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>
|
</script>
|
||||||
|
|
||||||
<label class="w-full">
|
<label class="w-full">
|
||||||
@@ -29,11 +45,11 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<textarea
|
<textarea
|
||||||
bind:this={textarea}
|
bind:this={textarea}
|
||||||
on:input={() => adjustHeight(value)}
|
oninput={() => adjustHeight(value)}
|
||||||
bind:value
|
bind:value
|
||||||
{required}
|
{required}
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
rows={1}
|
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>
|
</label>
|
||||||
@@ -1,21 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||||
import { Label, TextInput } from 'mono-svelte'
|
import { Label, TextInput } from 'mono-svelte'
|
||||||
|
|
||||||
export let accept = 'image/*'
|
interface Props {
|
||||||
export let files: FileList | undefined | null = null
|
accept?: string
|
||||||
export let label: string | undefined = undefined
|
files?: FileList | undefined | null
|
||||||
export let url: string | undefined = undefined
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<Label text={label} class="mb-1">
|
<Label text={label} class="mb-1" />
|
||||||
<slot name="label" />
|
|
||||||
</Label>
|
|
||||||
<label
|
<label
|
||||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
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
|
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
||||||
@@ -24,20 +33,20 @@
|
|||||||
: ''}
|
: ''}
|
||||||
{url != undefined ? 'rounded-b-none' : ''}
|
{url != undefined ? 'rounded-b-none' : ''}
|
||||||
"
|
"
|
||||||
on:drop|preventDefault={(event) => (files = event.dataTransfer?.files)}
|
ondrop={preventDefault((event) => (files = event.dataTransfer?.files))}
|
||||||
on:dragover|preventDefault={(event) => {
|
ondragover={preventDefault((event) => {
|
||||||
if (event.dataTransfer) {
|
if (event.dataTransfer) {
|
||||||
event.dataTransfer.dropEffect = 'copy'
|
event.dataTransfer.dropEffect = 'copy'
|
||||||
dragover = true
|
dragover = true
|
||||||
}
|
}
|
||||||
}}
|
})}
|
||||||
on:dragleave|preventDefault={() => (dragover = false)}
|
ondragleave={preventDefault(() => (dragover = false))}
|
||||||
>
|
>
|
||||||
{#if files}
|
{#if files}
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
<!-- svelte-ignore a11y_missing_attribute -->
|
||||||
<img
|
<img
|
||||||
src={previewURL}
|
src={previewURL}
|
||||||
on:load={() => {
|
onload={() => {
|
||||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||||
}}
|
}}
|
||||||
class="w-full max-w-sm h-full rounded-lg"
|
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) => {
|
export const parseURL = (href: string) => {
|
||||||
try {
|
try {
|
||||||
return new URL(href)
|
return new URL(href)
|
||||||
@@ -9,26 +9,42 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let href: string
|
interface Props {
|
||||||
export let highlight: boolean = false
|
href: string
|
||||||
export let nowrap: boolean = false
|
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>
|
</script>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
{href}
|
{href}
|
||||||
class="{highlight
|
class="{highlight
|
||||||
? 'text-blue-500'
|
? '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" />
|
{@render icon?.()}
|
||||||
<slot>
|
{#if children}{@render children()}{:else}
|
||||||
<span
|
<span
|
||||||
class="flex relative gap-0 {nowrap
|
class="flex relative gap-0 {nowrap
|
||||||
? 'w-full whitespace-nowrap overflow-hidden text-ellipsis text-xs'
|
? 'w-full whitespace-nowrap overflow-hidden text-ellipsis text-xs'
|
||||||
: ''} {$$props.class}"
|
: ''} {clazz}"
|
||||||
>
|
>
|
||||||
{#if richURL}
|
{#if richURL}
|
||||||
<span class="text-blue-300 dark:text-blue-800">
|
<span class="text-blue-300 dark:text-blue-800">
|
||||||
@@ -49,5 +65,5 @@
|
|||||||
{href}
|
{href}
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</slot>
|
{/if}
|
||||||
</a>
|
</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">
|
<script lang="ts">
|
||||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
import { run, preventDefault } from 'svelte/legacy'
|
||||||
import { Button } from 'mono-svelte'
|
|
||||||
|
|
||||||
import { createEventDispatcher } from 'svelte'
|
|
||||||
type T = $$Generic
|
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 }>()
|
interface Props {
|
||||||
|
options: T[]
|
||||||
$: {
|
disabled?: boolean[]
|
||||||
dispatcher('select', selected)
|
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 = `
|
let containerClass = `
|
||||||
flex flex-row rtl:flex-row-reverse items-center w-max max-w-full overflow-auto
|
flex flex-row rtl:flex-row-reverse items-center w-max max-w-full overflow-auto
|
||||||
${headless ? 'pb-1 gap-1' : ''}
|
${headless ? 'pb-1 gap-1' : ''}
|
||||||
${$$props.class}
|
${clazz}
|
||||||
`
|
`
|
||||||
|
|
||||||
const buttonClass = (selected: boolean) => `
|
const buttonClass = (selected: boolean) => `
|
||||||
@@ -27,7 +42,7 @@
|
|||||||
last:rounded-r-lg last:border-r last:dark:border-r-transparent
|
last:rounded-r-lg last:border-r last:dark:border-r-transparent
|
||||||
rounded-l-none
|
rounded-l-none
|
||||||
rounded-r-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
|
!selected
|
||||||
? `hover:dark:bg-zinc-800 border-slate-100 border-t border-b border-b-slate-300 dark:border-b-0
|
? `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>
|
</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}
|
{#each options as option, index}
|
||||||
|
{@const slctd = selected == option}
|
||||||
<button
|
<button
|
||||||
class={buttonClass(selected == option)}
|
class={[
|
||||||
on:click|preventDefault={() => (selected = option)}
|
'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}
|
disabled={disabled[index] ?? false}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
{optionNames[index] || option}
|
{optionNames[index] || option}
|
||||||
{#if headless && option == selected}
|
{#if slctd}
|
||||||
<div
|
<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}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<slot {selected} />
|
{@render children?.({ selected })}
|
||||||
@@ -1,21 +1,36 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
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 } from 'lemmy-js-client'
|
import type { Community, CommunityView, ListingType } from 'lemmy-js-client'
|
||||||
import { MenuButton, Search } from 'mono-svelte'
|
import { MenuButton, Search } from 'mono-svelte'
|
||||||
|
import type { SearchProps } from 'mono-svelte/search/Search.svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
|
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
export let type: 'community' | 'instance' = 'community'
|
interface Props {
|
||||||
export let q: string = ''
|
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
|
let {
|
||||||
export let listing_type: ListingType = 'Subscribed'
|
type = 'community',
|
||||||
export let showWhenEmpty: boolean = false
|
q = $bindable(''),
|
||||||
|
instance = undefined,
|
||||||
|
listing_type = 'Subscribed',
|
||||||
|
showWhenEmpty = false,
|
||||||
|
...rest
|
||||||
|
}: Props = $props()
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
||||||
$: instances = type == 'instance' && getClient().getFederatedInstances()
|
let instances = $derived(
|
||||||
|
type == 'instance' && getClient().getFederatedInstances(),
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if type == 'community'}
|
{#if type == 'community'}
|
||||||
@@ -32,36 +47,36 @@
|
|||||||
return results.communities.map((c) => c.community)
|
return results.communities.map((c) => c.community)
|
||||||
}}
|
}}
|
||||||
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
|
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
|
||||||
on:select
|
|
||||||
bind:query={q}
|
bind:query={q}
|
||||||
{showWhenEmpty}
|
{...rest}
|
||||||
{...$$restProps}
|
|
||||||
let:item
|
|
||||||
let:select
|
|
||||||
>
|
>
|
||||||
<div class="w-full h-full" slot="noresults">
|
{#snippet noresults()}
|
||||||
{#if q == '' && showWhenEmpty}
|
<div class="w-full h-full">
|
||||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
{#if q == '' && showWhenEmpty}
|
||||||
<Icon src={XCircle} size="16" mini />
|
<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">
|
<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>
|
</div>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{:else}
|
</div>
|
||||||
<span class="mx-auto my-auto">No results.</span>
|
{/snippet}
|
||||||
{/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>
|
|
||||||
</Search>
|
</Search>
|
||||||
{:else if type == 'instance'}
|
{:else if type == 'instance'}
|
||||||
<Search
|
<Search
|
||||||
@@ -70,36 +85,36 @@
|
|||||||
|
|
||||||
return q
|
return q
|
||||||
? (results.federated_instances?.linked || []).filter(
|
? (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}`}
|
extractName={(i) => `${i.domain}`}
|
||||||
on:select
|
|
||||||
bind:query={q}
|
bind:query={q}
|
||||||
{showWhenEmpty}
|
{...rest}
|
||||||
{...$$restProps}
|
|
||||||
let:item
|
|
||||||
let:select
|
|
||||||
>
|
>
|
||||||
<div class="w-full h-full" slot="noresults">
|
{#snippet noresults()}
|
||||||
{#if q == '' && showWhenEmpty}
|
<div class="w-full h-full">
|
||||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
{#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">
|
<div class="flex flex-col text-left">
|
||||||
<span>None (Start typing to search)</span>
|
<span>{item.domain}</span>
|
||||||
</div>
|
</div>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{:else}
|
</div>
|
||||||
<span class="mx-auto my-auto">No results.</span>
|
{/snippet}
|
||||||
{/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>
|
|
||||||
</Search>
|
</Search>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -19,16 +19,29 @@
|
|||||||
import { userLink } from '$lib/lemmy/generic'
|
import { userLink } from '$lib/lemmy/generic'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Entity from '../ui/Entity.svelte'
|
import Entity from '../ui/Entity.svelte'
|
||||||
import { userSettings } from '$lib/settings'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { optimizeImageURL } from './post/helpers'
|
import { optimizeImageURL } from './post/helpers'
|
||||||
|
import Link from '../input/Link.svelte'
|
||||||
|
import EndPlaceholder from '../ui/EndPlaceholder.svelte'
|
||||||
|
|
||||||
export let site: SiteView
|
interface Props {
|
||||||
export let taglines: Tagline[] | undefined = undefined
|
site: SiteView
|
||||||
export let admins: PersonView[] | undefined = undefined
|
taglines?: Tagline[] | undefined
|
||||||
export let version: string | undefined = undefined
|
admins?: PersonView[] | undefined
|
||||||
|
version?: string | undefined
|
||||||
|
class?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
site,
|
||||||
|
taglines = undefined,
|
||||||
|
admins = undefined,
|
||||||
|
version = undefined,
|
||||||
|
class: clazz = '',
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</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}
|
{#if site.site.banner}
|
||||||
<div
|
<div
|
||||||
class="rounded-xl
|
class="rounded-xl
|
||||||
@@ -43,41 +56,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<Entity name={site.site.name} label={new URL(site.site.actor_id).hostname}>
|
<Entity name={site.site.name} label={new URL(site.site.actor_id).hostname}>
|
||||||
<Avatar
|
{#snippet customIcon()}
|
||||||
width={32}
|
<Avatar
|
||||||
url={site.site.icon}
|
width={32}
|
||||||
alt={site.site.name}
|
url={site.site.icon}
|
||||||
circle={false}
|
alt={site.site.name}
|
||||||
slot="icon"
|
circle={false}
|
||||||
/>
|
/>
|
||||||
|
{/snippet}
|
||||||
</Entity>
|
</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">
|
<div class="flex flex-col gap-1">
|
||||||
{#if taglines && taglines.length > 0}
|
{#if taglines && taglines.length > 0}
|
||||||
@@ -88,22 +75,30 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={$userSettings.expand.about}>
|
<Expandable bind:open={settings.expand.about}>
|
||||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
{#snippet title()}
|
||||||
<Icon src={InformationCircle} size="16" mini />
|
<span class="flex items-center gap-1 py-1 px-2 w-full">
|
||||||
{$t('cards.site.about')}
|
{$t('cards.site.about')}
|
||||||
</span>
|
<hr
|
||||||
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
{/snippet}
|
||||||
<Markdown source={site.site.description} />
|
<Markdown source={site.site.description} />
|
||||||
<div class="my-4" />
|
<div class="my-4"></div>
|
||||||
<Markdown source={site.site.sidebar} />
|
<Markdown source={site.site.sidebar} />
|
||||||
</Expandable>
|
</Expandable>
|
||||||
|
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={$userSettings.expand.stats}>
|
<Expandable bind:open={settings.expand.stats}>
|
||||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
{#snippet title()}
|
||||||
<Icon src={ChartBar} size="16" mini />
|
<span class="flex items-center gap-1 py-1 px-2 w-full">
|
||||||
{$t('cards.site.stats')}
|
{$t('cards.site.stats')}
|
||||||
</span>
|
<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">
|
<div class="flex flex-row gap-4 flex-wrap">
|
||||||
<LabelStat
|
<LabelStat
|
||||||
label={$t('content.users')}
|
label={$t('content.users')}
|
||||||
@@ -125,11 +120,15 @@
|
|||||||
|
|
||||||
{#if admins}
|
{#if admins}
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={$userSettings.expand.team}>
|
<Expandable bind:open={settings.expand.team}>
|
||||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
{#snippet title()}
|
||||||
<Icon src={UserGroup} size="16" mini />
|
<span class="flex items-center gap-1 py-1 px-2 w-full">
|
||||||
{$t('cards.site.admins')}
|
{$t('cards.site.admins')}
|
||||||
</span>
|
<hr
|
||||||
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
{/snippet}
|
||||||
<ItemList
|
<ItemList
|
||||||
items={admins.map((a) => ({
|
items={admins.map((a) => ({
|
||||||
id: a.person.id,
|
id: a.person.id,
|
||||||
@@ -142,9 +141,23 @@
|
|||||||
</Expandable>
|
</Expandable>
|
||||||
{/if}
|
{/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}
|
{#if version}
|
||||||
<div class="w-max">
|
<div class="w-max">
|
||||||
<Badge title="Lemmy version">
|
<Badge label="Lemmy version">
|
||||||
<Icon src={ServerStack} micro size="14" />
|
<Icon src={ServerStack} micro size="14" />
|
||||||
{version}
|
{version}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import {
|
||||||
ArrowUp,
|
|
||||||
Bookmark,
|
Bookmark,
|
||||||
Icon,
|
Icon,
|
||||||
Microphone,
|
Microphone,
|
||||||
@@ -8,46 +7,61 @@
|
|||||||
Pencil,
|
Pencil,
|
||||||
Plus,
|
Plus,
|
||||||
Trash,
|
Trash,
|
||||||
PlusCircle,
|
|
||||||
MinusCircle,
|
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import type { CommentNodeI } from './comments'
|
import type { CommentNodeI } from './comments.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import CommentForm from './CommentForm.svelte'
|
import CommentForm from './CommentForm.svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import CommentActions from '$lib/components/lemmy/comment/CommentActions.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 { 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 { Button, Modal } from 'mono-svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/state'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { fly, slide } from 'svelte/transition'
|
import { fly, slide } from 'svelte/transition'
|
||||||
import { expoInOut, expoOut } from 'svelte/easing'
|
import { expoInOut, expoOut } from 'svelte/easing'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
|
import type { ClassValue } from 'svelte/elements'
|
||||||
|
|
||||||
export let node: CommentNodeI
|
interface Props {
|
||||||
export let postId: number
|
node: CommentNodeI
|
||||||
export let op: boolean = false
|
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
|
let {
|
||||||
export let meta: boolean = true
|
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
|
let editing = $state(false)
|
||||||
|
let newComment = $state(node.comment_view.comment.content)
|
||||||
export let replying = false
|
let editingLoad = $state(false)
|
||||||
|
|
||||||
let editing = false
|
|
||||||
let newComment = node.comment_view.comment.content
|
|
||||||
|
|
||||||
let editingLoad = false
|
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
if (!$profile?.jwt || newComment.length <= 0) return
|
if (!profile.data?.jwt || newComment.length <= 0) return
|
||||||
|
|
||||||
editingLoad = true
|
editingLoad = true
|
||||||
|
|
||||||
@@ -62,8 +76,7 @@
|
|||||||
editing = false
|
editing = false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
// @ts-ignore i hate this
|
content: err as any,
|
||||||
content: err,
|
|
||||||
type: 'error',
|
type: 'error',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -72,7 +85,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
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'
|
highlight = 'text-primary-900 dark:text-primary-100 font-medium'
|
||||||
|
|
||||||
setTimeout(() => (highlight = 'duration-[3s] transition-all'), 500)
|
setTimeout(() => (highlight = 'duration-[3s] transition-all'), 500)
|
||||||
@@ -80,19 +93,27 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let highlight = ''
|
let highlight = $state('')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if editing}
|
{#if editing}
|
||||||
<Modal bind:open={editing}>
|
<Modal bind:open={editing}>
|
||||||
<span slot="title">{$t('form.edit')}</span>
|
{#snippet customTitle()}
|
||||||
<form on:submit|preventDefault={save} class="contents">
|
<span>{$t('form.edit')}</span>
|
||||||
|
{/snippet}
|
||||||
|
<form
|
||||||
|
onsubmit={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
save()
|
||||||
|
}}
|
||||||
|
class="contents"
|
||||||
|
>
|
||||||
<CommentForm
|
<CommentForm
|
||||||
postId={node.comment_view.comment.id}
|
|
||||||
bind:value={newComment}
|
bind:value={newComment}
|
||||||
|
postId={node.comment_view.comment.id}
|
||||||
actions={false}
|
actions={false}
|
||||||
preview={true}
|
preview={true}
|
||||||
on:confirm={save}
|
onconfirm={save}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
submit
|
submit
|
||||||
@@ -111,16 +132,16 @@
|
|||||||
<li
|
<li
|
||||||
class="py-3 relative {node.comment_view.comment.distinguished
|
class="py-3 relative {node.comment_view.comment.distinguished
|
||||||
? ' text-primary-900 dark:text-primary-100'
|
? ' text-primary-900 dark:text-primary-100'
|
||||||
: ''} {highlight} {$$props.class}"
|
: ''} {highlight} {clazz}"
|
||||||
id={node.comment_view.comment.id.toString()}
|
id={node.comment_view.comment.id.toString()}
|
||||||
>
|
>
|
||||||
{#if meta}
|
{#if meta}
|
||||||
<button
|
<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
|
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full
|
||||||
z-0 group relative"
|
z-0 group relative"
|
||||||
>
|
>
|
||||||
<slot name="meta-suffix" />
|
{@render metaSuffix?.()}
|
||||||
<div
|
<div
|
||||||
class="absolute opacity-0 -z-10 inset-0 group-hover:block group-hover:opacity-100
|
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
|
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">
|
<span class:font-bold={op} class="flex flex-row gap-1 items-center">
|
||||||
<UserLink
|
<UserLink
|
||||||
inComment
|
inComment
|
||||||
avatarSize={24}
|
avatarSize={20}
|
||||||
avatar
|
avatar
|
||||||
user={node.comment_view.creator}
|
user={node.comment_view.creator}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="badges">
|
{#snippet extraBadges()}
|
||||||
{#if node.comment_view.creator_is_moderator}
|
{#if node.comment_view.creator_is_moderator}
|
||||||
<ShieldIcon filled width={14} class="text-green-500" />
|
<ShieldIcon filled width={14} class="text-green-500" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if node.comment_view.creator_is_admin}
|
{#if node.comment_view.creator_is_admin}
|
||||||
<ShieldIcon filled width={14} class="text-red-500" />
|
<ShieldIcon filled width={14} class="text-red-500" />
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
</UserLink>
|
</UserLink>
|
||||||
{#if op}
|
{#if op}
|
||||||
<Icon mini size="16" src={Microphone} class="text-sky-600" />
|
<Icon mini size="16" src={Microphone} class="text-sky-600" />
|
||||||
@@ -194,7 +215,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if open}
|
{#if open}
|
||||||
<div
|
<div
|
||||||
class="relative {$$props.contentClass}"
|
class="relative {contentClass}"
|
||||||
transition:slide={{ duration: 400, easing: expoOut }}
|
transition:slide={{ duration: 400, easing: expoOut }}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -205,7 +226,7 @@
|
|||||||
<div
|
<div
|
||||||
class="-z-10 bg-slate-100 dark:bg-zinc-900 absolute -top-9 -bottom-1.5
|
class="-z-10 bg-slate-100 dark:bg-zinc-900 absolute -top-9 -bottom-1.5
|
||||||
-inset-x-6 -right-6"
|
-inset-x-6 -right-6"
|
||||||
/>
|
></div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="max-w-full mt-0.5 break-words text-[15px] text-slate-800 dark:text-zinc-100"
|
class="max-w-full mt-0.5 break-words text-[15px] text-slate-800 dark:text-zinc-100"
|
||||||
@@ -214,9 +235,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{#if actions}
|
{#if actions}
|
||||||
<CommentActions
|
<CommentActions
|
||||||
bind:comment={node.comment_view}
|
comment={node.comment_view}
|
||||||
bind:replying
|
bind:replying
|
||||||
on:edit={() => (editing = true)}
|
onedit={() => (editing = true)}
|
||||||
disabled={node.comment_view.banned_from_community ||
|
disabled={node.comment_view.banned_from_community ||
|
||||||
node.comment_view.post.locked}
|
node.comment_view.post.locked}
|
||||||
/>
|
/>
|
||||||
@@ -232,25 +253,25 @@
|
|||||||
label={$t('comment.reply')}
|
label={$t('comment.reply')}
|
||||||
{postId}
|
{postId}
|
||||||
parentId={node.comment_view.comment.id}
|
parentId={node.comment_view.comment.id}
|
||||||
on:comment={(e) => {
|
oncomment={(e) => {
|
||||||
node.children = [
|
node.children = [
|
||||||
{
|
{
|
||||||
children: [],
|
children: [],
|
||||||
comment_view: e.detail.comment_view,
|
comment_view: e.comment_view,
|
||||||
depth: node.depth + 1,
|
depth: node.depth + 1,
|
||||||
ui: {},
|
expanded: true,
|
||||||
},
|
},
|
||||||
...node.children,
|
...node.children,
|
||||||
]
|
]
|
||||||
replying = false
|
replying = false
|
||||||
}}
|
}}
|
||||||
on:cancel={() => (replying = false)}
|
oncancel={() => (replying = false)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="bg-transparent dark:bg-transparent">
|
<div class="bg-transparent dark:bg-transparent">
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -22,36 +22,35 @@
|
|||||||
report,
|
report,
|
||||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
|
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 { deleteItem, save } from '$lib/lemmy/contentview.js'
|
||||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Translation from '$lib/components/translate/Translation.svelte'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { text } from '$lib/components/translate/translation'
|
|
||||||
import { userSettings } from '$lib/settings'
|
|
||||||
|
|
||||||
export let comment: CommentView
|
interface Props {
|
||||||
export let replying: boolean = false
|
comment: CommentView
|
||||||
export let disabled = false
|
replying?: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
onedit?: (comment: CommentView) => void
|
||||||
|
}
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ edit: CommentView }>()
|
let {
|
||||||
|
comment = $bindable(),
|
||||||
let reply = ''
|
replying = $bindable(false),
|
||||||
let translating = false
|
disabled = false,
|
||||||
|
onedit,
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if translating}
|
|
||||||
<Translation bind:open={translating} />
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex flex-row items-center gap-0.5 h-7 w-full"
|
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
|
<CommentVote
|
||||||
bind:upvotes={comment.counts.upvotes}
|
upvotes={comment.counts.upvotes}
|
||||||
bind:downvotes={comment.counts.downvotes}
|
downvotes={comment.counts.downvotes}
|
||||||
bind:vote={comment.my_vote}
|
vote={comment.my_vote}
|
||||||
commentId={comment.comment.id}
|
commentId={comment.comment.id}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
@@ -59,35 +58,32 @@
|
|||||||
color="tertiary"
|
color="tertiary"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
class="text-slate-700 dark:text-zinc-300"
|
class="text-slate-700 dark:text-zinc-300"
|
||||||
on:click={() => (replying = !replying)}
|
onclick={() => (replying = !replying)}
|
||||||
disabled={comment.post.locked || disabled}
|
disabled={comment.post.locked || disabled}
|
||||||
>
|
>
|
||||||
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
||||||
<span class="text-xs">{$t('comment.reply')}</span>
|
<span class="text-xs">{$t('comment.reply')}</span>
|
||||||
</Button>
|
</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} />
|
<CommentModerationMenu bind:item={comment} />
|
||||||
{/if}
|
{/if}
|
||||||
<Menu placement="bottom">
|
<Menu placement="bottom">
|
||||||
<Button
|
{#snippet target()}
|
||||||
slot="target"
|
<Button
|
||||||
title={$t('comment.actions.label')}
|
title={$t('comment.actions.label')}
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
size="square-sm"
|
size="square-sm"
|
||||||
class="text-slate-700 dark:text-zinc-300"
|
class="text-slate-700 dark:text-zinc-300"
|
||||||
>
|
>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={EllipsisHorizontal}
|
<Icon src={EllipsisHorizontal} width={16} height={16} mini />
|
||||||
width={16}
|
{/snippet}
|
||||||
height={16}
|
</Button>
|
||||||
mini
|
{/snippet}
|
||||||
slot="prefix"
|
|
||||||
/>
|
|
||||||
</Button>
|
|
||||||
<MenuDivider>{$t('comment.actions.label')}</MenuDivider>
|
<MenuDivider>{$t('comment.actions.label')}</MenuDivider>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
navigator.share?.({
|
navigator.share?.({
|
||||||
url: comment.comment.ap_id,
|
url: comment.comment.ap_id,
|
||||||
}) ?? navigator.clipboard.writeText(comment.comment.ap_id)
|
}) ?? navigator.clipboard.writeText(comment.comment.ap_id)
|
||||||
@@ -96,29 +92,21 @@
|
|||||||
<Icon src={Square2Stack} mini size="16" />
|
<Icon src={Square2Stack} mini size="16" />
|
||||||
<div>{$t('comment.actions.link')}</div>
|
<div>{$t('comment.actions.link')}</div>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $userSettings.translator}
|
{#if profile.data?.jwt}
|
||||||
<MenuButton
|
{#if comment.creator.id == profile.data.user?.local_user_view.person.id}
|
||||||
on:click={() => {
|
<MenuButton onclick={() => onedit?.(comment)}>
|
||||||
// @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)}>
|
|
||||||
<Icon src={PencilSquare} mini size="16" />
|
<Icon src={PencilSquare} mini size="16" />
|
||||||
<span>{$t('post.actions.more.edit')}</span>
|
<span>{$t('post.actions.more.edit')}</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if ($profile?.jwt)
|
if (profile.data?.jwt)
|
||||||
comment.saved = await save(comment, !comment.saved, $profile.jwt)
|
comment.saved = await save(
|
||||||
|
comment,
|
||||||
|
!comment.saved,
|
||||||
|
profile.data.jwt,
|
||||||
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
|
||||||
@@ -126,15 +114,15 @@
|
|||||||
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
{comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||||
</span>
|
</span>
|
||||||
</MenuButton>
|
</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
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if ($profile?.jwt)
|
if (profile.data?.jwt)
|
||||||
comment.comment.deleted = await deleteItem(
|
comment.comment.deleted = await deleteItem(
|
||||||
comment,
|
comment,
|
||||||
!comment.comment.deleted,
|
!comment.comment.deleted,
|
||||||
$profile.jwt
|
profile.data.jwt,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -146,13 +134,13 @@
|
|||||||
</span>
|
</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile.jwt && $profile.user?.local_user_view.person.id != comment.creator.id}
|
{#if profile.data.jwt && profile.data.user?.local_user_view.person.id != comment.creator.id}
|
||||||
<MenuButton on:click={() => report(comment)} color="danger-subtle">
|
<MenuButton onclick={() => report(comment)} color="danger-subtle">
|
||||||
<Icon src={Flag} mini size="16" />
|
<Icon src={Flag} mini size="16" />
|
||||||
<span>{$t('moderation.report')}</span>
|
<span>{$t('moderation.report')}</span>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</Menu>
|
</Menu>
|
||||||
<div class="flex-1 w-full" />
|
<div class="flex-1 w-full"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,41 +1,55 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { CommentResponse } from 'lemmy-js-client'
|
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 { createEventDispatcher } from 'svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import { toast } from 'mono-svelte'
|
import { Menu, Select, Spinner, toast, Option, MenuButton } from 'mono-svelte'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.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 { Button } from 'mono-svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
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
|
interface Props {
|
||||||
export let parentId: number | undefined = undefined
|
postId: number
|
||||||
export let locked: boolean = false
|
parentId?: number | undefined
|
||||||
export let banned: boolean = false
|
locked?: boolean
|
||||||
export let rows: number = 7
|
banned?: boolean
|
||||||
export let placeholder: string | undefined = undefined
|
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<{
|
let {
|
||||||
comment: CommentResponse
|
postId,
|
||||||
confirm: string
|
parentId = undefined,
|
||||||
cancel: boolean
|
locked = false,
|
||||||
}>()
|
banned = false,
|
||||||
|
rows = 7,
|
||||||
|
placeholder = undefined,
|
||||||
|
value = $bindable(''),
|
||||||
|
actions = true,
|
||||||
|
preview: previewAction = true,
|
||||||
|
oncancel,
|
||||||
|
oncomment,
|
||||||
|
onconfirm,
|
||||||
|
...rest
|
||||||
|
}: Props = $props()
|
||||||
|
|
||||||
export let value = ''
|
let loading = $state(false)
|
||||||
export let actions = true
|
|
||||||
|
|
||||||
let previewAction = true
|
|
||||||
export { previewAction as preview }
|
|
||||||
|
|
||||||
let loading = false
|
|
||||||
let preview = false
|
let preview = false
|
||||||
|
let language: number | undefined = $state()
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!$profile?.user || !$profile?.jwt || value == '') return
|
if (!profile.data?.user || !profile.data?.jwt || value == '') return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
@@ -45,7 +59,7 @@
|
|||||||
post_id: postId,
|
post_id: postId,
|
||||||
parent_id: parentId,
|
parent_id: parentId,
|
||||||
})
|
})
|
||||||
dispatch('comment', response)
|
oncomment?.(response)
|
||||||
|
|
||||||
value = ''
|
value = ''
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -70,7 +84,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
{rows}
|
{rows}
|
||||||
placeholder={locked
|
placeholder={locked
|
||||||
? $t('comment.locked')
|
? $t('comment.locked')
|
||||||
@@ -79,35 +93,77 @@
|
|||||||
: (placeholder ?? placeholders.get('comment'))}
|
: (placeholder ?? placeholders.get('comment'))}
|
||||||
bind:value
|
bind:value
|
||||||
disabled={locked || loading || banned}
|
disabled={locked || loading || banned}
|
||||||
on:confirm={() => {
|
onconfirm={() => {
|
||||||
if (actions) {
|
if (actions) {
|
||||||
submit()
|
submit()
|
||||||
dispatch('confirm', value)
|
onconfirm?.(value)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:focus
|
|
||||||
previewButton={previewAction}
|
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}
|
{#if actions}
|
||||||
<Button
|
<Button
|
||||||
size="custom"
|
size="custom"
|
||||||
title={$t('common.cancel')}
|
title={$t('common.cancel')}
|
||||||
on:click={() => dispatch('cancel', true)}
|
onclick={() => oncancel?.(true)}
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
class="w-8 h-8"
|
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>
|
||||||
<Button
|
<Button
|
||||||
on:click={submit}
|
onclick={submit}
|
||||||
color="primary"
|
color="primary"
|
||||||
|
rounding="pill"
|
||||||
|
size="custom"
|
||||||
|
class="w-9 h-9"
|
||||||
|
title={$t('form.submit')}
|
||||||
{loading}
|
{loading}
|
||||||
disabled={locked || loading || banned}
|
disabled={locked || loading || banned}
|
||||||
size="lg"
|
|
||||||
>
|
>
|
||||||
{$t('form.submit')}
|
{#snippet prefix()}
|
||||||
|
<Icon src={ArrowUp} size="18" micro />
|
||||||
|
{/snippet}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</MarkdownEditor>
|
</MarkdownEditor>
|
||||||
|
|||||||
@@ -2,28 +2,36 @@
|
|||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import { getInstance } from '$lib/lemmy.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import type { CommentView } from 'lemmy-js-client'
|
import type { CommentView } from 'lemmy-js-client'
|
||||||
import { Button, Material } from 'mono-svelte'
|
import { Button, Material } from 'mono-svelte'
|
||||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let comment: CommentView
|
interface Props {
|
||||||
export let view = $userSettings.view
|
comment: CommentView
|
||||||
export let community = false
|
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>
|
</script>
|
||||||
|
|
||||||
<Material
|
<Material
|
||||||
class="flex flex-col flex-1 {view != 'card'
|
class="flex flex-col flex-1 !bg-transparent !border-0 rounded-none
|
||||||
? '!bg-transparent !border-0 rounded-none'
|
{view == 'compact' ? 'py-4' : 'py-5'} {clazz}"
|
||||||
: 'p-5'} {view == 'list'
|
|
||||||
? 'py-5'
|
|
||||||
: view == 'compact'
|
|
||||||
? 'py-4'
|
|
||||||
: 'py-5'} {$$props.class}"
|
|
||||||
color="distinct"
|
color="distinct"
|
||||||
padding="none"
|
padding="none"
|
||||||
>
|
>
|
||||||
@@ -51,22 +59,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
|
rounding="pill"
|
||||||
|
size="sm"
|
||||||
href="/post/{comment.post.id}?thread={comment.comment.path}#{comment
|
href="/post/{comment.post.id}?thread={comment.comment.path}#{comment
|
||||||
.comment.id}"
|
.comment.id}"
|
||||||
class="self-start"
|
class="self-start"
|
||||||
>
|
>
|
||||||
{$t('common.jump')}
|
{$t('common.jump')}
|
||||||
<Icon src={ArrowUturnUp} size="16" micro />
|
<Icon src={ArrowUturnUp} size="14" micro />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="list-none">
|
<div class="list-none">
|
||||||
<Comment
|
<Comment
|
||||||
postId={comment.post.id}
|
postId={comment.post.id}
|
||||||
node={{ children: [], comment_view: comment, depth: 1, ui: {} }}
|
node={{ children: [], comment_view: comment, depth: 1, expanded: true }}
|
||||||
replying={false}
|
replying={false}
|
||||||
{meta}
|
{meta}
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
|
class={commentClass}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Material>
|
</Material>
|
||||||
@@ -1,35 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import type { CommentNodeI } from './comments'
|
import type { CommentNodeI } from './comments.svelte'
|
||||||
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
|
||||||
import Comments from './Comments.svelte'
|
import Comments from './Comments.svelte'
|
||||||
import { browser } from '$app/environment'
|
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
interface Props {
|
||||||
export let post: Post
|
nodes: CommentNodeI[]
|
||||||
export let scrollTo: string | undefined
|
post: Post
|
||||||
|
scrollTo: string | undefined
|
||||||
|
}
|
||||||
|
|
||||||
let virtualListEl: HTMLElement | undefined = undefined
|
let { nodes, post, scrollTo }: Props = $props()
|
||||||
|
|
||||||
$: virtualizer = createWindowVirtualizer({
|
let offsetEl = $state<HTMLElement>()
|
||||||
count: nodes.length,
|
|
||||||
estimateSize: () => 30,
|
|
||||||
scrollMargin: virtualListEl?.offsetTop,
|
|
||||||
initialRect: {
|
|
||||||
height: 1500,
|
|
||||||
width: 99999,
|
|
||||||
},
|
|
||||||
overscan: 5,
|
|
||||||
})
|
|
||||||
|
|
||||||
let virtualItemEls: HTMLElement[] = []
|
let initialOffset = $state(0)
|
||||||
|
|
||||||
$: items = $virtualizer.getVirtualItems()
|
const updateOffset = (entry: IntersectionObserverEntry) => {
|
||||||
|
if (entry.isIntersecting && offsetEl) {
|
||||||
$: {
|
initialOffset = entry.boundingClientRect.top + window.scrollY
|
||||||
if (virtualItemEls.length)
|
}
|
||||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -39,30 +30,40 @@
|
|||||||
element?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
element?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
}, 100)
|
}, 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>
|
</script>
|
||||||
|
|
||||||
<div
|
<div bind:this={offsetEl}>
|
||||||
style="position:relative; height: {browser
|
<VirtualList
|
||||||
? `${$virtualizer.getTotalSize()}px`
|
class="divide-y divide-slate-200 dark:divide-zinc-800 w-full"
|
||||||
: '100%'}; width: 100%;"
|
overscan={500}
|
||||||
bind:this={virtualListEl}
|
items={nodes}
|
||||||
>
|
{initialOffset}
|
||||||
<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 (row.index)}
|
{#snippet item(item, index)}
|
||||||
<div
|
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
|
||||||
bind:this={virtualItemEls[index]}
|
<Comments
|
||||||
data-index={row.index}
|
isParent={true}
|
||||||
class="-mx-4 sm:-mx-6 px-4 sm:px-6"
|
bind:nodes={() => [nodes[index]], (v) => (nodes[index] = v[0])}
|
||||||
>
|
{post}
|
||||||
<Comments isParent={true} nodes={[nodes[row.index]]} {post} />
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/snippet}
|
||||||
</div>
|
</VirtualList>
|
||||||
</div>
|
</div>
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
ChevronUp,
|
ChevronUp,
|
||||||
Icon,
|
Icon,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { getClient, site } from '$lib/lemmy'
|
import { getClient, site } from '$lib/lemmy.svelte'
|
||||||
import { userSettings } from '$lib/settings'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { Button, buttonColor, toast } from 'mono-svelte'
|
import { Button, buttonColor, toast } from 'mono-svelte'
|
||||||
import { vote as voteItem } from '$lib/lemmy/contentview'
|
import { vote as voteItem } from '$lib/lemmy/contentview'
|
||||||
@@ -18,13 +18,22 @@
|
|||||||
import { backOut } from 'svelte/easing'
|
import { backOut } from 'svelte/easing'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
|
||||||
export let vote: number = 0
|
interface Props {
|
||||||
export let upvotes: number
|
vote?: number
|
||||||
export let downvotes: number
|
upvotes: number
|
||||||
export let commentId: number
|
downvotes: number
|
||||||
|
commentId: number
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
vote = $bindable(0),
|
||||||
|
upvotes = $bindable(),
|
||||||
|
downvotes = $bindable(),
|
||||||
|
commentId,
|
||||||
|
}: Props = $props()
|
||||||
|
|
||||||
const castVote = async (newVote: number) => {
|
const castVote = async (newVote: number) => {
|
||||||
if (!$profile?.jwt) {
|
if (!profile.data?.jwt) {
|
||||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -39,10 +48,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<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
|
<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
|
class="flex items-center gap-0.5 transition-colors px-1.5 h-full
|
||||||
{vote == 1
|
{vote == 1
|
||||||
? shouldShowVoteColor(vote, 'upvotes')
|
? shouldShowVoteColor(vote, 'upvotes')
|
||||||
@@ -65,7 +74,7 @@
|
|||||||
class="border-l h-4 w-0 !p-0 border-slate-200 dark:border-zinc-800"
|
class="border-l h-4 w-0 !p-0 border-slate-200 dark:border-zinc-800"
|
||||||
></div>
|
></div>
|
||||||
<button
|
<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
|
class="flex flex-row-reverse items-center gap-0.5 h-full transition-colors border-0 px-1.5
|
||||||
{vote == -1
|
{vote == -1
|
||||||
? shouldShowVoteColor(vote, 'downvotes')
|
? shouldShowVoteColor(vote, 'downvotes')
|
||||||
|
|||||||
@@ -1,37 +1,35 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import Comments from './Comments.svelte'
|
||||||
import Comment from './Comment.svelte'
|
import Comment from './Comment.svelte'
|
||||||
import { buildCommentsTree, type CommentNodeI } from './comments'
|
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/state'
|
||||||
import { onMount, setContext } from 'svelte'
|
import { onMount, setContext } from 'svelte'
|
||||||
import {
|
import { Icon, ArrowDownCircle } from 'svelte-hero-icons'
|
||||||
ChevronDoubleDown,
|
import { getClient } from '$lib/lemmy.svelte.js'
|
||||||
ChevronDown,
|
|
||||||
Icon,
|
|
||||||
Plus,
|
|
||||||
PlusCircle,
|
|
||||||
ArrowDownCircle,
|
|
||||||
} from 'svelte-hero-icons'
|
|
||||||
import { getClient } from '$lib/lemmy.js'
|
|
||||||
import type { CommentView, Post } from 'lemmy-js-client'
|
import type { CommentView, Post } from 'lemmy-js-client'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import { afterNavigate, goto } from '$app/navigation'
|
import { afterNavigate, goto } from '$app/navigation'
|
||||||
import { backOut, expoOut } from 'svelte/easing'
|
import { backOut, expoOut } from 'svelte/easing'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
|
|
||||||
export let nodes: CommentNodeI[]
|
interface Props {
|
||||||
export let isParent: boolean
|
nodes: CommentNodeI[]
|
||||||
export let post: Post
|
isParent: boolean
|
||||||
|
post: Post
|
||||||
|
}
|
||||||
|
|
||||||
let hydrated = false
|
let { nodes = $bindable(), isParent, post }: Props = $props()
|
||||||
|
|
||||||
|
let hydrated = $state(false)
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
hydrated = true
|
hydrated = true
|
||||||
if (isParent && $page.url.hash && browser) {
|
if (isParent && page.url.hash && browser) {
|
||||||
document.getElementById($page.url.hash)?.scrollIntoView({
|
document.getElementById(page.url.hash)?.scrollIntoView({
|
||||||
behavior: 'smooth',
|
behavior: 'smooth',
|
||||||
block: 'center',
|
block: 'center',
|
||||||
})
|
})
|
||||||
@@ -47,13 +45,14 @@
|
|||||||
parent.comment_view.counts.child_count > 0 &&
|
parent.comment_view.counts.child_count > 0 &&
|
||||||
parent.children.length == 0
|
parent.children.length == 0
|
||||||
)
|
)
|
||||||
)
|
) {
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parent.loading = true
|
parent.loading = true
|
||||||
|
|
||||||
const newComments = await getClient($page.params.instance).getComments({
|
const newComments = await getClient(page.params.instance).getComments({
|
||||||
max_depth: 5,
|
max_depth: 5,
|
||||||
parent_id: parent.comment_view.comment.id,
|
parent_id: parent.comment_view.comment.id,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
@@ -74,7 +73,7 @@
|
|||||||
// 0.18.2 -> 0.18.3 broke this
|
// 0.18.2 -> 0.18.3 broke this
|
||||||
// so i'm adding this check
|
// so i'm adding this check
|
||||||
const treeParent = tree.find(
|
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) {
|
if (treeParent) {
|
||||||
@@ -108,63 +107,66 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul
|
<ul
|
||||||
in:fly={{ duration: 500, easing: expoOut, y: -12 }}
|
in:fly={{ duration: 500, easing: expoOut, y: -12, opacity: 0 }}
|
||||||
class={isParent
|
class={isParent
|
||||||
? 'divide-y dark:divide-zinc-900 divide-slate-100'
|
? 'divide-y dark:divide-zinc-900 divide-slate-100'
|
||||||
: ' border-slate-200 dark:border-zinc-800 my-1'}
|
: ' 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
|
<Comment
|
||||||
postId={post.id}
|
postId={post.id}
|
||||||
bind:node
|
node={nodes[index]}
|
||||||
bind:open={node.ui.open}
|
|
||||||
op={post.creator_id == node.comment_view.creator.id}
|
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
|
node.comment_view.counts.child_count > 0
|
||||||
? 'border-l'
|
? '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}
|
{#if node.children?.length > 0}
|
||||||
<svelte:self {post} bind:nodes={node.children} isParent={false} />
|
<Comments {post} nodes={nodes[index].children} isParent={false} />
|
||||||
{/if}
|
{/if}
|
||||||
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
</Comment>
|
||||||
<svelte:element
|
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
||||||
this={hydrated ? 'div' : 'a'}
|
<svelte:element
|
||||||
class="w-full my-2 h-8"
|
this={hydrated ? 'div' : 'a'}
|
||||||
href="/comment/{$page.params.instance}/{node.comment_view.comment.id}"
|
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
|
{#snippet prefix()}
|
||||||
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))
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Icon
|
<Icon
|
||||||
src={ArrowDownCircle}
|
src={ArrowDownCircle}
|
||||||
micro
|
micro
|
||||||
size="16"
|
size="16"
|
||||||
slot="prefix"
|
|
||||||
class="text-primary-900 dark:text-primary-100"
|
class="text-primary-900 dark:text-primary-100"
|
||||||
/>
|
/>
|
||||||
{$t('comment.more', {
|
{/snippet}
|
||||||
// @ts-ignore
|
{$t('comment.more', {
|
||||||
comments: node.comment_view.counts.child_count,
|
// @ts-ignore
|
||||||
})}
|
comments: node.comment_view.counts.child_count,
|
||||||
</Button>
|
})}
|
||||||
</svelte:element>
|
</Button>
|
||||||
{/if}
|
</svelte:element>
|
||||||
</Comment>
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
+5
-12
@@ -5,9 +5,7 @@ export interface CommentNodeI {
|
|||||||
children: Array<CommentNodeI>
|
children: Array<CommentNodeI>
|
||||||
depth: number
|
depth: number
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
ui: {
|
expanded?: boolean
|
||||||
open?: boolean
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCommentParentId(comment?: Comment): number | undefined {
|
function getCommentParentId(comment?: Comment): number | undefined {
|
||||||
@@ -28,9 +26,8 @@ function getDepthFromComment(comment?: Comment): number | undefined {
|
|||||||
export function buildCommentsTree(
|
export function buildCommentsTree(
|
||||||
comments: CommentView[],
|
comments: CommentView[],
|
||||||
baseDepth: number = 0,
|
baseDepth: number = 0,
|
||||||
filter: (c: CommentView) => boolean = (c) => true
|
filter: (c: CommentView) => boolean = (c) => true,
|
||||||
): CommentNodeI[] {
|
): CommentNodeI[] {
|
||||||
const start = performance.now()
|
|
||||||
const map = new Map<number, CommentNodeI>()
|
const map = new Map<number, CommentNodeI>()
|
||||||
|
|
||||||
let min_depth = Number.MAX_VALUE
|
let min_depth = Number.MAX_VALUE
|
||||||
@@ -41,9 +38,7 @@ export function buildCommentsTree(
|
|||||||
comment_view,
|
comment_view,
|
||||||
children: [],
|
children: [],
|
||||||
depth: depth,
|
depth: depth,
|
||||||
ui: {
|
expanded: true,
|
||||||
open: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
min_depth = Math.min(min_depth, depth)
|
min_depth = Math.min(min_depth, depth)
|
||||||
if (filter(comment_view)) {
|
if (filter(comment_view)) {
|
||||||
@@ -75,13 +70,12 @@ export function buildCommentsTree(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Built tree in ${performance.now() - start}ms`)
|
|
||||||
return tree
|
return tree
|
||||||
}
|
}
|
||||||
|
|
||||||
export function searchCommentTree(
|
export function searchCommentTree(
|
||||||
tree: CommentNodeI[],
|
tree: CommentNodeI[],
|
||||||
id: number
|
id: number,
|
||||||
): CommentNodeI | undefined {
|
): CommentNodeI | undefined {
|
||||||
for (const node of tree) {
|
for (const node of tree) {
|
||||||
if (node.comment_view.comment.id === id) {
|
if (node.comment_view.comment.id === id) {
|
||||||
@@ -102,14 +96,13 @@ export function searchCommentTree(
|
|||||||
export function insertCommentIntoTree(
|
export function insertCommentIntoTree(
|
||||||
tree: CommentNodeI[],
|
tree: CommentNodeI[],
|
||||||
cv: CommentView,
|
cv: CommentView,
|
||||||
parentComment: boolean
|
parentComment: boolean,
|
||||||
) {
|
) {
|
||||||
// Building a fake node to be used for later
|
// Building a fake node to be used for later
|
||||||
const node: CommentNodeI = {
|
const node: CommentNodeI = {
|
||||||
comment_view: cv,
|
comment_view: cv,
|
||||||
children: [],
|
children: [],
|
||||||
depth: 0,
|
depth: 0,
|
||||||
ui: {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentId = getCommentParentId(cv.comment)
|
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) {
|
export async function block(id: number, block: boolean) {
|
||||||
try {
|
try {
|
||||||
const loading = toast({
|
const loading = toast({
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import {
|
import {
|
||||||
amMod,
|
amMod,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
@@ -83,9 +83,9 @@
|
|||||||
modal,
|
modal,
|
||||||
action,
|
action,
|
||||||
} from 'mono-svelte'
|
} 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 { 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 type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
@@ -109,18 +109,15 @@
|
|||||||
import { userLink } from '$lib/lemmy/generic'
|
import { userLink } from '$lib/lemmy/generic'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Entity from '$lib/components/ui/Entity.svelte'
|
import Entity from '$lib/components/ui/Entity.svelte'
|
||||||
import { userSettings } from '$lib/settings'
|
import { settings } from '$lib/settings.svelte'
|
||||||
|
|
||||||
export let community_view: CommunityView
|
let loading = $state({
|
||||||
export let moderators: CommunityModeratorView[] = []
|
|
||||||
|
|
||||||
let loading = {
|
|
||||||
blocking: false,
|
blocking: false,
|
||||||
subscribing: false,
|
subscribing: false,
|
||||||
}
|
})
|
||||||
|
|
||||||
async function subscribe() {
|
async function subscribe() {
|
||||||
if (!$profile?.jwt) return
|
if (!profile.data?.jwt) return
|
||||||
loading.subscribing = true
|
loading.subscribing = true
|
||||||
const subscribed =
|
const subscribed =
|
||||||
community_view.subscribed == 'Subscribed' ||
|
community_view.subscribed == 'Subscribed' ||
|
||||||
@@ -140,43 +137,61 @@
|
|||||||
|
|
||||||
loading.subscribing = false
|
loading.subscribing = false
|
||||||
}
|
}
|
||||||
|
interface Props {
|
||||||
|
community_view: CommunityView
|
||||||
|
moderators?: CommunityModeratorView[]
|
||||||
|
class?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
community_view = $bindable(),
|
||||||
|
moderators = [],
|
||||||
|
class: clazz = '',
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<StickyCard
|
<StickyCard class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {clazz}">
|
||||||
class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {$$props.class}"
|
|
||||||
>
|
|
||||||
<Entity
|
<Entity
|
||||||
name={community_view.community.title}
|
name={community_view.community.title}
|
||||||
label="!{fullCommunityName(
|
label="!{fullCommunityName(
|
||||||
community_view.community.name,
|
community_view.community.name,
|
||||||
community_view.community.actor_id
|
community_view.community.actor_id,
|
||||||
)}"
|
)}"
|
||||||
>
|
>
|
||||||
<Avatar
|
{#snippet customIcon()}
|
||||||
width={32}
|
<Avatar
|
||||||
url={community_view.community.icon}
|
width={32}
|
||||||
alt={community_view.community.name}
|
url={community_view.community.icon}
|
||||||
circle={false}
|
alt={community_view.community.name}
|
||||||
slot="icon"
|
circle={false}
|
||||||
/>
|
/>
|
||||||
|
{/snippet}
|
||||||
</Entity>
|
</Entity>
|
||||||
|
|
||||||
<div class="flex flex-col gap-1">
|
<div class="flex flex-col gap-1">
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={$userSettings.expand.about} class="!pt-0">
|
<Expandable bind:open={settings.expand.about} class="!pt-0">
|
||||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
{#snippet title()}
|
||||||
<Icon src={InformationCircle} size="15" mini />
|
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||||
{$t('cards.site.about')}
|
{$t('cards.site.about')}
|
||||||
</span>
|
<hr
|
||||||
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
{/snippet}
|
||||||
<Markdown source={community_view.community.description} />
|
<Markdown source={community_view.community.description} />
|
||||||
</Expandable>
|
</Expandable>
|
||||||
|
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={$userSettings.expand.stats}>
|
<Expandable bind:open={settings.expand.stats}>
|
||||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
{#snippet title()}
|
||||||
<Icon src={ChartBar} size="15" mini />
|
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||||
{$t('cards.site.stats')}
|
{$t('cards.site.stats')}
|
||||||
</span>
|
<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">
|
<div class="flex flex-row gap-4 flex-wrap">
|
||||||
<LabelStat
|
<LabelStat
|
||||||
label={$t('cards.community.members')}
|
label={$t('cards.community.members')}
|
||||||
@@ -193,11 +208,16 @@
|
|||||||
|
|
||||||
{#if moderators && moderators.length > 0}
|
{#if moderators && moderators.length > 0}
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||||
<Expandable bind:open={$userSettings.expand.team}>
|
<Expandable bind:open={settings.expand.team}>
|
||||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
{#snippet title()}
|
||||||
<ShieldIcon width={15} filled />
|
<span class="py-1 px-1 flex gap-1 items-center w-full">
|
||||||
{$t('cards.community.moderators')}
|
{$t('cards.community.moderators')}
|
||||||
</span>
|
|
||||||
|
<hr
|
||||||
|
class="w-full flex-1 ml-1 border-slate-200 dark:border-zinc-800"
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
{/snippet}
|
||||||
<ItemList
|
<ItemList
|
||||||
items={moderators.map((m) => ({
|
items={moderators.map((m) => ({
|
||||||
id: m.moderator.id,
|
id: m.moderator.id,
|
||||||
@@ -213,74 +233,86 @@
|
|||||||
<div
|
<div
|
||||||
class="flex flex-row items-center gap-1 sticky bottom-0 drop-shadow-xl w-full"
|
class="flex flex-row items-center gap-1 sticky bottom-0 drop-shadow-xl w-full"
|
||||||
>
|
>
|
||||||
{#if $profile?.jwt}
|
{#if profile.data?.jwt}
|
||||||
<Button
|
<Button
|
||||||
disabled={loading.subscribing}
|
disabled={loading.subscribing}
|
||||||
loading={loading.subscribing}
|
loading={loading.subscribing}
|
||||||
size="md"
|
size="md"
|
||||||
|
rounding="xl"
|
||||||
color={community_view.subscribed == 'Subscribed'
|
color={community_view.subscribed == 'Subscribed'
|
||||||
? 'secondary'
|
? 'secondary'
|
||||||
: 'primary'}
|
: 'primary'}
|
||||||
on:click={subscribe}
|
onclick={subscribe}
|
||||||
class="flex-1 relative z-[inherit]"
|
class="px-5 relative z-[inherit]"
|
||||||
>
|
>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
<Icon
|
||||||
mini
|
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||||
size="16"
|
mini
|
||||||
slot="prefix"
|
size="16"
|
||||||
/>
|
/>
|
||||||
|
{/snippet}
|
||||||
{community_view.subscribed == 'Subscribed' ||
|
{community_view.subscribed == 'Subscribed' ||
|
||||||
community_view.subscribed == 'Pending'
|
community_view.subscribed == 'Pending'
|
||||||
? $t('cards.community.subscribed')
|
? $t('cards.community.subscribed')
|
||||||
: $t('cards.community.subscribe')}
|
: $t('cards.community.subscribe')}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile?.user && amMod($profile.user, community_view.community)}
|
{#if profile.data?.user && amMod(profile.data.user, community_view.community)}
|
||||||
<Button
|
<Button
|
||||||
href="/c/{fullCommunityName(
|
href="/c/{fullCommunityName(
|
||||||
community_view.community.name,
|
community_view.community.name,
|
||||||
community_view.community.actor_id
|
community_view.community.actor_id,
|
||||||
)}/settings"
|
)}/settings"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={Cog6Tooth} mini size="16" slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Cog6Tooth} mini size="16" />
|
||||||
|
{/snippet}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<Menu placement="top-end">
|
<Menu placement="top-end">
|
||||||
<Button size="square-md" slot="target" class="ml-auto">
|
{#snippet target()}
|
||||||
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
<Button size="square-md">
|
||||||
</Button>
|
{#snippet prefix()}
|
||||||
|
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
<MenuButton href="/modlog?community={community_view.community.id}">
|
<MenuButton href="/modlog?community={community_view.community.id}">
|
||||||
<Icon src={Newspaper} size="16" mini />
|
<Icon src={Newspaper} size="16" mini />
|
||||||
{$t('cards.community.modlog')}
|
{$t('cards.community.modlog')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile?.jwt}
|
{#if profile.data?.jwt}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
size="lg"
|
size="lg"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
block(community_view.community.id, !community_view.blocked)}
|
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
|
{community_view.blocked
|
||||||
? $t('cards.community.unblock')
|
? $t('cards.community.unblock')
|
||||||
: $t('cards.community.block')}
|
: $t('cards.community.block')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile?.user}
|
{#if profile.data?.user}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
size="lg"
|
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')}
|
{$t('cards.community.blockInstance')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile?.user && isAdmin($profile.user)}
|
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
modal({
|
modal({
|
||||||
title: $t('admin.purgeCommunity.title'),
|
title: $t('admin.purgeCommunity.title'),
|
||||||
body: `${community_view.community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
body: `${community_view.community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
||||||
@@ -301,7 +333,9 @@
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Fire} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
{$t('admin.purge')}
|
{$t('admin.purge')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,47 +1,65 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import { goto } from '$app/navigation'
|
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 MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { ImageInput, Switch, toast } from 'mono-svelte'
|
import { Badge, ImageInput, MenuButton, Switch, toast } from 'mono-svelte'
|
||||||
import { client, getClient } from '$lib/lemmy.js'
|
import { client, getClient, site } from '$lib/lemmy.svelte.js'
|
||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import { Button, Checkbox, TextInput } from 'mono-svelte'
|
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 { t } from '$lib/translations'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
|
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
|
||||||
import Label from 'mono-svelte/forms/Label.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 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'
|
||||||
|
|
||||||
/**
|
interface Props {
|
||||||
* The community ID to edit.
|
/**
|
||||||
*/
|
* The community ID to edit.
|
||||||
export let edit: number | undefined = undefined
|
*/
|
||||||
|
edit?: number
|
||||||
export let formData: {
|
formData?: {
|
||||||
name: string
|
name: string
|
||||||
displayName: string
|
displayName: string
|
||||||
icon?: string
|
icon?: string
|
||||||
banner?: string
|
banner?: string
|
||||||
sidebar?: string
|
sidebar?: string
|
||||||
nsfw: boolean
|
nsfw: boolean
|
||||||
postsLockedToModerators: boolean
|
postsLockedToModerators: boolean
|
||||||
submitting: boolean
|
submitting: boolean
|
||||||
visibility: 'Public' | 'LocalOnly'
|
visibility: 'Public' | 'LocalOnly'
|
||||||
} = {
|
languages?: number[]
|
||||||
name: '',
|
}
|
||||||
displayName: '',
|
formtitle?: import('svelte').Snippet
|
||||||
sidebar: '',
|
|
||||||
nsfw: false,
|
|
||||||
postsLockedToModerators: false,
|
|
||||||
submitting: false,
|
|
||||||
visibility: 'Public',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
async function submit() {
|
||||||
if (!$profile?.jwt) return
|
if (!profile.data?.jwt) return
|
||||||
if ((!edit && formData.name == '') || formData.displayName == '') return
|
if ((!edit && formData.name == '') || formData.displayName == '') return
|
||||||
|
|
||||||
formData.submitting = true
|
formData.submitting = true
|
||||||
@@ -57,6 +75,7 @@
|
|||||||
banner: formData.banner,
|
banner: formData.banner,
|
||||||
community_id: edit,
|
community_id: edit,
|
||||||
visibility: formData.visibility,
|
visibility: formData.visibility,
|
||||||
|
discussion_languages: formData.languages,
|
||||||
})
|
})
|
||||||
: await getClient().createCommunity({
|
: await getClient().createCommunity({
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
@@ -67,6 +86,7 @@
|
|||||||
icon: formData.icon,
|
icon: formData.icon,
|
||||||
banner: formData.banner,
|
banner: formData.banner,
|
||||||
visibility: formData.visibility,
|
visibility: formData.visibility,
|
||||||
|
discussion_languages: formData.languages,
|
||||||
})
|
})
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
@@ -74,23 +94,23 @@
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
if ($profile.user) {
|
if (profile.data.user) {
|
||||||
const c = $profile.user.moderates
|
const c = profile.data.user.moderates
|
||||||
.map((m) => m.community.id)
|
.map((m) => m.community.id)
|
||||||
.indexOf(res.community_view.community.id)
|
.indexOf(res.community_view.community.id)
|
||||||
if (c != -1) {
|
if (c != -1) {
|
||||||
$profile.user.moderates[c] = {
|
profile.data.user.moderates[c] = {
|
||||||
community: res.community_view.community,
|
community: res.community_view.community,
|
||||||
moderator: $profile.user.local_user_view.person,
|
moderator: profile.data.user.local_user_view.person,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$profile.user = {
|
profile.data.user = {
|
||||||
...$profile.user,
|
...profile.data.user,
|
||||||
moderates: [
|
moderates: [
|
||||||
...$profile.user.moderates,
|
...profile.data.user.moderates,
|
||||||
{
|
{
|
||||||
community: res.community_view.community,
|
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(
|
goto(
|
||||||
`/c/${res.community_view.community.name}@${
|
`/c/${res.community_view.community.name}@${
|
||||||
new URL(res.community_view.community.actor_id).hostname
|
new URL(res.community_view.community.actor_id).hostname
|
||||||
}`
|
}`,
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast({
|
toast({
|
||||||
@@ -115,24 +135,24 @@
|
|||||||
formData.submitting = false
|
formData.submitting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
let uploading = {
|
let uploading = $state({
|
||||||
banner: false,
|
banner: false,
|
||||||
icon: false,
|
icon: false,
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
on:submit|preventDefault={submit}
|
onsubmit={preventDefault(submit)}
|
||||||
class="flex flex-col gap-4 h-full w-full"
|
class="flex flex-col gap-4 h-full w-full"
|
||||||
>
|
>
|
||||||
<slot name="formtitle">
|
{#if formtitle}{@render formtitle()}{:else}
|
||||||
<Header>{$t('routes.createCommunity')}</Header>
|
<Header>{$t('routes.createCommunity')}</Header>
|
||||||
</slot>
|
{/if}
|
||||||
<TextInput
|
<TextInput
|
||||||
required
|
required
|
||||||
label={$t('form.name')}
|
label={$t('form.name')}
|
||||||
bind:value={formData.name}
|
bind:value={formData.name}
|
||||||
on:input={() => {
|
oninput={() => {
|
||||||
formData.name = formData.name.toLowerCase().replaceAll(' ', '_')
|
formData.name = formData.name.toLowerCase().replaceAll(' ', '_')
|
||||||
}}
|
}}
|
||||||
disabled={edit != undefined}
|
disabled={edit != undefined}
|
||||||
@@ -147,7 +167,7 @@
|
|||||||
<Label>{$t('routes.admin.config.icon')}</Label>
|
<Label>{$t('routes.admin.config.icon')}</Label>
|
||||||
<button
|
<button
|
||||||
type="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"
|
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}
|
{#if formData.icon}
|
||||||
@@ -164,9 +184,9 @@
|
|||||||
<ImageUploadModal
|
<ImageUploadModal
|
||||||
bind:open={uploading.icon}
|
bind:open={uploading.icon}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
on:upload={(uploaded) => {
|
onupload={(uploaded) => {
|
||||||
uploading.icon = false
|
uploading.icon = false
|
||||||
formData.icon = uploaded.detail[0]
|
formData.icon = uploaded[0]
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -175,7 +195,7 @@
|
|||||||
<Label>{$t('routes.admin.config.banner')}</Label>
|
<Label>{$t('routes.admin.config.banner')}</Label>
|
||||||
<button
|
<button
|
||||||
type="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"
|
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}
|
{#if formData.banner}
|
||||||
@@ -192,9 +212,9 @@
|
|||||||
<ImageUploadModal
|
<ImageUploadModal
|
||||||
bind:open={uploading.banner}
|
bind:open={uploading.banner}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
on:upload={(uploaded) => {
|
onupload={(uploaded) => {
|
||||||
uploading.banner = false
|
uploading.banner = false
|
||||||
formData.banner = uploaded.detail[0]
|
formData.banner = uploaded[0]
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -211,9 +231,57 @@
|
|||||||
Only moderators can post
|
Only moderators can post
|
||||||
</Switch>
|
</Switch>
|
||||||
<Select label="Visibility" class="w-max" bind:value={formData.visibility}>
|
<Select label="Visibility" class="w-max" bind:value={formData.visibility}>
|
||||||
<option value="Public">Public</option>
|
<Option icon={GlobeAlt} value="Public">Public</Option>
|
||||||
<option value="LocalOnly">Local Only</option>
|
<Option icon={MapPin} value="LocalOnly">Local Only</Option>
|
||||||
</Select>
|
</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
|
<Button
|
||||||
submit
|
submit
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile } from '$lib/auth'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { fullCommunityName } from '$lib/util'
|
import { fullCommunityName } from '$lib/util.svelte'
|
||||||
import type {
|
import type {
|
||||||
Community,
|
Community,
|
||||||
CommunityAggregates,
|
CommunityAggregates,
|
||||||
@@ -30,16 +30,29 @@
|
|||||||
import { publishedToDate } from '$lib/components/util/date'
|
import { publishedToDate } from '$lib/components/util/date'
|
||||||
import { isAdmin } from '../moderation/moderation'
|
import { isAdmin } from '../moderation/moderation'
|
||||||
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
||||||
|
import { settings } from '$lib/settings.svelte'
|
||||||
|
|
||||||
export let community: Community
|
interface Props {
|
||||||
export let subscribed: SubscribedType
|
community: Community
|
||||||
export let counts: CommunityAggregates | undefined = undefined
|
subscribed: SubscribedType
|
||||||
export let moderators: CommunityModeratorView[] = []
|
counts?: CommunityAggregates | undefined
|
||||||
export let blocked: boolean = false
|
moderators?: CommunityModeratorView[]
|
||||||
|
blocked?: boolean
|
||||||
|
class?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
community = $bindable(),
|
||||||
|
subscribed = $bindable(),
|
||||||
|
counts = undefined,
|
||||||
|
moderators = [],
|
||||||
|
blocked = false,
|
||||||
|
class: clazz = '',
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<EntityHeader
|
<EntityHeader
|
||||||
banner={community.banner}
|
banner={settings.nsfwBlur && community.nsfw ? undefined : community.banner}
|
||||||
avatar={community.icon}
|
avatar={community.icon}
|
||||||
name={community.title}
|
name={community.title}
|
||||||
url="/c/{fullCommunityName(community.name, community.actor_id)}"
|
url="/c/{fullCommunityName(community.name, community.actor_id)}"
|
||||||
@@ -67,29 +80,27 @@
|
|||||||
]
|
]
|
||||||
: []}
|
: []}
|
||||||
bio={community.description}
|
bio={community.description}
|
||||||
class={$$props.class}
|
class={clazz}
|
||||||
>
|
>
|
||||||
<button
|
{#snippet nameDetail()}
|
||||||
on:click={() => {
|
<button
|
||||||
navigator?.clipboard?.writeText?.(
|
onclick={() => {
|
||||||
`!${fullCommunityName(community.name, community.actor_id)}`
|
navigator?.clipboard?.writeText?.(
|
||||||
)
|
`!${fullCommunityName(community.name, community.actor_id)}`,
|
||||||
toast({ content: $t('toast.copied') })
|
)
|
||||||
}}
|
toast({ content: $t('toast.copied') })
|
||||||
class="text-sm flex gap-0 items-center"
|
}}
|
||||||
slot="nameDetail"
|
class="text-sm flex gap-0 items-center"
|
||||||
>
|
|
||||||
!{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"
|
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="title">
|
!{fullCommunityName(community.name, community.actor_id)}
|
||||||
<ShieldIcon width={15} filled />
|
</button>
|
||||||
|
{/snippet}
|
||||||
|
{#if moderators.length > 0}
|
||||||
|
<Expandable class="">
|
||||||
|
{#snippet title()}
|
||||||
{$t('cards.community.moderators')}
|
{$t('cards.community.moderators')}
|
||||||
</svelte:fragment>
|
<hr class="flex-1 border-slate-200 dark:border-zinc-800 mx-3" />
|
||||||
|
{/snippet}
|
||||||
<ItemList
|
<ItemList
|
||||||
items={moderators.map((m) => ({
|
items={moderators.map((m) => ({
|
||||||
id: m.moderator.id,
|
id: m.moderator.id,
|
||||||
@@ -101,8 +112,8 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
|||||||
/>
|
/>
|
||||||
</Expandable>
|
</Expandable>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex items-center gap-2 h-max">
|
<div class="flex items-center gap-2 h-max w-max">
|
||||||
{#if $profile?.jwt}
|
{#if profile.data?.jwt}
|
||||||
<Subscribe
|
<Subscribe
|
||||||
community={{
|
community={{
|
||||||
community: community,
|
community: community,
|
||||||
@@ -112,34 +123,36 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
|||||||
counts: counts ?? {},
|
counts: counts ?? {},
|
||||||
subscribed: subscribed,
|
subscribed: subscribed,
|
||||||
}}
|
}}
|
||||||
let:subscribe
|
|
||||||
let:subscribing
|
|
||||||
>
|
>
|
||||||
<Button
|
{#snippet children({ subscribe, subscribing })}
|
||||||
disabled={subscribing}
|
<Button
|
||||||
loading={subscribing}
|
disabled={subscribing}
|
||||||
size="lg"
|
loading={subscribing}
|
||||||
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
size="lg"
|
||||||
on:click={async () => {
|
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
||||||
subscribed =
|
onclick={async () => {
|
||||||
(await subscribe())?.community_view.subscribed ?? 'NotSubscribed'
|
subscribed =
|
||||||
}}
|
(await subscribe())?.community_view.subscribed ??
|
||||||
class="flex-1 relative z-[inherit]"
|
'NotSubscribed'
|
||||||
>
|
}}
|
||||||
<Icon
|
class="relative px-8 z-[inherit]"
|
||||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
>
|
||||||
micro
|
{#snippet prefix()}
|
||||||
size="16"
|
<Icon
|
||||||
slot="prefix"
|
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||||
/>
|
micro
|
||||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
size="16"
|
||||||
? $t('cards.community.subscribed')
|
/>
|
||||||
: $t('cards.community.subscribe')}
|
{/snippet}
|
||||||
</Button>
|
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||||
|
? $t('cards.community.subscribed')
|
||||||
|
: $t('cards.community.subscribe')}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
</Subscribe>
|
</Subscribe>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $profile?.user && $profile.user.moderates
|
{#if profile.data?.user && profile.data.user.moderates
|
||||||
.map((c) => c.community.id)
|
.map((c) => c.community.id)
|
||||||
.includes(community.id)}
|
.includes(community.id)}
|
||||||
<Button
|
<Button
|
||||||
@@ -148,7 +161,7 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
|||||||
rounding="xl"
|
rounding="xl"
|
||||||
href="/c/{fullCommunityName(
|
href="/c/{fullCommunityName(
|
||||||
community.name,
|
community.name,
|
||||||
community.actor_id
|
community.actor_id,
|
||||||
)}/settings"
|
)}/settings"
|
||||||
style="height: 38px; width: 38px;"
|
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>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<Menu placement="top-end">
|
<Menu placement="top-end">
|
||||||
<Button
|
{#snippet target()}
|
||||||
rounding="xl"
|
<Button rounding="xl" size="custom" style="height: 38px; width: 38px;">
|
||||||
size="custom"
|
{#snippet prefix()}
|
||||||
slot="target"
|
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||||
style="height: 38px; width: 38px;"
|
{/snippet}
|
||||||
>
|
</Button>
|
||||||
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
{/snippet}
|
||||||
</Button>
|
|
||||||
<MenuButton href="/modlog?community={community.id}">
|
<MenuButton href="/modlog?community={community.id}">
|
||||||
<Icon src={Newspaper} size="16" mini />
|
<Icon src={Newspaper} size="16" mini />
|
||||||
{$t('cards.community.modlog')}
|
{$t('cards.community.modlog')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile?.jwt}
|
{#if profile.data?.jwt}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
size="lg"
|
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
|
{blocked
|
||||||
? $t('cards.community.unblock')
|
? $t('cards.community.unblock')
|
||||||
: $t('cards.community.block')}
|
: $t('cards.community.block')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile?.user}
|
{#if profile.data?.user}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
size="lg"
|
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')}
|
{$t('cards.community.blockInstance')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile?.user && isAdmin($profile.user)}
|
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
modal({
|
modal({
|
||||||
title: $t('admin.purgeCommunity.title'),
|
title: $t('admin.purgeCommunity.title'),
|
||||||
body: `${community.title}: ${$t('admin.purgeCommunity.warning')}`,
|
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',
|
type: 'error',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Fire} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
{$t('admin.purge')}
|
{$t('admin.purge')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -5,16 +5,20 @@
|
|||||||
import {
|
import {
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
Check,
|
Check,
|
||||||
|
ExclamationTriangle,
|
||||||
Icon,
|
Icon,
|
||||||
InformationCircle,
|
InformationCircle,
|
||||||
|
MapPin,
|
||||||
|
NoSymbol,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
Plus,
|
Plus,
|
||||||
|
Trash,
|
||||||
UserGroup,
|
UserGroup,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
import { fullCommunityName, isSubscribed } from '$lib/util.js'
|
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
|
||||||
@@ -23,11 +27,22 @@
|
|||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Entity from '$lib/components/ui/Entity.svelte'
|
import Entity from '$lib/components/ui/Entity.svelte'
|
||||||
|
|
||||||
export let community: CommunityView
|
let showInfo = $state(false)
|
||||||
export let view: 'cozy' | 'compact' = 'compact'
|
interface Props {
|
||||||
export let showCounts: boolean = true
|
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>
|
</script>
|
||||||
|
|
||||||
{#if showInfo}
|
{#if showInfo}
|
||||||
@@ -36,10 +51,7 @@
|
|||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div
|
<div class={clazz}>
|
||||||
class={$$props.class ??
|
|
||||||
'py-4 flex flex-col gap-4 text-sm max-w-full relative'}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="flex
|
class="flex
|
||||||
{view == 'cozy'
|
{view == 'cozy'
|
||||||
@@ -49,7 +61,7 @@
|
|||||||
<a
|
<a
|
||||||
href="/c/{fullCommunityName(
|
href="/c/{fullCommunityName(
|
||||||
community.community.name,
|
community.community.name,
|
||||||
community.community.actor_id
|
community.community.actor_id,
|
||||||
)}"
|
)}"
|
||||||
class="flex-1 w-full overflow-hidden"
|
class="flex-1 w-full overflow-hidden"
|
||||||
data-sveltekit-preload-data="tap"
|
data-sveltekit-preload-data="tap"
|
||||||
@@ -59,18 +71,54 @@
|
|||||||
? 'flex-col gap-2'
|
? 'flex-col gap-2'
|
||||||
: 'flex-row'} gap-2 items-center"
|
: 'flex-row'} gap-2 items-center"
|
||||||
>
|
>
|
||||||
<slot name="icon">
|
{#if icon}{@render icon()}{:else}
|
||||||
<Avatar
|
<Avatar
|
||||||
url={community.community.icon}
|
url={community.community.icon}
|
||||||
width={32}
|
width={32}
|
||||||
alt={community.community.name}
|
alt={community.community.name}
|
||||||
/>
|
/>
|
||||||
</slot>
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="flex flex-col overflow-hidden whitespace-nowrap flex-1 min-w-0 flex-shrink"
|
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">
|
<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>
|
||||||
<div
|
<div
|
||||||
class="text-sm text-slate-600 dark:text-zinc-400 flex gap-0.5"
|
class="text-sm text-slate-600 dark:text-zinc-400 flex gap-0.5"
|
||||||
@@ -90,53 +138,58 @@
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="flex flex-row items-center gap-2">
|
<div class="flex flex-row items-center gap-2">
|
||||||
<Button size="square-md" on:click={() => (showInfo = !showInfo)}>
|
<Button size="square-md" onclick={() => (showInfo = !showInfo)}>
|
||||||
<Icon src={InformationCircle} size="16" micro />
|
<Icon src={InformationCircle} size="16" mini />
|
||||||
</Button>
|
</Button>
|
||||||
<Subscribe {community} let:subscribe let:subscribing>
|
<Subscribe {community}>
|
||||||
<Button
|
{#snippet children({ subscribe, subscribing })}
|
||||||
disabled={subscribing || !$profile?.jwt}
|
<Button
|
||||||
loading={subscribing}
|
disabled={subscribing || !profile.data?.jwt}
|
||||||
on:click={async () => {
|
loading={subscribing}
|
||||||
const res = await subscribe()
|
onclick={async () => {
|
||||||
|
const res = await subscribe()
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
const newSubscribed =
|
const newSubscribed =
|
||||||
res.community_view.subscribed != 'NotSubscribed'
|
res.community_view.subscribed != 'NotSubscribed'
|
||||||
? 'Subscribed'
|
? 'Subscribed'
|
||||||
: 'NotSubscribed'
|
: 'NotSubscribed'
|
||||||
|
|
||||||
community.subscribed = newSubscribed
|
community.subscribed = newSubscribed
|
||||||
addSubscription(
|
addSubscription(
|
||||||
community.community,
|
community.community,
|
||||||
newSubscribed == 'Subscribed'
|
newSubscribed == 'Subscribed',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
size="custom"
|
size="custom"
|
||||||
title={isSubscribed(community.subscribed)
|
title={isSubscribed(community.subscribed)
|
||||||
? $t('cards.community.subscribed')
|
? $t('cards.community.subscribed')
|
||||||
: $t('cards.community.subscribe')}
|
: $t('cards.community.subscribe')}
|
||||||
color={isSubscribed(community.subscribed) ? 'elevatedLow' : 'primary'}
|
color={isSubscribed(community.subscribed)
|
||||||
class="{isSubscribed(community.subscribed)
|
? 'elevatedLow'
|
||||||
? 'text-slate-600 dark:text-zinc-400'
|
: 'primary'}
|
||||||
: ''}
|
class="{isSubscribed(community.subscribed)
|
||||||
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
|
? 'text-slate-600 dark:text-zinc-400'
|
||||||
>
|
: ''}
|
||||||
<Icon
|
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
|
||||||
src={isSubscribed(community.subscribed) ? Check : Plus}
|
>
|
||||||
size="16"
|
{#snippet prefix()}
|
||||||
micro
|
<Icon
|
||||||
slot="prefix"
|
src={isSubscribed(community.subscribed) ? Check : Plus}
|
||||||
/>
|
size="16"
|
||||||
<span class="hidden @md:block">
|
micro
|
||||||
{#if isSubscribed(community.subscribed)}
|
/>
|
||||||
{$t('cards.community.subscribed')}
|
{/snippet}
|
||||||
{:else}
|
<span class="hidden @md:block">
|
||||||
{$t('cards.community.subscribe')}
|
{#if isSubscribed(community.subscribed)}
|
||||||
{/if}
|
{$t('cards.community.subscribed')}
|
||||||
</span>
|
{:else}
|
||||||
</Button>
|
{$t('cards.community.subscribe')}
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
</Subscribe>
|
</Subscribe>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,27 +1,42 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
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 { t } from '$lib/translations'
|
||||||
import type { Community } from 'lemmy-js-client'
|
import type { Community } from 'lemmy-js-client'
|
||||||
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let community: Community
|
interface Props {
|
||||||
|
community: Community
|
||||||
export let avatar: boolean = false
|
avatar?: boolean
|
||||||
export let name: boolean = true
|
name?: boolean
|
||||||
export let avatarSize: number = 24
|
avatarSize?: number
|
||||||
export let showInstance: boolean = $userSettings.showInstances.community
|
showInstance?: boolean
|
||||||
export let displayName: boolean = true
|
displayName?: boolean
|
||||||
|
badges?: any
|
||||||
export let badges = {
|
class?: string
|
||||||
nsfw: false,
|
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>
|
</script>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {$$props.class ||
|
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}"
|
href="/c/{community.name}@{new URL(community.actor_id).hostname}"
|
||||||
data-sveltekit-preload-data="tap"
|
data-sveltekit-preload-data="tap"
|
||||||
>
|
>
|
||||||
@@ -42,7 +57,7 @@
|
|||||||
{#if showInstance}
|
{#if showInstance}
|
||||||
<span
|
<span
|
||||||
class="text-slate-500 dark:text-zinc-500 font-normal
|
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}
|
@{new URL(community.actor_id).hostname}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import type { Community } from 'lemmy-js-client'
|
import type { Community } from 'lemmy-js-client'
|
||||||
|
|
||||||
export let community: Community
|
interface Props {
|
||||||
|
community: Community
|
||||||
|
}
|
||||||
|
|
||||||
|
let { community }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-row gap-3 items-center">
|
<div class="flex flex-row gap-3 items-center">
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/state'
|
||||||
import { profile } from '$lib/auth'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import { userSettings } from '$lib/settings'
|
import { searchParam } from '$lib/util.svelte'
|
||||||
import { searchParam } from '$lib/util'
|
|
||||||
import { Select } from 'mono-svelte'
|
import { Select } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
GlobeAmericas,
|
GlobeAmericas,
|
||||||
@@ -13,73 +12,56 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { amModOfAny } from '../moderation/moderation'
|
import { amModOfAny } from '../moderation/moderation'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
|
|
||||||
export let selected: string
|
interface Props {
|
||||||
export let navigate: boolean = true
|
selected: string
|
||||||
export let changeDefault: boolean = false
|
navigate?: boolean
|
||||||
export let showLabel: boolean = true
|
changeDefault?: boolean
|
||||||
|
showLabel?: boolean
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
let feed: string = selected
|
let {
|
||||||
$: feed = selected
|
selected = $bindable(),
|
||||||
$: changeDefault
|
navigate = true,
|
||||||
? ($userSettings.defaultSort.feed = selected as
|
changeDefault = false,
|
||||||
| 'All'
|
showLabel = true,
|
||||||
| 'Subscribed'
|
...rest
|
||||||
| 'Local')
|
}: Props = $props()
|
||||||
: undefined
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
bind:value={feed}
|
bind:value={selected}
|
||||||
on:change={() => {
|
onchange={() => {
|
||||||
if (navigate) searchParam($page.url, 'type', feed, 'page', 'cursor')
|
if (navigate) searchParam(page.url, 'type', selected, 'page', 'cursor')
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="label">
|
{#snippet customLabel()}
|
||||||
{#if showLabel}
|
{#if showLabel}
|
||||||
<span class="flex items-center gap-1">
|
<span class="flex items-center gap-1">
|
||||||
<Icon src={GlobeAmericas} size="16" micro />
|
<Icon src={GlobeAmericas} size="16" micro />
|
||||||
{$t('filter.location.label')}
|
{$t('filter.location.label')}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
<option value="All">
|
<Option value="All" icon={GlobeAmericas}>
|
||||||
<Icon
|
|
||||||
src={GlobeAmericas}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.location.all')}
|
{$t('filter.location.all')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="Local">
|
<Option value="Local" icon={MapPin}>{$t('filter.location.local')}</Option>
|
||||||
<Icon
|
<Option
|
||||||
src={MapPin}
|
value="Subscribed"
|
||||||
size="16"
|
disabled={profile.data?.jwt == undefined}
|
||||||
micro
|
icon={Newspaper}
|
||||||
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"
|
|
||||||
/>
|
|
||||||
{$t('filter.location.subscribed')}
|
{$t('filter.location.subscribed')}
|
||||||
</option>
|
</Option>
|
||||||
<option
|
<Option
|
||||||
value="ModeratorView"
|
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')}
|
{$t('filter.location.moderator')}
|
||||||
</option>
|
</Option>
|
||||||
</Select>
|
</Select>
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/state'
|
||||||
import { userSettings } from '$lib/settings'
|
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { searchParam } from '$lib/util.js'
|
import { searchParam } from '$lib/util.svelte.js'
|
||||||
import type { SortType } from 'lemmy-js-client'
|
|
||||||
import { Select } from 'mono-svelte'
|
import { Select } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
ArrowTrendingDown,
|
ArrowTrendingDown,
|
||||||
@@ -24,215 +22,119 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { backOut } from 'svelte/easing'
|
import { backOut } from 'svelte/easing'
|
||||||
import { fly, slide } from 'svelte/transition'
|
import { fly, slide } from 'svelte/transition'
|
||||||
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
|
|
||||||
export let selected: string
|
interface Props {
|
||||||
export let navigate: boolean = true
|
selected: string
|
||||||
export let changeDefault: boolean = false
|
navigate?: boolean
|
||||||
|
changeDefault?: boolean
|
||||||
let sort: string = selected?.startsWith('Top') ? 'TopAll' : selected
|
class?: string
|
||||||
$: if (selected) {
|
[key: string]: any
|
||||||
sort = selected?.startsWith('Top') ? 'TopAll' : selected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
const setSelected = () => (selected = sort)
|
||||||
$: changeDefault
|
|
||||||
? ($userSettings.defaultSort.sort = selected as SortType)
|
|
||||||
: undefined
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-row {$$props.class}">
|
<div class="flex flex-row {clazz}">
|
||||||
<Select
|
<Select
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
class={selected?.startsWith('Top') ? 'rounded-r-none' : ''}
|
class={selected?.startsWith('Top') ? 'rounded-r-none' : ''}
|
||||||
bind:value={sort}
|
bind:value={sort}
|
||||||
on:change={(e) => {
|
onchange={() => {
|
||||||
setSelected()
|
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">
|
{#snippet customLabel()}
|
||||||
<Icon src={ChartBar} size="13" micro />
|
<span class="flex items-center gap-1">
|
||||||
{$t('filter.sort.label')}
|
<Icon src={ChartBar} size="13" micro />
|
||||||
</span>
|
{$t('filter.sort.label')}
|
||||||
<option value="Active">
|
</span>
|
||||||
<Icon
|
{/snippet}
|
||||||
src={ArrowTrendingUp}
|
<Option value="Active" icon={ArrowTrendingUp}>
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.active')}
|
{$t('filter.sort.active')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="Hot">
|
<Option value="Hot" icon={Fire}>
|
||||||
<Icon
|
|
||||||
src={Fire}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.hot')}
|
{$t('filter.sort.hot')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="Scaled">
|
<Option value="Scaled" icon={Scale}>
|
||||||
<Icon
|
|
||||||
src={Scale}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.scaled')}
|
{$t('filter.sort.scaled')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="TopAll">
|
<Option value="TopAll" icon={Trophy}>
|
||||||
<Icon
|
|
||||||
src={Trophy}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.top.label')}
|
{$t('filter.sort.top.label')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="New">
|
<Option value="New" icon={Star}>
|
||||||
<Icon
|
|
||||||
src={Star}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.new')}
|
{$t('filter.sort.new')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="Old">
|
<Option value="Old" icon={Clock}>
|
||||||
<Icon
|
|
||||||
src={Clock}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.old')}
|
{$t('filter.sort.old')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="Controversial">
|
<Option value="Controversial" icon={ArrowTrendingDown}>
|
||||||
<Icon
|
|
||||||
src={ArrowTrendingDown}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.controversial')}
|
{$t('filter.sort.controversial')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="MostComments">
|
<Option value="MostComments" icon={ChatBubbleOvalLeft}>
|
||||||
<Icon
|
|
||||||
src={ChatBubbleOvalLeft}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.mostcomments')}
|
{$t('filter.sort.mostcomments')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="NewComments">
|
<Option value="NewComments" icon={ChatBubbleLeftRight}>
|
||||||
<Icon
|
|
||||||
src={ChatBubbleLeftRight}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.newcomments')}
|
{$t('filter.sort.newcomments')}
|
||||||
</option>
|
</Option>
|
||||||
</Select>
|
</Select>
|
||||||
{#if selected?.startsWith('Top')}
|
{#if selected?.startsWith('Top')}
|
||||||
<div transition:fly={{ easing: backOut, x: 2 }}>
|
<div transition:fly={{ easing: backOut, x: 2 }}>
|
||||||
<Select
|
<Select
|
||||||
class="border-l-0 rounded-l-none"
|
class="border-l-0 rounded-l-none"
|
||||||
bind:value={selected}
|
bind:value={selected}
|
||||||
on:change={(e) => {
|
onchange={() => {
|
||||||
sort = 'TopAll'
|
sort = 'TopAll'
|
||||||
if (navigate)
|
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">
|
{#snippet customLabel()}
|
||||||
<Icon src={Clock} size="15" micro />
|
<span class="flex items-center gap-1">
|
||||||
{$t('filter.sort.top.time.label')}
|
<Icon src={Clock} size="15" micro />
|
||||||
</span>
|
{$t('filter.sort.top.time.label')}
|
||||||
<option value="TopAll">
|
</span>
|
||||||
<Icon
|
{/snippet}
|
||||||
src={PlusCircle}
|
<Option value="TopAll" icon={PlusCircle}>
|
||||||
size="16"
|
{$t('filter.sort.top.time.all')}
|
||||||
micro
|
</Option>
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
<Option value="TopNineMonths" icon={Calendar}>
|
||||||
/>{$t('filter.sort.top.time.all')}
|
|
||||||
</option>
|
|
||||||
<option value="TopNineMonths">
|
|
||||||
<Icon
|
|
||||||
src={Calendar}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.top.time.9months')}
|
{$t('filter.sort.top.time.9months')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="TopSixMonths">
|
<Option value="TopSixMonths" icon={Calendar}>
|
||||||
<Icon
|
|
||||||
src={Calendar}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.top.time.6months')}
|
{$t('filter.sort.top.time.6months')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="TopThreeMonths">
|
<Option value="TopThreeMonths" icon={Calendar}>
|
||||||
<Icon
|
|
||||||
src={Calendar}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.sort.top.time.3months')}
|
{$t('filter.sort.top.time.3months')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="TopMonth">
|
<Option value="TopMonth" icon={CalendarDays}>
|
||||||
<Icon
|
{$t('filter.sort.top.time.month')}
|
||||||
src={CalendarDays}
|
</Option>
|
||||||
size="16"
|
<Option value="TopWeek" icon={CalendarDays}>
|
||||||
micro
|
{$t('filter.sort.top.time.week')}
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
</Option>
|
||||||
/>{$t('filter.sort.top.time.month')}
|
<Option value="TopDay" icon={Sun}>
|
||||||
</option>
|
{$t('filter.sort.top.time.day')}
|
||||||
<option value="TopWeek">
|
</Option>
|
||||||
<Icon
|
<Option value="TopTwelveHour" icon={Clock}>
|
||||||
src={CalendarDays}
|
{$t('filter.sort.top.time.12hours')}
|
||||||
size="16"
|
</Option>
|
||||||
micro
|
<Option value="TopSixHour" icon={Clock}>
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
{$t('filter.sort.top.time.6hours')}
|
||||||
/>{$t('filter.sort.top.time.week')}
|
</Option>
|
||||||
</option>
|
<Option value="TopHour" icon={Clock}>
|
||||||
<option value="TopDay">
|
{$t('filter.sort.top.time.hour')}
|
||||||
<Icon
|
</Option>
|
||||||
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>
|
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { Select } from 'mono-svelte'
|
import { Select } from 'mono-svelte'
|
||||||
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
import {
|
import {
|
||||||
Bars3,
|
Bars3,
|
||||||
Clock,
|
Clock,
|
||||||
@@ -13,43 +14,27 @@
|
|||||||
ViewColumns,
|
ViewColumns,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let showLabel = true
|
interface Props {
|
||||||
|
showLabel?: boolean
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
|
let { showLabel = true, ...rest }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Select {...$$restProps} bind:value={$userSettings.view}>
|
<Select {...rest} bind:value={settings.view}>
|
||||||
<svelte:fragment slot="label">
|
{#snippet customLabel()}
|
||||||
{#if showLabel}
|
{#if showLabel}
|
||||||
<span class="flex items-center gap-1">
|
<span class="flex items-center gap-1">
|
||||||
<Icon src={ViewColumns} size="14" micro />
|
<Icon src={ViewColumns} size="14" micro />
|
||||||
{$t('filter.view.label')}
|
{$t('filter.view.label')}
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
<option value="cozy">
|
<Option value="cozy" icon={RectangleGroup}>
|
||||||
<Icon
|
|
||||||
src={RectangleGroup}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class="text-slate-600 dark:text-zinc-400"
|
|
||||||
/>
|
|
||||||
{$t('filter.view.cozy')}
|
{$t('filter.view.cozy')}
|
||||||
</option>
|
</Option>
|
||||||
<option value="list">
|
<Option value="compact" icon={Bars3}>
|
||||||
<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"
|
|
||||||
/>
|
|
||||||
{$t('filter.view.compact')}
|
{$t('filter.view.compact')}
|
||||||
</option>
|
</Option>
|
||||||
</Select>
|
</Select>
|
||||||
@@ -5,13 +5,17 @@
|
|||||||
import { flip } from 'svelte/animate'
|
import { flip } from 'svelte/animate'
|
||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
|
|
||||||
export let items: {
|
interface Props {
|
||||||
avatar?: string
|
items: {
|
||||||
name: string
|
avatar?: string
|
||||||
instance?: string
|
name: string
|
||||||
id: number
|
instance?: string
|
||||||
url: string
|
id: number
|
||||||
}[]
|
url: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
let { items }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each items.sort((a, b) => a.name.localeCompare(b.name)) as item (item.id)}
|
{#each items.sort((a, b) => a.name.localeCompare(b.name)) as item (item.id)}
|
||||||
@@ -31,7 +35,6 @@
|
|||||||
alt={item.name}
|
alt={item.name}
|
||||||
title={item.name}
|
title={item.name}
|
||||||
width={24}
|
width={24}
|
||||||
slot="prefix"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col max-w-full break-words">
|
<div class="flex flex-col max-w-full break-words">
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
<script lang="ts">
|
<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 UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.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'
|
import type { PrivateMessageView } from 'lemmy-js-client'
|
||||||
|
|
||||||
export let message: PrivateMessageView
|
interface Props {
|
||||||
export let meta: boolean = true
|
message: PrivateMessageView
|
||||||
|
meta?: boolean
|
||||||
|
style?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { message, meta = true, style = '' }: Props = $props()
|
||||||
</script>
|
</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}
|
{#if meta}
|
||||||
<div class="flex flex-row gap-2 items-center flex-wrap">
|
<div class="flex flex-row gap-2 items-center flex-wrap">
|
||||||
<span class="font-medium text-xs">From</span>
|
<span class="font-medium text-xs">From</span>
|
||||||
@@ -18,7 +24,7 @@
|
|||||||
avatar
|
avatar
|
||||||
avatarSize={20}
|
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
|
to
|
||||||
<UserLink
|
<UserLink
|
||||||
showInstance={false}
|
showInstance={false}
|
||||||
@@ -29,5 +35,10 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<Markdown source={message.private_message.content} />
|
<TextProps wrap="no-wrap">
|
||||||
|
<Markdown
|
||||||
|
rendererOptions={{ autoloadImages: false }}
|
||||||
|
source={message.private_message.content}
|
||||||
|
/>
|
||||||
|
</TextProps>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,16 +1,25 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import type { Person } from 'lemmy-js-client'
|
import type { Person } from 'lemmy-js-client'
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
|
|
||||||
export let open: boolean = false
|
interface Props {
|
||||||
export let user: Person
|
open?: boolean
|
||||||
|
user: Person
|
||||||
|
denying: boolean
|
||||||
|
denyReason?: string
|
||||||
|
}
|
||||||
|
|
||||||
export let denying: boolean
|
let {
|
||||||
|
open = $bindable(false),
|
||||||
export let denyReason: string = ''
|
user,
|
||||||
|
denying = $bindable(),
|
||||||
|
denyReason = $bindable(''),
|
||||||
|
}: Props = $props()
|
||||||
|
|
||||||
let loading = false
|
let loading = false
|
||||||
|
|
||||||
@@ -21,10 +30,12 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal bind:open>
|
<Modal bind:open>
|
||||||
<h1 class="text-2xl font-bold" slot="title">
|
{#snippet customTitle()}
|
||||||
{$t('routes.admin.applications.modalTitle')}
|
<h1 class="text-2xl font-bold">
|
||||||
</h1>
|
{$t('routes.admin.applications.modalTitle')}
|
||||||
<form on:submit|preventDefault={() => deny()} class="flex flex-col gap-4">
|
</h1>
|
||||||
|
{/snippet}
|
||||||
|
<form onsubmit={preventDefault(() => deny())} class="flex flex-col gap-4">
|
||||||
<UserLink avatar {user} />
|
<UserLink avatar {user} />
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
bind:value={denyReason}
|
bind:value={denyReason}
|
||||||
|
|||||||
@@ -1,29 +1,38 @@
|
|||||||
<script lang="ts">
|
<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 ProgressBar from '$lib/components/ui/ProgressBar.svelte'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
import { t } from '$lib/translations'
|
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 { ImageInput, Spinner, toast } from 'mono-svelte'
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
|
||||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||||
import { expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { slide } from 'svelte/transition'
|
import { slide } from 'svelte/transition'
|
||||||
|
|
||||||
export let open: boolean
|
interface Props {
|
||||||
export let image: FileList | null = null
|
open: boolean
|
||||||
export let preview: boolean = true
|
image?: FileList | null
|
||||||
export let multiple: boolean = true
|
preview?: boolean
|
||||||
let progress = 1
|
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
|
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined
|
||||||
|
)
|
||||||
const dispatcher = createEventDispatcher<{ upload: string[] }>()
|
|
||||||
|
|
||||||
async function upload() {
|
async function upload() {
|
||||||
if (!$profile?.jwt || image == null) return
|
if (!profile.data?.jwt || image == null) return
|
||||||
|
|
||||||
progress = 0
|
progress = 0
|
||||||
|
|
||||||
@@ -31,7 +40,7 @@
|
|||||||
const uploaded = (
|
const uploaded = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Array.from(image).map((i) =>
|
Array.from(image).map((i) =>
|
||||||
uploadImage(i, $profile.instance, $profile.jwt!)
|
uploadImage(i, profile.data.instance, profile.data.jwt!)
|
||||||
.then((uploaded) => {
|
.then((uploaded) => {
|
||||||
progress += 1 / (image?.length ?? 0)
|
progress += 1 / (image?.length ?? 0)
|
||||||
return uploaded
|
return uploaded
|
||||||
@@ -46,7 +55,7 @@
|
|||||||
|
|
||||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||||
|
|
||||||
dispatcher('upload', uploaded)
|
onupload?.(uploaded)
|
||||||
progress = 1
|
progress = 1
|
||||||
open = false
|
open = false
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -61,13 +70,21 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal bind:open>
|
<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}
|
{#if progress != 1}
|
||||||
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
||||||
<ProgressBar {progress} />
|
<ProgressBar {progress} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/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
|
<label
|
||||||
for="image-input"
|
for="image-input"
|
||||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
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'}"
|
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
|
||||||
>
|
>
|
||||||
{#each previewURLs as file}
|
{#each previewURLs as file}
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
<!-- svelte-ignore a11y_missing_attribute -->
|
||||||
<img
|
<img
|
||||||
src={file}
|
src={file}
|
||||||
on:load={() => URL.revokeObjectURL(file)}
|
onload={() => URL.revokeObjectURL(file)}
|
||||||
alt={file}
|
alt={file}
|
||||||
class="w-full rounded-md h-full object-cover transition-all
|
class="w-full rounded-md h-full object-cover transition-all
|
||||||
border border-slate-200 dark:border-zinc-800 ring-1
|
border border-slate-200 dark:border-zinc-800 ring-1
|
||||||
@@ -91,9 +108,12 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{: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" />
|
<Icon src={DocumentPlus} size="32" />
|
||||||
<span>{$t('form.post.selectFile')}</span>
|
<span class="font-medium text-sm">{$t('form.post.selectFile')}</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
<script lang="ts">
|
<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 UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.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 { t } from '$lib/translations'
|
||||||
import type { Person } from 'lemmy-js-client'
|
import type { Person } from 'lemmy-js-client'
|
||||||
import { Button, Modal, toast } from 'mono-svelte'
|
import { Button, Modal, toast } from 'mono-svelte'
|
||||||
import { Icon, PaperAirplane } from 'svelte-hero-icons'
|
import { Icon, PaperAirplane } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let open: boolean = false
|
interface Props {
|
||||||
export let user: Person
|
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() {
|
async function sendMessage() {
|
||||||
if (!$profile?.jwt || message == '') return
|
if (!profile.data?.jwt || message == '') return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
@@ -44,8 +50,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal bind:open>
|
<Modal bind:open>
|
||||||
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
{#snippet customTitle()}
|
||||||
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
<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">
|
<p class="inline-flex flex-row gap-2 items-center">
|
||||||
<Icon src={PaperAirplane} size="16" mini />
|
<Icon src={PaperAirplane} size="16" mini />
|
||||||
<UserLink avatar {user} />
|
<UserLink avatar {user} />
|
||||||
|
|||||||
@@ -1,65 +1,58 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { run, preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
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 { 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 { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import CommunityLink from '../community/CommunityLink.svelte'
|
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
|
interface Props {
|
||||||
let item: Person | undefined
|
open?: boolean
|
||||||
export { item as user }
|
user: Person | undefined
|
||||||
export let community: Community | undefined
|
community: Community | undefined
|
||||||
export let banned: boolean
|
banned: boolean
|
||||||
|
}
|
||||||
|
|
||||||
let reason = ''
|
let {
|
||||||
let deleteData = false
|
open = $bindable(false),
|
||||||
let expires = ''
|
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
|
// hack due to svelte's reactive declarations
|
||||||
const resetReason = () => {
|
const resetReason = () => {
|
||||||
reason = ''
|
reason = ''
|
||||||
deleteData = false
|
deleteData = false
|
||||||
expires = ''
|
expires = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (item) resetReason()
|
$effect(() => {
|
||||||
|
if (item) resetReason()
|
||||||
|
})
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!item || !$profile?.user || !$profile?.jwt) return
|
if (!item || !profile.data?.user || !profile.data?.jwt) return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let date: number | undefined
|
let date: number | undefined
|
||||||
|
|
||||||
if (expires != '') {
|
if (expires > 0) {
|
||||||
date = Date.parse(expires)
|
date = Math.floor(Date.now() / 1000) + 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 (community) {
|
if (community) {
|
||||||
@@ -69,7 +62,7 @@
|
|||||||
person_id: item.id,
|
person_id: item.id,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
remove_data: deleteData,
|
remove_data: deleteData,
|
||||||
expires: date ? Math.floor(date / 1000) : undefined,
|
expires: date,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await getClient().banPerson({
|
await getClient().banPerson({
|
||||||
@@ -77,7 +70,7 @@
|
|||||||
person_id: item.id,
|
person_id: item.id,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
remove_data: deleteData,
|
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')}
|
title={banned ? $t('moderation.ban.unbanning') : $t('moderation.ban.banning')}
|
||||||
>
|
>
|
||||||
{#if item}
|
{#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">
|
<div class="flex items-center gap-1">
|
||||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||||
<span class="font-bold">{item.name}</span>
|
<span class="font-bold">{item.name}</span>
|
||||||
@@ -121,15 +114,14 @@
|
|||||||
{#if !banned}
|
{#if !banned}
|
||||||
<Checkbox bind:checked={deleteData}>
|
<Checkbox bind:checked={deleteData}>
|
||||||
{$t('moderation.ban.deleteData')}
|
{$t('moderation.ban.deleteData')}
|
||||||
<svelte:fragment slot="description">
|
{#snippet description()}
|
||||||
{$t('moderation.ban.warning')}
|
{$t('moderation.ban.warning')}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<TextInput
|
<div>
|
||||||
bind:value={expires}
|
<SectionTitle>{$t('moderation.ban.expires')}</SectionTitle>
|
||||||
label={$t('moderation.ban.expires')}
|
<Duration bind:value={expires}></Duration>
|
||||||
placeholder="2024 August 5"
|
</div>
|
||||||
/>
|
|
||||||
{/if}
|
{/if}
|
||||||
<Button submit color="primary" {loading} disabled={loading} size="lg">
|
<Button submit color="primary" {loading} disabled={loading} size="lg">
|
||||||
{$t('form.submit')}
|
{$t('form.submit')}
|
||||||
|
|||||||
@@ -9,34 +9,42 @@
|
|||||||
Trash,
|
Trash,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { isCommentView } from '$lib/lemmy/item.js'
|
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 ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||||
import { t } from '$lib/translations'
|
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>
|
</script>
|
||||||
|
|
||||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||||
<Button
|
{#snippet target()}
|
||||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
<Button
|
||||||
size="square-md"
|
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||||
slot="target"
|
size="square-md"
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
>
|
>
|
||||||
<ShieldIcon filled width={14} />
|
<ShieldIcon filled width={14} />
|
||||||
</Button>
|
</Button>
|
||||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
{/snippet}
|
||||||
|
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||||
<MenuDivider>
|
<MenuDivider>
|
||||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||||
{$t('moderation.labelInstanceOnly')}
|
{$t('moderation.labelInstanceOnly')}
|
||||||
{:else}
|
{:else}
|
||||||
{$t('moderation.label')}
|
{$t('moderation.label')}
|
||||||
{/if}
|
{/if}
|
||||||
</MenuDivider>
|
</MenuDivider>
|
||||||
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
<MenuButton color="danger-subtle" onclick={() => remove(item)}>
|
||||||
<Icon src={Trash} size="16" mini slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Trash} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
{#if isCommentView(item)}
|
{#if isCommentView(item)}
|
||||||
{item.comment.removed
|
{item.comment.removed
|
||||||
? $t('moderation.restore')
|
? $t('moderation.restore')
|
||||||
@@ -45,14 +53,16 @@
|
|||||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||||
{/if}
|
{/if}
|
||||||
</MenuButton>
|
</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-->
|
<!--Comment made by someone else-->
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
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
|
{item.creator_banned_from_community
|
||||||
? $t('moderation.ban.unbanFromCommunity')
|
? $t('moderation.ban.unbanFromCommunity')
|
||||||
: $t('moderation.ban.banFromCommunity')}
|
: $t('moderation.ban.banFromCommunity')}
|
||||||
@@ -61,18 +71,20 @@
|
|||||||
<!--Comment made by self-->
|
<!--Comment made by self-->
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="success-subtle"
|
color="success-subtle"
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if (!$profile.jwt) return
|
if (!profile.data.jwt) return
|
||||||
item.comment = (
|
item.comment = (
|
||||||
await feature(
|
await feature(
|
||||||
!item.comment.distinguished,
|
!item.comment.distinguished,
|
||||||
item.comment,
|
item.comment,
|
||||||
$profile.jwt
|
profile.data.jwt,
|
||||||
)
|
)
|
||||||
).comment_view.comment
|
).comment_view.comment
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon src={Megaphone} size="16" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Megaphone} size="16" micro />
|
||||||
|
{/snippet}
|
||||||
{item.comment.distinguished
|
{item.comment.distinguished
|
||||||
? $t('moderation.unfeature')
|
? $t('moderation.unfeature')
|
||||||
: $t('moderation.feature')}
|
: $t('moderation.feature')}
|
||||||
@@ -80,10 +92,12 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $profile?.user && isAdmin($profile.user)}
|
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||||
<MenuButton color="danger-subtle" on:click={() => remove(item, true)}>
|
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Fire} size="16" mini />
|
||||||
|
{/snippet}
|
||||||
{$t('admin.purge')}
|
{$t('admin.purge')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getClient } from '$lib/lemmy'
|
import { getClient } from '$lib/lemmy.svelte'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
import { amMod, ban, isAdmin, remove } from './moderation'
|
import { amMod, ban, isAdmin, remove } from './moderation'
|
||||||
import {
|
import {
|
||||||
|
ArrowsUpDown,
|
||||||
Fire,
|
Fire,
|
||||||
Icon,
|
Icon,
|
||||||
LockClosed,
|
LockClosed,
|
||||||
@@ -13,20 +14,25 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||||
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
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 { Button } from 'mono-svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import ShieldIcon from './ShieldIcon.svelte'
|
import ShieldIcon from './ShieldIcon.svelte'
|
||||||
|
|
||||||
export let item: PostView | CommentView
|
interface Props {
|
||||||
|
item: PostView | CommentView
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
let locking = false
|
let { item = $bindable(), ...rest }: Props = $props()
|
||||||
let pinning = false
|
|
||||||
|
|
||||||
$: acting = locking || pinning
|
let locking = $state(false)
|
||||||
|
let pinning = $state(false)
|
||||||
|
|
||||||
|
let acting = $derived(locking || pinning)
|
||||||
|
|
||||||
async function lock(lock: boolean) {
|
async function lock(lock: boolean) {
|
||||||
if (!$profile?.jwt || !isPostView(item)) return
|
if (!profile.data?.jwt || !isPostView(item)) return
|
||||||
locking = true
|
locking = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -47,7 +53,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||||
if (!$profile?.jwt || !isPostView(item)) return
|
if (!profile.data?.jwt || !isPostView(item)) return
|
||||||
|
|
||||||
pinning = true
|
pinning = true
|
||||||
|
|
||||||
@@ -71,19 +77,20 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Menu placement="bottom-end">
|
<Menu placement="bottom-end">
|
||||||
<Button
|
{#snippet target()}
|
||||||
class="hover:!text-green-500"
|
<Button
|
||||||
slot="target"
|
class="hover:!text-green-500"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
loading={acting}
|
loading={acting}
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
>
|
>
|
||||||
<ShieldIcon filled width={16} />
|
<ShieldIcon filled width={16} />
|
||||||
</Button>
|
</Button>
|
||||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
{/snippet}
|
||||||
|
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
|
||||||
<MenuDivider>
|
<MenuDivider>
|
||||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
{#if !item.community.local && !amMod(profile.data.user, item.community)}
|
||||||
{$t('moderation.labelInstanceOnly')}
|
{$t('moderation.labelInstanceOnly')}
|
||||||
{:else}
|
{:else}
|
||||||
{$t('moderation.label')}
|
{$t('moderation.label')}
|
||||||
@@ -91,22 +98,19 @@
|
|||||||
</MenuDivider>
|
</MenuDivider>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="warning-subtle"
|
color="warning-subtle"
|
||||||
on:click={() => lock(!item.post.locked)}
|
onclick={() => lock(!item.post.locked)}
|
||||||
loading={locking}
|
loading={locking}
|
||||||
disabled={locking}
|
disabled={locking}
|
||||||
>
|
>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={item.post.locked ? LockOpen : LockClosed}
|
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||||
size="16"
|
{/snippet}
|
||||||
mini
|
|
||||||
slot="prefix"
|
|
||||||
/>
|
|
||||||
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="success-subtle"
|
color="success-subtle"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
pin(isPostView(item) ? !item.post.featured_community : false)}
|
pin(isPostView(item) ? !item.post.featured_community : false)}
|
||||||
loading={pinning}
|
loading={pinning}
|
||||||
disabled={pinning}
|
disabled={pinning}
|
||||||
@@ -120,12 +124,12 @@
|
|||||||
? $t('moderation.unfeature')
|
? $t('moderation.unfeature')
|
||||||
: $t('moderation.feature')}
|
: $t('moderation.feature')}
|
||||||
</span>
|
</span>
|
||||||
{#if isAdmin($profile.user)}
|
{#if isAdmin(profile.data.user)}
|
||||||
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
<MenuButton color="danger-subtle" onclick={() => remove(item)}>
|
||||||
<Icon src={Trash} size="16" mini />
|
<Icon src={Trash} size="16" mini />
|
||||||
{#if isCommentView(item)}
|
{#if isCommentView(item)}
|
||||||
{item.comment.removed
|
{item.comment.removed
|
||||||
@@ -135,10 +139,10 @@
|
|||||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||||
{/if}
|
{/if}
|
||||||
</MenuButton>
|
</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
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||||
>
|
>
|
||||||
<Icon src={ShieldExclamation} size="16" mini />
|
<Icon src={ShieldExclamation} size="16" mini />
|
||||||
@@ -148,11 +152,11 @@
|
|||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile?.user && isAdmin($profile.user)}
|
{#if profile.data?.user && isAdmin(profile.data.user)}
|
||||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="success-subtle"
|
color="success-subtle"
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
pin(isPostView(item) ? !item.post.featured_local : false, true)}
|
pin(isPostView(item) ? !item.post.featured_local : false, true)}
|
||||||
>
|
>
|
||||||
<Icon src={Megaphone} size="16" mini />
|
<Icon src={Megaphone} size="16" mini />
|
||||||
@@ -167,7 +171,7 @@
|
|||||||
<span class="text-xs opacity-80">{$t('admin.instance')}</span>
|
<span class="text-xs opacity-80">{$t('admin.instance')}</span>
|
||||||
</div>
|
</div>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton color="danger-subtle" on:click={() => remove(item, true)}>
|
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||||
<Icon src={Fire} size="16" mini />
|
<Icon src={Fire} size="16" mini />
|
||||||
{$t('admin.purge')}
|
{$t('admin.purge')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
|||||||
@@ -1,36 +1,49 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { run, preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import { Select, Switch, toast } from 'mono-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 { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
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 MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { fullCommunityName } from '$lib/util.js'
|
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||||
import { amMod, isAdmin } from './moderation'
|
import { amMod, isAdmin } from './moderation'
|
||||||
import { Button, Checkbox, Modal } from 'mono-svelte'
|
import { Button, Checkbox, Modal } from 'mono-svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
|
|
||||||
export let open: boolean
|
interface Props {
|
||||||
export let item: PostView | CommentView | undefined = undefined
|
open: boolean
|
||||||
export let purge: boolean = false
|
item?: PostView | CommentView | undefined
|
||||||
|
purge?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
let reason = ''
|
let {
|
||||||
let commentReason: boolean = false
|
open = $bindable(),
|
||||||
let privateMessage: boolean = false
|
item = $bindable(undefined),
|
||||||
let loading = false
|
purge = false,
|
||||||
let preset = $userSettings.moderation.presets[0]?.content ?? ''
|
}: Props = $props()
|
||||||
|
|
||||||
$: removed = item
|
let reason = $state('')
|
||||||
? isCommentView(item)
|
let commentReason: boolean = $state(false)
|
||||||
? item.comment.removed
|
let privateMessage: boolean = $state(false)
|
||||||
: item.post.removed
|
let loading = $state(false)
|
||||||
: 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) => {
|
const getReplyReason = (reason: string, preset: string) => {
|
||||||
if (!item) return `no template`
|
if (!item) return `no template`
|
||||||
@@ -38,7 +51,7 @@
|
|||||||
return removalTemplate(preset, {
|
return removalTemplate(preset, {
|
||||||
communityLink: `!${fullCommunityName(
|
communityLink: `!${fullCommunityName(
|
||||||
item!.community.name,
|
item!.community.name,
|
||||||
item!.community.actor_id
|
item!.community.actor_id,
|
||||||
)}`,
|
)}`,
|
||||||
postTitle: item.post.name,
|
postTitle: item.post.name,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
@@ -46,11 +59,14 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$: replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
let replyReason = $state('')
|
||||||
|
$effect(() => {
|
||||||
|
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||||
|
})
|
||||||
|
|
||||||
async function remove() {
|
async function remove() {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
if (!$profile?.jwt) throw new Error('Unauthenticated')
|
if (!profile.data?.jwt) throw new Error('Unauthenticated')
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
@@ -147,15 +163,14 @@
|
|||||||
|
|
||||||
const resetText = () => {
|
const resetText = () => {
|
||||||
reason = ''
|
reason = ''
|
||||||
replyReason = ''
|
|
||||||
commentReason = false
|
commentReason = false
|
||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
run(() => {
|
||||||
if (item) {
|
if (item) {
|
||||||
resetText()
|
resetText()
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
@@ -168,7 +183,7 @@
|
|||||||
>
|
>
|
||||||
{#if item}
|
{#if item}
|
||||||
<form
|
<form
|
||||||
on:submit|preventDefault={remove}
|
onsubmit={preventDefault(remove)}
|
||||||
class="flex flex-col gap-4 list-none"
|
class="flex flex-col gap-4 list-none"
|
||||||
>
|
>
|
||||||
{#if isCommentView(item)}
|
{#if isCommentView(item)}
|
||||||
@@ -177,7 +192,6 @@
|
|||||||
children: [],
|
children: [],
|
||||||
comment_view: item,
|
comment_view: item,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
ui: {},
|
|
||||||
}}
|
}}
|
||||||
postId={item.post.id}
|
postId={item.post.id}
|
||||||
actions={false}
|
actions={false}
|
||||||
@@ -193,7 +207,7 @@
|
|||||||
bind:value={reason}
|
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}>
|
<Switch bind:checked={commentReason}>
|
||||||
{$t('moderation.removeSubmission.withReason')}
|
{$t('moderation.removeSubmission.withReason')}
|
||||||
</Switch>
|
</Switch>
|
||||||
@@ -212,16 +226,18 @@
|
|||||||
placeholder={replyReason}
|
placeholder={replyReason}
|
||||||
rows={3}
|
rows={3}
|
||||||
>
|
>
|
||||||
<div class="flex justify-between items-end mb-1" slot="label">
|
{#snippet customLabel()}
|
||||||
{$t('comment.reply')}
|
<div class="flex justify-between items-end mb-1">
|
||||||
<Select bind:value={preset} placeholder="No preset">
|
{$t('comment.reply')}
|
||||||
{#each $userSettings.moderation.presets as preset}
|
<Select bind:value={preset} placeholder="No preset">
|
||||||
<option value={preset.content}>
|
{#each settings.moderation.presets as preset}
|
||||||
{preset.title}
|
<Option value={preset.content}>
|
||||||
</option>
|
{preset.title}
|
||||||
{/each}
|
</Option>
|
||||||
</Select>
|
{/each}
|
||||||
</div>
|
</Select>
|
||||||
|
</div>
|
||||||
|
{/snippet}
|
||||||
</MarkdownEditor>
|
</MarkdownEditor>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -233,7 +249,9 @@
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
submit
|
submit
|
||||||
>
|
>
|
||||||
<Icon src={purge ? Fire : Trash} mini size="16" slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={purge ? Fire : Trash} mini size="16" />
|
||||||
|
{/snippet}
|
||||||
{#if purge}
|
{#if purge}
|
||||||
{$t('admin.purge')}
|
{$t('admin.purge')}
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { run, preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import { toast } from 'mono-svelte'
|
import { toast } from 'mono-svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.svelte.js'
|
||||||
import type {
|
import type {
|
||||||
CommentView,
|
CommentView,
|
||||||
PostView,
|
PostView,
|
||||||
PrivateMessageView,
|
PrivateMessageView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import { Button, Modal } from 'mono-svelte'
|
import { Button, Modal } from 'mono-svelte'
|
||||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
@@ -16,27 +18,30 @@
|
|||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||||
|
|
||||||
export let open: boolean
|
interface Props {
|
||||||
export let item: PostView | CommentView | PrivateMessageView | undefined =
|
open: boolean
|
||||||
undefined
|
item?: PostView | CommentView | PrivateMessageView | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
let { open = $bindable(), item = $bindable() }: Props = $props()
|
||||||
|
|
||||||
const isComment = (
|
const isComment = (
|
||||||
item: PostView | CommentView | PrivateMessageView
|
item: PostView | CommentView | PrivateMessageView,
|
||||||
): item is CommentView => 'comment' in item
|
): item is CommentView => 'comment' in item
|
||||||
|
|
||||||
const isPost = (
|
const isPost = (
|
||||||
item: PostView | CommentView | PrivateMessageView
|
item: PostView | CommentView | PrivateMessageView,
|
||||||
): item is PostView => !isComment(item) && 'post' in item
|
): item is PostView => !isComment(item) && 'post' in item
|
||||||
|
|
||||||
const isPrivateMessage = (
|
const isPrivateMessage = (
|
||||||
item: PostView | CommentView | PrivateMessageView
|
item: PostView | CommentView | PrivateMessageView,
|
||||||
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
||||||
|
|
||||||
let loading = false
|
let loading = $state(false)
|
||||||
let reason = ''
|
let reason = $state('')
|
||||||
|
|
||||||
async function report() {
|
async function report() {
|
||||||
if (!item || !$profile?.jwt || reason == '') return
|
if (!item || !profile.data?.jwt || reason == '') return
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -70,15 +75,15 @@
|
|||||||
|
|
||||||
const resetText = () => (reason = '')
|
const resetText = () => (reason = '')
|
||||||
|
|
||||||
$: {
|
run(() => {
|
||||||
if (item) {
|
if (item) {
|
||||||
resetText()
|
resetText()
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal bind:open title={$t('moderation.reportModal.title')}>
|
<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}
|
{#if item}
|
||||||
<div class="pointer-events-none list-none">
|
<div class="pointer-events-none list-none">
|
||||||
{#if isComment(item)}
|
{#if isComment(item)}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let width: number = 16
|
interface Props {
|
||||||
export let filled: boolean = false
|
width?: number
|
||||||
|
filled?: boolean
|
||||||
|
class?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { width = 16, filled = false, class: clazz = '' }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if filled}
|
{#if filled}
|
||||||
@@ -10,7 +15,7 @@
|
|||||||
viewBox="0 0 20 22"
|
viewBox="0 0 20 22"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="inline {$$props.class}"
|
class="inline {clazz}"
|
||||||
>
|
>
|
||||||
<path
|
<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"
|
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"
|
viewBox="0 0 20 22"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="inline {$$props.class}"
|
class="inline {clazz}"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
fill-rule="evenodd"
|
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 { SubmissionView } from '$lib/lemmy/contentview.js'
|
||||||
import type {
|
import type {
|
||||||
Comment,
|
Comment,
|
||||||
@@ -106,7 +106,7 @@ export const removalTemplate = (
|
|||||||
communityLink?: string
|
communityLink?: string
|
||||||
username?: string
|
username?: string
|
||||||
reason?: string
|
reason?: string
|
||||||
}
|
},
|
||||||
) => {
|
) => {
|
||||||
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
||||||
if (content.communityLink)
|
if (content.communityLink)
|
||||||
|
|||||||
@@ -1,65 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PostView } from 'lemmy-js-client'
|
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 PostActions from '$lib/components/lemmy/post/PostActions.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { settings, type View } from '$lib/settings.svelte.js'
|
||||||
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
|
|
||||||
import PostMeta, {
|
import PostMeta, {
|
||||||
parseTags,
|
parseTags,
|
||||||
type Tag,
|
type Tag,
|
||||||
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
} from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||||
import { Badge, Material, toast } from 'mono-svelte'
|
import { Badge } from 'mono-svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
|
||||||
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 { publishedToDate } from '$lib/components/util/date.js'
|
import { publishedToDate } from '$lib/components/util/date.js'
|
||||||
import {
|
import { ArrowUp, ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
|
||||||
ArrowUp,
|
|
||||||
ChatBubbleOvalLeft,
|
|
||||||
Icon,
|
|
||||||
VideoCamera,
|
|
||||||
} from 'svelte-hero-icons'
|
|
||||||
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
|
||||||
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
|
||||||
import PostBody from './PostBody.svelte'
|
import PostBody from './PostBody.svelte'
|
||||||
import { profile } from '$lib/auth'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
|
import type { ClassValue } from 'svelte/elements'
|
||||||
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'
|
|
||||||
|
|
||||||
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
|
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
|
||||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||||
|
|
||||||
let rule: 'blur' | 'hide' | undefined
|
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'
|
rule = 'blur'
|
||||||
tagContent.forEach((tag) => {
|
tagContent.forEach((tag) => {
|
||||||
if ($userSettings.tagRules?.[tag])
|
if (settings.tagRules?.[tag]) rule = settings.tagRules?.[tag] ?? rule
|
||||||
rule = $userSettings.tagRules?.[tag] ?? rule
|
|
||||||
if (rule == 'hide') return rule
|
if (rule == 'hide') return rule
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -74,6 +39,59 @@
|
|||||||
goto(postLink(post.post))
|
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>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -81,44 +99,35 @@
|
|||||||
This is the sole component for displaying posts.
|
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.
|
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_no_static_element_interactions -->
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||||
<div
|
<div
|
||||||
class="post relative max-w-full min-w-0 w-full cursor-pointer outline-none
|
class={[
|
||||||
group
|
'post relative max-w-full min-w-0 w-full cursor-pointer outline-none group',
|
||||||
{$userSettings.leftAlign ? 'left-align' : ''}
|
settings.leftAlign && 'left-align',
|
||||||
{view == 'compact' ? 'py-3 list-type compact' : ''}
|
view == 'compact' && 'py-3 list-type compact',
|
||||||
{view == 'list' ? 'py-5 list-type' : ''}
|
view == 'cozy' && 'py-5 flex flex-col gap-2',
|
||||||
{view == 'cozy' ? 'py-5 flex flex-col gap-2' : ''}
|
clazz,
|
||||||
{$$props.class ?? ''}"
|
]}
|
||||||
id={post.post.id.toString()}
|
id={post.post.id.toString()}
|
||||||
on:click={(e) => {
|
onclick={(e) => {
|
||||||
onClick(e)
|
onClick(e)
|
||||||
}}
|
}}
|
||||||
on:keydown={(e) => {
|
onkeydown={(e) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (e.key == 'Enter') onClick(e)
|
if (e.key == 'Enter') onClick(e)
|
||||||
}}
|
}}
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
style={$$props.style ?? ''}
|
{style}
|
||||||
>
|
>
|
||||||
<PostMeta
|
<PostMeta
|
||||||
community={post.community}
|
community={post.community}
|
||||||
showCommunity={!hideCommunity}
|
showCommunity={!hideCommunity}
|
||||||
user={post.creator}
|
user={post.creator}
|
||||||
published={publishedToDate(post.post.published)}
|
published={publishedToDate(post.post.published)}
|
||||||
badges={{
|
{badges}
|
||||||
deleted: post.post.deleted,
|
subscribed={profile.data?.user?.follows
|
||||||
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
|
|
||||||
.map((c) => c.community.id)
|
.map((c) => c.community.id)
|
||||||
.includes(post.community.id)
|
.includes(post.community.id)
|
||||||
? 'Subscribed'
|
? 'Subscribed'
|
||||||
@@ -130,14 +139,10 @@
|
|||||||
edited={post.post.updated}
|
edited={post.post.updated}
|
||||||
tags={tags?.tags}
|
tags={tags?.tags}
|
||||||
{view}
|
{view}
|
||||||
>
|
{extraBadges}
|
||||||
<slot name="badges" slot="badges" />
|
/>
|
||||||
</PostMeta>
|
|
||||||
{#key post.post.url}
|
{#key post.post.url}
|
||||||
<div
|
<div style="grid-area:embed;" class={{ contents: view == 'cozy' }}>
|
||||||
style="grid-area:embed;"
|
|
||||||
class={view == 'list' || view == 'compact' ? '' : 'contents'}
|
|
||||||
>
|
|
||||||
{#if rule != 'hide'}
|
{#if rule != 'hide'}
|
||||||
<PostMedia
|
<PostMedia
|
||||||
post={post.post}
|
post={post.post}
|
||||||
@@ -147,11 +152,11 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{#if view == 'list' || view == 'compact'}
|
{#if view == 'compact'}
|
||||||
<PostMediaCompact
|
<PostMediaCompact
|
||||||
post={post.post}
|
post={post.post}
|
||||||
{type}
|
{type}
|
||||||
class="{$userSettings.leftAlign
|
class="{settings.leftAlign
|
||||||
? 'mr-3'
|
? 'mr-3'
|
||||||
: 'ml-3'} flex-shrink no-list-margin"
|
: 'ml-3'} flex-shrink no-list-margin"
|
||||||
style="grid-area: media;"
|
style="grid-area: media;"
|
||||||
@@ -170,18 +175,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if actions}
|
{#if actions}
|
||||||
<PostActions on:hide {post} style="grid-area: actions;" {view} />
|
<PostActions {onhide} bind: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>
|
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="absolute overflow-hidden inset-0
|
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-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
|
group-focus:inset-y-0.5 group-focus:-inset-x-4 group-focus:sm:-inset-x-5 group-focus:opacity-100
|
||||||
duration-150"
|
duration-150"
|
||||||
/>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PostView } from 'lemmy-js-client'
|
import type { PostView } from 'lemmy-js-client'
|
||||||
import PostVote from './PostVote.svelte'
|
import PostVote from './PostVote.svelte'
|
||||||
import { getInstance, site } from '$lib/lemmy.js'
|
import { site } from '$lib/lemmy.svelte.js'
|
||||||
import {
|
import {
|
||||||
ArrowsUpDown,
|
ArrowsUpDown,
|
||||||
ArrowTopRightOnSquare,
|
ArrowTopRightOnSquare,
|
||||||
Bookmark,
|
Bookmark,
|
||||||
BookmarkSlash,
|
BookmarkSlash,
|
||||||
BugAnt,
|
BugAnt,
|
||||||
ChatBubbleLeftEllipsis,
|
|
||||||
ChatBubbleOvalLeft,
|
ChatBubbleOvalLeft,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
CheckBadge,
|
|
||||||
Clock,
|
Clock,
|
||||||
EllipsisHorizontal,
|
EllipsisHorizontal,
|
||||||
Eye,
|
Eye,
|
||||||
@@ -19,31 +17,27 @@
|
|||||||
Flag,
|
Flag,
|
||||||
GlobeAmericas,
|
GlobeAmericas,
|
||||||
Icon,
|
Icon,
|
||||||
Language,
|
|
||||||
MapPin,
|
MapPin,
|
||||||
Newspaper,
|
Newspaper,
|
||||||
Pencil,
|
Pencil,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
ServerStack,
|
|
||||||
Share,
|
Share,
|
||||||
Star,
|
|
||||||
Trash,
|
Trash,
|
||||||
UserCircle,
|
UserCircle,
|
||||||
XMark,
|
XMark,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
|
||||||
import {
|
import {
|
||||||
amMod,
|
amMod,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
report,
|
report,
|
||||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
|
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 { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
|
||||||
import { setSessionStorage } from '$lib/session.js'
|
import { setSessionStorage } from '$lib/session.js'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { userSettings, type View } from '$lib/settings.js'
|
import { settings, type View } from '$lib/settings.svelte.js'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Menu,
|
Menu,
|
||||||
@@ -53,40 +47,49 @@
|
|||||||
Spinner,
|
Spinner,
|
||||||
toast,
|
toast,
|
||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
import { fediseer, type Data } from '$lib/fediseer/fediseer'
|
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { text } from '$lib/components/translate/translation'
|
|
||||||
import { hidePost, postLink } from './helpers'
|
import { hidePost, postLink } from './helpers'
|
||||||
import { feature } from '$lib/version'
|
import { feature } from '$lib/version'
|
||||||
import Switch from '$lib/components/input/Switch.svelte'
|
import { instanceId, instanceToURL } from '$lib/util.svelte'
|
||||||
import { instanceId, instanceToURL } from '$lib/util'
|
|
||||||
import { publishedToDate } from '$lib/components/util/date'
|
import { publishedToDate } from '$lib/components/util/date'
|
||||||
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
import TextProps from '$lib/components/ui/text/TextProps.svelte'
|
||||||
import { communityLink, userLink } from '$lib/lemmy/generic'
|
import { communityLink, userLink } from '$lib/lemmy/generic'
|
||||||
import RelativeDate, {
|
import RelativeDate, {
|
||||||
formatRelativeDate,
|
formatRelativeDate,
|
||||||
} from '$lib/components/util/RelativeDate.svelte'
|
} from '$lib/components/util/RelativeDate.svelte'
|
||||||
|
import { instance } from '$lib/instance.svelte'
|
||||||
|
|
||||||
export let post: PostView
|
let editing = $state(false)
|
||||||
export let view: View = 'cozy'
|
let saving = $state(false)
|
||||||
export let debug: boolean = false
|
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
|
let localShare = $state(false)
|
||||||
|
|
||||||
let editing = false
|
interface Props {
|
||||||
let saving = false
|
post: PostView
|
||||||
|
view?: View
|
||||||
|
debug?: boolean
|
||||||
|
style?: string
|
||||||
|
onedit?: (post: PostView) => void
|
||||||
|
onhide?: (hide: boolean) => void
|
||||||
|
}
|
||||||
|
|
||||||
let translating = false
|
let {
|
||||||
|
post = $bindable(),
|
||||||
let localShare = false
|
view = 'cozy',
|
||||||
|
debug = $bindable(false),
|
||||||
$: buttonHeight = view == 'compact' ? 'h-7' : 'h-8'
|
style = '',
|
||||||
$: buttonSquare = view == 'compact' ? 'w-7 h-7' : 'w-8 h-8'
|
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>
|
</script>
|
||||||
|
|
||||||
{#if editing}
|
{#if editing}
|
||||||
<Modal bind:open={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')}
|
{#await import('./form/PostForm.svelte')}
|
||||||
<div class="mx-auto h-96 flex justify-center items-center">
|
<div class="mx-auto h-96 flex justify-center items-center">
|
||||||
<Spinner width={32} />
|
<Spinner width={32} />
|
||||||
@@ -95,39 +98,33 @@
|
|||||||
<PostForm
|
<PostForm
|
||||||
edit
|
edit
|
||||||
editingPost={post.post}
|
editingPost={post.post}
|
||||||
on:submit={(e) => {
|
onsubmit={(e) => {
|
||||||
editing = false
|
editing = false
|
||||||
post = e.detail
|
post = e
|
||||||
dispatcher('edit', e.detail)
|
onedit?.(e)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="formtitle">
|
{#snippet formtitle()}
|
||||||
<!-- Have the title not exist at all -->
|
<!-- Have the title not exist at all -->
|
||||||
{''}
|
{''}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
</PostForm>
|
</PostForm>
|
||||||
{/await}
|
{/await}
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if translating}
|
|
||||||
{#await import('$lib/components/translate/Translation.svelte') then { default: Translation }}
|
|
||||||
<Translation bind:open={translating} />
|
|
||||||
{/await}
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<footer
|
<footer
|
||||||
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
|
class="flex flex-row gap-2 items-center flex-shrink-0 {buttonHeight}"
|
||||||
class:flex-row-reverse={$userSettings.posts.reverseActions}
|
class:flex-row-reverse={settings.posts.reverseActions}
|
||||||
style={$$props.style ?? ''}
|
{style}
|
||||||
>
|
>
|
||||||
<PostVote
|
<PostVote
|
||||||
post={post.post}
|
bind:post={post.post}
|
||||||
bind:vote={post.my_vote}
|
vote={post.my_vote}
|
||||||
bind:score={post.counts.score}
|
score={post.counts.score}
|
||||||
bind:upvotes={post.counts.upvotes}
|
upvotes={post.counts.upvotes}
|
||||||
bind:downvotes={post.counts.downvotes}
|
downvotes={post.counts.downvotes}
|
||||||
showCounts={$profile?.user?.local_user_view?.local_user?.show_scores ??
|
showCounts={profile.data?.user?.local_user_view?.local_user?.show_scores ??
|
||||||
true}
|
true}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -137,7 +134,7 @@
|
|||||||
class="!text-inherit h-full px-3 relative"
|
class="!text-inherit h-full px-3 relative"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
target={$userSettings.openLinksInNewTab ? '_blank' : ''}
|
target={settings.openLinksInNewTab ? '_blank' : ''}
|
||||||
title={$t('post.actions.comments')}
|
title={$t('post.actions.comments')}
|
||||||
animations={{ scale: true, large: false }}
|
animations={{ scale: true, large: false }}
|
||||||
>
|
>
|
||||||
@@ -150,16 +147,16 @@
|
|||||||
/>
|
/>
|
||||||
<FormattedNumber number={post.counts.comments} />
|
<FormattedNumber number={post.counts.comments} />
|
||||||
</Button>
|
</Button>
|
||||||
<div class="flex-1" />
|
<div class="flex-1"></div>
|
||||||
|
|
||||||
{#if $userSettings.debugInfo}
|
{#if settings.debugInfo}
|
||||||
{#if debug}
|
{#if debug}
|
||||||
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
|
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
|
||||||
<DebugObject object={post} bind:open={debug} />
|
<DebugObject object={post} bind:open={debug} />
|
||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => (debug = true)}
|
onclick={() => (debug = true)}
|
||||||
title="Debug"
|
title="Debug"
|
||||||
size="custom"
|
size="custom"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
@@ -167,10 +164,12 @@
|
|||||||
class={buttonSquare}
|
class={buttonSquare}
|
||||||
animations={{ scale: true, large: true }}
|
animations={{ scale: true, large: true }}
|
||||||
>
|
>
|
||||||
<Icon src={BugAnt} micro size="16" slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={BugAnt} micro size="16" />
|
||||||
|
{/snippet}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/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
|
<ModerationMenu
|
||||||
size="custom"
|
size="custom"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
@@ -181,12 +180,12 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $profile?.jwt}
|
{#if profile.data?.jwt}
|
||||||
<Button
|
<Button
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if (!$profile?.jwt) return
|
if (!profile.data?.jwt) return
|
||||||
saving = true
|
saving = true
|
||||||
post.saved = await save(post, !post.saved, $profile?.jwt)
|
post.saved = await save(post, !post.saved, profile.data?.jwt)
|
||||||
saving = false
|
saving = false
|
||||||
}}
|
}}
|
||||||
size="custom"
|
size="custom"
|
||||||
@@ -198,12 +197,9 @@
|
|||||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||||
animations={{ scale: true, large: true }}
|
animations={{ scale: true, large: true }}
|
||||||
>
|
>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={post.saved ? BookmarkSlash : Bookmark}
|
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||||
size="16"
|
{/snippet}
|
||||||
mini
|
|
||||||
slot="prefix"
|
|
||||||
/>
|
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -214,21 +210,26 @@
|
|||||||
targetClass="h-full"
|
targetClass="h-full"
|
||||||
title={$t('post.actions.more.label')}
|
title={$t('post.actions.more.label')}
|
||||||
>
|
>
|
||||||
<Button
|
{#snippet target()}
|
||||||
slot="target"
|
<Button
|
||||||
title={$t('post.actions.more.label')}
|
title={$t('post.actions.more.label')}
|
||||||
color="ghost"
|
color="ghost"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
size="custom"
|
size="custom"
|
||||||
class={buttonSquare}
|
class={buttonSquare}
|
||||||
animations={{ scale: true, large: true }}
|
animations={{ scale: true, large: true }}
|
||||||
>
|
>
|
||||||
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
|
{#snippet prefix()}
|
||||||
</Button>
|
<Icon src={EllipsisHorizontal} width={16} micro />
|
||||||
|
{/snippet}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
|
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
|
||||||
<div class="flex flex-row gap-1 items-center">
|
<div class="flex flex-row gap-1 items-center">
|
||||||
<MenuButton class="flex-1">
|
<MenuButton class="flex-1">
|
||||||
<Icon src={Clock} size="16" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Clock} size="16" micro />
|
||||||
|
{/snippet}
|
||||||
<span>
|
<span>
|
||||||
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
|
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
|
||||||
dateStyle: 'short',
|
dateStyle: 'short',
|
||||||
@@ -240,10 +241,12 @@
|
|||||||
publishedToDate(post.post.updated),
|
publishedToDate(post.post.updated),
|
||||||
{
|
{
|
||||||
style: 'long',
|
style: 'long',
|
||||||
}
|
},
|
||||||
)}
|
)}
|
||||||
<MenuButton class="flex-1" aria-label={editedTime}>
|
<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)} />
|
<RelativeDate date={publishedToDate(post.post.updated)} />
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -254,7 +257,9 @@
|
|||||||
<MenuButton
|
<MenuButton
|
||||||
aria-label={$t('aria.vote.score', { default: post.counts.score })}
|
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')}
|
{$t('post.actions.vote.score')}
|
||||||
•
|
•
|
||||||
<FormattedNumber
|
<FormattedNumber
|
||||||
@@ -274,25 +279,17 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||||
<MenuButton link href={userLink(post.creator)}>
|
<MenuButton link href={userLink(post.creator)}>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={UserCircle}
|
<Icon src={UserCircle} size="16" micro class="flex-shrink-0" />
|
||||||
size="16"
|
{/snippet}
|
||||||
micro
|
|
||||||
slot="prefix"
|
|
||||||
class="flex-shrink-0"
|
|
||||||
/>
|
|
||||||
<TextProps wrap="no-wrap">
|
<TextProps wrap="no-wrap">
|
||||||
{post.creator.name}
|
{post.creator.name}
|
||||||
</TextProps>
|
</TextProps>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuButton link href={communityLink(post.community)}>
|
<MenuButton link href={communityLink(post.community)}>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={Newspaper}
|
<Icon src={Newspaper} size="16" micro class="flex-shrink-0" />
|
||||||
size="16"
|
{/snippet}
|
||||||
micro
|
|
||||||
slot="prefix"
|
|
||||||
class="flex-shrink-0"
|
|
||||||
/>
|
|
||||||
<TextProps wrap="no-wrap">
|
<TextProps wrap="no-wrap">
|
||||||
{post.community.title}
|
{post.community.title}
|
||||||
</TextProps>
|
</TextProps>
|
||||||
@@ -300,51 +297,61 @@
|
|||||||
<MenuDivider>
|
<MenuDivider>
|
||||||
{$t('post.actions.more.actions')}
|
{$t('post.actions.more.actions')}
|
||||||
</MenuDivider>
|
</MenuDivider>
|
||||||
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
{#if profile.data?.user && profile.data?.jwt && profile.data.user.local_user_view.person.id == post.creator.id}
|
||||||
<MenuButton on:click={() => (editing = true)}>
|
<MenuButton onclick={() => (editing = true)}>
|
||||||
<Icon src={PencilSquare} size="16" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={PencilSquare} size="16" micro />
|
||||||
|
{/snippet}
|
||||||
{$t('post.actions.more.edit')}
|
{$t('post.actions.more.edit')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile?.jwt}
|
{#if profile.data?.jwt}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if ($profile?.jwt)
|
if (profile.data?.jwt)
|
||||||
post.read = await markAsRead(post.post, !post.read, $profile.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
|
{post.read
|
||||||
? $t('post.actions.more.markUnread')
|
? $t('post.actions.more.markUnread')
|
||||||
: $t('post.actions.more.markRead')}
|
: $t('post.actions.more.markRead')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
navigator.share?.({
|
navigator.share?.({
|
||||||
url: localShare
|
url: localShare
|
||||||
? `${instanceToURL(getInstance())}/post/${post.post.id}`
|
? `${instanceToURL(instance.data)}/post/${post.post.id}`
|
||||||
: post.post.ap_id,
|
: post.post.ap_id,
|
||||||
}) ??
|
}) ??
|
||||||
navigator.clipboard.writeText(
|
navigator.clipboard.writeText(
|
||||||
localShare
|
localShare
|
||||||
? `${instanceToURL(getInstance())}/post/${post.post.id}`
|
? `${instanceToURL(instance.data)}/post/${post.post.id}`
|
||||||
: post.post.ap_id
|
: post.post.ap_id,
|
||||||
)
|
)
|
||||||
toast({ content: $t('toast.copied') })
|
toast({ content: $t('toast.copied') })
|
||||||
}}
|
}}
|
||||||
class="flex-1 !py-0"
|
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')}
|
{$t('post.actions.more.share')}
|
||||||
<div class="flex-1" />
|
<div class="flex-1"></div>
|
||||||
{#if !post.post.local}
|
{#if !post.post.local}
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<Button
|
<Button
|
||||||
color={!localShare ? 'primary' : 'secondary'}
|
color={!localShare ? 'primary' : 'secondary'}
|
||||||
size="square-md"
|
size="square-md"
|
||||||
roundingSide="left"
|
roundingSide="left"
|
||||||
on:click={() => (localShare = false)}
|
onclick={() => (localShare = false)}
|
||||||
title={$t('filter.location.global')}
|
title={$t('filter.location.global')}
|
||||||
>
|
>
|
||||||
<Icon src={GlobeAmericas} size="16" micro />
|
<Icon src={GlobeAmericas} size="16" micro />
|
||||||
@@ -353,7 +360,7 @@
|
|||||||
color={localShare ? 'primary' : 'secondary'}
|
color={localShare ? 'primary' : 'secondary'}
|
||||||
size="square-md"
|
size="square-md"
|
||||||
roundingSide="right"
|
roundingSide="right"
|
||||||
on:click={() => (localShare = true)}
|
onclick={() => (localShare = true)}
|
||||||
title={$t('filter.location.local')}
|
title={$t('filter.location.local')}
|
||||||
>
|
>
|
||||||
<Icon src={MapPin} size="16" micro />
|
<Icon src={MapPin} size="16" micro />
|
||||||
@@ -361,24 +368,12 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if post.post.body && $userSettings.translator}
|
{#if profile.data?.jwt}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
// @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={() => {
|
|
||||||
setSessionStorage('postDraft', {
|
setSessionStorage('postDraft', {
|
||||||
body: `${
|
body: `${
|
||||||
$userSettings.crosspostOriginalLink
|
settings.crosspostOriginalLink
|
||||||
? `cross-posted from: ${post.post.ap_id}`
|
? `cross-posted from: ${post.post.ap_id}`
|
||||||
: ``
|
: ``
|
||||||
}\n${
|
}\n${
|
||||||
@@ -397,52 +392,58 @@
|
|||||||
goto('/create/post?crosspost=true')
|
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')}
|
{$t('post.actions.more.crosspost')}
|
||||||
</MenuButton>
|
</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
|
<MenuButton
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if ($profile?.jwt)
|
if (profile.data?.jwt)
|
||||||
post.post.deleted = await deleteItem(
|
post.post.deleted = await deleteItem(
|
||||||
post,
|
post,
|
||||||
!post.post.deleted,
|
!post.post.deleted,
|
||||||
$profile.jwt
|
profile.data.jwt,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
>
|
>
|
||||||
<Icon src={Trash} size="16" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Trash} size="16" micro />
|
||||||
|
{/snippet}
|
||||||
{post.post.deleted
|
{post.post.deleted
|
||||||
? $t('post.actions.more.restore')
|
? $t('post.actions.more.restore')
|
||||||
: $t('post.actions.more.delete')}
|
: $t('post.actions.more.delete')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $profile.user?.local_user_view.person.id != post.creator.id}
|
{#if profile.data.user?.local_user_view.person.id != post.creator.id}
|
||||||
{#if feature('hidePosts', $site?.version)}
|
{#if feature('hidePosts', site.data?.version)}
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
if (!$profile?.jwt) return
|
if (!profile.data?.jwt) return
|
||||||
const hidden = await hidePost(
|
const hidden = await hidePost(
|
||||||
post.post.id,
|
post.post.id,
|
||||||
!post.hidden,
|
!post.hidden,
|
||||||
$profile?.jwt
|
profile.data?.jwt,
|
||||||
)
|
)
|
||||||
post.hidden = hidden
|
post.hidden = hidden
|
||||||
if (hidden) {
|
if (hidden) onhide?.(hidden)
|
||||||
dispatcher('hide', hidden)
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
>
|
>
|
||||||
<Icon slot="prefix" src={XMark} size="16" micro />
|
{#snippet prefix()}
|
||||||
|
<Icon src={XMark} size="16" micro />
|
||||||
|
{/snippet}
|
||||||
{post.hidden
|
{post.hidden
|
||||||
? $t('post.actions.more.unhide')
|
? $t('post.actions.more.unhide')
|
||||||
: $t('post.actions.more.hide')}
|
: $t('post.actions.more.hide')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
<MenuButton onclick={() => report(post)} color="danger-subtle">
|
||||||
<Icon src={Flag} width={16} micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Flag} width={16} micro />
|
||||||
|
{/snippet}
|
||||||
{$t('moderation.report')}
|
{$t('moderation.report')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,51 +1,60 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
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 { Button } from 'mono-svelte'
|
||||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let body: string
|
const MAX_HEIGHT = 192
|
||||||
export let view: View = 'cozy'
|
|
||||||
export let clickThrough = false
|
|
||||||
let htmlElement = 'div'
|
|
||||||
|
|
||||||
export { htmlElement as element }
|
let element = $state<Element>()
|
||||||
|
|
||||||
let expanded = false
|
function isOverflown(element: Element) {
|
||||||
let element: Element
|
if (!element) return false
|
||||||
|
|
||||||
function isOverflown(element: Element, body: string = '') {
|
return element.scrollHeight > MAX_HEIGHT
|
||||||
if (!element) return
|
|
||||||
let overflows =
|
|
||||||
element.scrollHeight > element.clientHeight ||
|
|
||||||
element.scrollWidth > element.clientWidth
|
|
||||||
|
|
||||||
if (!overflows) expanded = true
|
|
||||||
else expanded = false
|
|
||||||
|
|
||||||
return overflows
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: 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>
|
</script>
|
||||||
|
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={htmlElement}
|
this={htmlElement}
|
||||||
style={$$props.style ?? ''}
|
{style}
|
||||||
class="{!expanded
|
class="{!expanded
|
||||||
? ` overflow-hidden
|
? ` overflow-hidden
|
||||||
bg-gradient-to-b text-transparent from-slate-600 via-slate-600
|
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
|
dark:from-zinc-400 dark:via-zinc-400 bg-clip-text z-0 max-h-36`
|
||||||
${view == 'list' ? `max-h-24` : 'max-h-48'}`
|
: 'text-slate-600 dark:text-zinc-400 max-h-full'} text-base {clazz}"
|
||||||
: 'text-slate-600 dark:text-zinc-400 max-h-full'} text-base {$$props.class ??
|
|
||||||
''}"
|
|
||||||
class:pointer-events-none={!clickThrough}
|
class:pointer-events-none={!clickThrough}
|
||||||
bind:this={element}
|
bind:this={element}
|
||||||
>
|
>
|
||||||
<Markdown inline={!expanded} source={expanded ? body : body.slice(0, 1000)} />
|
<Markdown inline={!expanded} source={expanded ? body : body.slice(0, 1000)} />
|
||||||
{#if overflows}
|
{#if overflows}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => (expanded = !expanded)}
|
onclick={() => (expanded = !expanded)}
|
||||||
size="square-sm"
|
size="square-sm"
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
class="text-black dark:text-white absolute z-10 isolate pointer-events-auto bottom-0 {expanded
|
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 {
|
export interface Tag {
|
||||||
content: string
|
content: string
|
||||||
color?: string
|
color?: string
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
])
|
])
|
||||||
|
|
||||||
export const parseTags = (
|
export const parseTags = (
|
||||||
title?: string
|
title?: string,
|
||||||
): { tags: Tag[]; title?: string } => {
|
): { tags: Tag[]; title?: string } => {
|
||||||
if (!title) return { tags: [] }
|
if (!title) return { tags: [] }
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
extracted.push(
|
extracted.push(
|
||||||
textToTag.get(content) ?? {
|
textToTag.get(content) ?? {
|
||||||
content: content,
|
content: content,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
return ''
|
return ''
|
||||||
@@ -61,43 +61,61 @@
|
|||||||
Trash,
|
Trash,
|
||||||
PaperAirplane,
|
PaperAirplane,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { getInstance } from '$lib/lemmy.js'
|
|
||||||
import ShieldIcon from '../moderation/ShieldIcon.svelte'
|
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 Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { Pencil, type IconSource } from 'svelte-hero-icons'
|
import { Pencil, type IconSource } from 'svelte-hero-icons'
|
||||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||||
import { publishedToDate } from '$lib/components/util/date'
|
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
|
interface Props {
|
||||||
export let showCommunity: boolean = true
|
community?: Community | undefined
|
||||||
export let subscribed: SubscribedType | undefined = undefined
|
showCommunity?: boolean
|
||||||
|
subscribed?: SubscribedType | undefined
|
||||||
export let user: Person | undefined = undefined
|
user?: Person | undefined
|
||||||
export let published: Date | undefined = undefined
|
published?: Date | undefined
|
||||||
export let title: string | undefined = undefined
|
title?: string | undefined
|
||||||
export let id: number | undefined = undefined
|
id?: number | undefined
|
||||||
export let read: boolean = false
|
read?: boolean
|
||||||
export let edited: string | undefined = undefined
|
edited?: string | undefined
|
||||||
|
view?: View
|
||||||
export let view: View = 'cozy'
|
// Badges
|
||||||
|
badges?: any
|
||||||
// Badges
|
tags?: Tag[]
|
||||||
export let badges = {
|
style?: string
|
||||||
nsfw: false,
|
titleClass?: string
|
||||||
saved: false,
|
extraBadges?: import('svelte').Snippet
|
||||||
featured: false,
|
|
||||||
deleted: false,
|
|
||||||
removed: false,
|
|
||||||
locked: false,
|
|
||||||
moderator: false,
|
|
||||||
admin: false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export let tags: Tag[] = []
|
let {
|
||||||
|
community = $bindable(undefined),
|
||||||
let popoverOpen = false
|
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>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -109,34 +127,33 @@
|
|||||||
? 'grid-rows-2'
|
? 'grid-rows-2'
|
||||||
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
: 'grid-rows-1'} text-xs min-w-0 max-w-full"
|
||||||
class:compact={view == 'compact'}
|
class:compact={view == 'compact'}
|
||||||
style={$$props.style ?? ''}
|
{style}
|
||||||
>
|
>
|
||||||
{#if showCommunity && community && subscribed && showCommunity}
|
{#if showCommunity && community}
|
||||||
<Popover bind:open={popoverOpen} manual>
|
<Popover autoClose={false} popoverClass="backdrop-blur-xl rounded-2xl">
|
||||||
<button
|
{#snippet target()}
|
||||||
on:click={() => (popoverOpen = !popoverOpen)}
|
<button
|
||||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
class="row-span-2 flex-shrink-0 mr-2 self-center group/btn bg-slate-200 dark:bg-zinc-800 rounded-full"
|
||||||
slot="target"
|
>
|
||||||
>
|
<Avatar
|
||||||
<Avatar
|
url={community?.icon}
|
||||||
url={community.icon}
|
width={view == 'compact' ? 24 : 32}
|
||||||
width={view == 'compact' ? 24 : 32}
|
alt={community?.name}
|
||||||
alt={community.name}
|
class="group-hover/btn:scale-90 group-active/btn:scale-[.85] transition-transform"
|
||||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
/>
|
||||||
/>
|
</button>
|
||||||
</button>
|
{/snippet}
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
{#snippet popover()}
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
{#if community && subscribed}
|
||||||
<div
|
<div
|
||||||
slot="popover"
|
class="bg-white/80 dark:bg-zinc-900/90 border border-slate-200 dark:border-zinc-800 rounded-2xl shadow-xl p-4
|
||||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
max-w-2xl w-full max-h-[32rem] overflow-auto"
|
||||||
on:click|stopPropagation={() => {}}
|
>
|
||||||
>
|
<CommunityHeader {community} {subscribed} />
|
||||||
<CommunityHeader bind:community bind:subscribed />
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
|
{/snippet}
|
||||||
</Popover>
|
</Popover>
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if showCommunity && community}
|
{#if showCommunity && community}
|
||||||
<CommunityLink
|
<CommunityLink
|
||||||
@@ -171,14 +188,14 @@
|
|||||||
avatar={!showCommunity}
|
avatar={!showCommunity}
|
||||||
class="flex-shrink "
|
class="flex-shrink "
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="badges">
|
{#snippet extraBadges()}
|
||||||
{#if badges.moderator}
|
{#if badges.moderator}
|
||||||
<ShieldIcon filled width={14} class="text-green-500" />
|
<ShieldIcon filled width={14} class="text-green-500" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if badges.admin}
|
{#if badges.admin}
|
||||||
<ShieldIcon filled width={14} class="text-red-500" />
|
<ShieldIcon filled width={14} class="text-red-500" />
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
</UserLink>
|
</UserLink>
|
||||||
</address>
|
</address>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -210,13 +227,13 @@
|
|||||||
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
||||||
>
|
>
|
||||||
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
||||||
<svelte:fragment slot="icon">
|
{#snippet icon()}
|
||||||
{#if tag.icon}
|
{#if tag.icon}
|
||||||
<Icon src={tag.icon} micro size="14" />
|
<Icon src={tag.icon} micro size="14" />
|
||||||
{:else}
|
{:else}
|
||||||
<Icon src={Tag} micro size="14" />
|
<Icon src={Tag} micro size="14" />
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:fragment>
|
{/snippet}
|
||||||
{tag.content}
|
{tag.content}
|
||||||
</Badge>
|
</Badge>
|
||||||
</a>
|
</a>
|
||||||
@@ -224,7 +241,9 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if badges.nsfw}
|
{#if badges.nsfw}
|
||||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
<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')}
|
{$t('post.badges.nsfw')}
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -234,7 +253,9 @@
|
|||||||
color="yellow-subtle"
|
color="yellow-subtle"
|
||||||
allowIconOnly
|
allowIconOnly
|
||||||
>
|
>
|
||||||
<Icon src={Bookmark} micro size="14" slot="icon" />
|
{#snippet icon()}
|
||||||
|
<Icon src={Bookmark} micro size="14" />
|
||||||
|
{/snippet}
|
||||||
{$t('post.badges.saved')}
|
{$t('post.badges.saved')}
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -244,19 +265,25 @@
|
|||||||
color="yellow-subtle"
|
color="yellow-subtle"
|
||||||
allowIconOnly
|
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>
|
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{#if badges.removed}
|
{#if badges.removed}
|
||||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
<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>
|
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{#if badges.deleted}
|
{#if badges.deleted}
|
||||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
<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>
|
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -266,34 +293,38 @@
|
|||||||
color="green-subtle"
|
color="green-subtle"
|
||||||
allowIconOnly
|
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>
|
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
<slot name="badges" />
|
{@render extraBadges?.()}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
{#if title && id}
|
{#if title && id}
|
||||||
<a
|
<a
|
||||||
href="/post/{getInstance()}/{id}"
|
href="/post/{encodeURIComponent(instance.data)}/{id}"
|
||||||
class="inline hover:underline
|
class="inline hover:underline
|
||||||
hover:text-primary-900 hover:dark:text-primary-100 transition-colors max-[480px]:!mt-0
|
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-display font-semibold'
|
||||||
: 'font-medium'} {$$props.titleClass ?? ''}"
|
: 'font-medium'} {titleClass}"
|
||||||
class:text-slate-600={$userSettings.markReadPosts && read}
|
class:text-slate-600={settings.markReadPosts && read}
|
||||||
class:dark:text-zinc-400={$userSettings.markReadPosts && read}
|
class:dark:text-zinc-400={settings.markReadPosts && read}
|
||||||
class:text-base={view == 'compact'}
|
class:text-base={view == 'compact'}
|
||||||
class:text-lg={view != 'compact'}
|
class:text-lg={view != 'compact'}
|
||||||
style="grid-area: title;"
|
style="grid-area: title;"
|
||||||
data-sveltekit-preload-data="tap"
|
data-sveltekit-preload-data="tap"
|
||||||
>
|
>
|
||||||
<Markdown
|
{#if title}
|
||||||
source={title}
|
<Markdown
|
||||||
inline
|
source={title}
|
||||||
noStyle
|
inline
|
||||||
class={view == 'compact' ? '' : 'leading-[1.3]'}
|
noStyle
|
||||||
></Markdown>
|
class={view == 'compact' ? '' : 'leading-[1.3]'}
|
||||||
|
></Markdown>
|
||||||
|
{/if}
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
<div style="grid-area: title; margin: 0;"></div>
|
<div style="grid-area: title; margin: 0;"></div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" module>
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
export const voteColor = (vote: number, border: boolean = false) =>
|
export const voteColor = (vote: number, border: boolean = false) =>
|
||||||
vote == 1
|
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`
|
? `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 = (
|
export const shouldShowVoteColor = (
|
||||||
vote: number,
|
vote: number,
|
||||||
type: 'upvotes' | 'downvotes'
|
type: 'upvotes' | 'downvotes',
|
||||||
): string =>
|
): string =>
|
||||||
(vote == -1 && type == 'downvotes') || (vote == 1 && type == 'upvotes')
|
(vote == -1 && type == 'downvotes') || (vote == 1 && type == 'upvotes')
|
||||||
? voteColor(vote)
|
? voteColor(vote)
|
||||||
@@ -20,36 +20,48 @@
|
|||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import type { Post } from 'lemmy-js-client'
|
import type { Post } from 'lemmy-js-client'
|
||||||
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
|
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 { vote as voteItem } from '$lib/lemmy/contentview.js'
|
||||||
import { Button, Popover, buttonColor, toast } from 'mono-svelte'
|
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 { fade, fly } from 'svelte/transition'
|
||||||
import { backOut } from 'svelte/easing'
|
import { backOut } from 'svelte/easing'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
|
||||||
export let post: Post
|
interface Props {
|
||||||
export let vote: number = 0
|
post: Post
|
||||||
export let score: number
|
vote?: number
|
||||||
export let upvotes: number = 0
|
score: number
|
||||||
export let downvotes: number = 0
|
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
|
let oldScore = score
|
||||||
|
|
||||||
const castVote = async (newVote: number) => {
|
const castVote = async (newVote: number) => {
|
||||||
if (!$profile?.jwt) {
|
if (!profile.data?.jwt) {
|
||||||
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loading = true
|
loading = true
|
||||||
oldScore = score
|
oldScore = score
|
||||||
vote = newVote
|
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' })
|
toast({ content: errorMessage(e), type: 'error' })
|
||||||
return { upvotes: 0, downvotes: 0, score: 0 }
|
return { upvotes: 0, downvotes: 0, score: 0 }
|
||||||
})
|
})
|
||||||
@@ -58,7 +70,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot {vote} {score}>
|
{#if children}{@render children({ vote, score })}{:else}
|
||||||
<div
|
<div
|
||||||
class="{buttonColor.ghost} rounded-full h-full font-medium flex items-center *:p-2
|
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
|
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')}
|
aria-label={$t('aria.vote.group')}
|
||||||
>
|
>
|
||||||
<button
|
<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
|
class="flex items-center gap-0.5 transition-colors relative z-0
|
||||||
{vote == 1
|
{vote == 1
|
||||||
? shouldShowVoteColor(vote, 'upvotes')
|
? shouldShowVoteColor(vote, 'upvotes')
|
||||||
@@ -94,9 +106,9 @@
|
|||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{#if $site?.site_view.local_site.enable_downvotes ?? true}
|
{#if site.data?.site_view.local_site.enable_downvotes ?? true}
|
||||||
<button
|
<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
|
class="flex items-center flex-row-reverse gap-0.5 transition-colors
|
||||||
{vote == -1
|
{vote == -1
|
||||||
? shouldShowVoteColor(vote, 'downvotes')
|
? shouldShowVoteColor(vote, 'downvotes')
|
||||||
@@ -122,4 +134,4 @@
|
|||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</slot>
|
{/if}
|
||||||
@@ -1,28 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||||
import Placeholder from '$lib/components/ui/Placeholder.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 type { PostView } from 'lemmy-js-client'
|
||||||
import { Badge, Button } from 'mono-svelte'
|
import { Badge, Button } from 'mono-svelte'
|
||||||
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
|
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[]
|
interface Props {
|
||||||
export let community: boolean = false
|
posts: PostView[]
|
||||||
export let feedData: any
|
community?: boolean
|
||||||
let etc = $$restProps
|
feedData: any
|
||||||
|
children?: import('svelte').Snippet
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
$: combinedPosts = combineCrossposts(posts)
|
let {
|
||||||
|
posts = $bindable(),
|
||||||
let viewPost: number = -1
|
community = false,
|
||||||
|
feedData,
|
||||||
|
children,
|
||||||
|
...rest
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul
|
<ul
|
||||||
class="flex flex-col list-none {$userSettings.view == 'card'
|
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
|
||||||
? 'gap-3 md:gap-4'
|
|
||||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
|
||||||
>
|
>
|
||||||
{#if posts?.length == 0}
|
{#if posts?.length == 0}
|
||||||
<div class="h-full grid place-items-center">
|
<div class="h-full grid place-items-center">
|
||||||
@@ -32,77 +34,30 @@
|
|||||||
description="There are no posts that match this filter."
|
description="There are no posts that match this filter."
|
||||||
>
|
>
|
||||||
<Button href="/communities">
|
<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>
|
<span>Follow some communities</span>
|
||||||
</Button>
|
</Button>
|
||||||
</Placeholder>
|
</Placeholder>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each combinedPosts as post, index}
|
{#each posts as post, index (post.post.id)}
|
||||||
{#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
|
<li class="relative post-container">
|
||||||
<li class="relative post-container">
|
<Post
|
||||||
<Post
|
hideCommunity={community}
|
||||||
hideCommunity={community}
|
view={(post.post.featured_community || post.post.featured_local) &&
|
||||||
view={(post.post.featured_community || post.post.featured_local) &&
|
settings.posts.compactFeatured
|
||||||
$userSettings.posts.compactFeatured
|
? 'compact'
|
||||||
? 'compact'
|
: settings.view}
|
||||||
: $userSettings.view}
|
{post}
|
||||||
{post}
|
class="transition-all duration-250"
|
||||||
class="transition-all duration-250"
|
onhide={() => {
|
||||||
on:hide={() => {
|
posts = posts.toSpliced(index, 1)
|
||||||
posts = posts.toSpliced(index, 1)
|
}}
|
||||||
}}
|
/>
|
||||||
>
|
</li>
|
||||||
<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}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -1,81 +1,53 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { browser } from '$app/environment'
|
||||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
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 Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { client } from '$lib/lemmy.svelte'
|
||||||
import type {
|
import {
|
||||||
GetPostsResponse,
|
postFeeds,
|
||||||
ListingType,
|
type PostFeed,
|
||||||
PostView,
|
type PostFeedID,
|
||||||
SortType,
|
} from '$lib/lemmy/postfeed.svelte'
|
||||||
} from 'lemmy-js-client'
|
import { settings } from '$lib/settings.svelte.js'
|
||||||
import { Badge, Button } from 'mono-svelte'
|
import { t } from '$lib/translations'
|
||||||
|
import type { PostView } from 'lemmy-js-client'
|
||||||
|
import { Button } from 'mono-svelte'
|
||||||
|
import { onMount, tick, untrack } from 'svelte'
|
||||||
import {
|
import {
|
||||||
ArchiveBox,
|
ArchiveBox,
|
||||||
ChevronDoubleUp,
|
ChevronDoubleUp,
|
||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
Icon,
|
Icon,
|
||||||
Minus,
|
|
||||||
Plus,
|
Plus,
|
||||||
} from 'svelte-hero-icons'
|
} 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 InfiniteScroll from 'svelte-infinite-scroll'
|
||||||
import type { Readable } from 'svelte/motion'
|
import VirtualList from '$lib/components/render/VirtualList.svelte'
|
||||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
|
||||||
|
|
||||||
export let posts: PostView[]
|
interface Props {
|
||||||
export let community: boolean = false
|
posts: PostView[]
|
||||||
export let feedId: PostFeedID
|
community?: boolean
|
||||||
|
feedId: PostFeedID
|
||||||
let virtualItemEls: HTMLElement[] = []
|
feedData: PostFeed['data']
|
||||||
let virtualListEl: HTMLElement | undefined = undefined
|
children?: import('svelte').Snippet
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (posts.length && virtualListEl)
|
let {
|
||||||
$virtualizer.setOptions({
|
posts = $bindable(),
|
||||||
scrollMargin: virtualListEl?.offsetTop,
|
community = false,
|
||||||
count: posts.length,
|
feedId,
|
||||||
})
|
feedData = $bindable(),
|
||||||
|
children,
|
||||||
|
}: Props = $props()
|
||||||
|
|
||||||
afterNavigate(() => {
|
let listEl = $state<HTMLUListElement>()
|
||||||
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
|
let listComp = $state<{
|
||||||
})
|
scrollToIndex: (index: number, window?: boolean) => void
|
||||||
|
}>()
|
||||||
|
|
||||||
export let feedData: PostFeed['data']
|
let error: any = $state(undefined)
|
||||||
|
let loading = $state(false)
|
||||||
let error: any = undefined
|
let hasMore = $state(true)
|
||||||
let loading = false
|
|
||||||
let hasMore = true
|
|
||||||
|
|
||||||
async function loadMore() {
|
async function loadMore() {
|
||||||
if (!hasMore || loading) return
|
if (!hasMore || loading) return
|
||||||
@@ -106,11 +78,9 @@
|
|||||||
hasMore = newPosts.posts.length != 0
|
hasMore = newPosts.posts.length != 0
|
||||||
|
|
||||||
feedData.cursor.next = newPosts.next_page
|
feedData.cursor.next = newPosts.next_page
|
||||||
feedData.posts.posts = [...feedData.posts.posts, ...newPosts.posts]
|
feedData.posts.posts.push(...newPosts.posts)
|
||||||
|
|
||||||
postFeeds.updateFeed(feedId, {
|
postFeeds.value[feedId].data = feedData
|
||||||
data: feedData,
|
|
||||||
})
|
|
||||||
|
|
||||||
loading = false
|
loading = false
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -128,127 +98,112 @@
|
|||||||
|
|
||||||
if (!id) return
|
if (!id) return
|
||||||
|
|
||||||
postFeeds.updateFeed(feedId, {
|
postFeeds.value[feedId].lastSeen = Number(id)
|
||||||
lastSeen: Number(id),
|
|
||||||
})
|
|
||||||
observer.unobserve(element)
|
observer.unobserve(element)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const observer = new IntersectionObserver(callback, {
|
const observer = new IntersectionObserver(callback, {
|
||||||
root: null,
|
|
||||||
rootMargin: '0px',
|
|
||||||
threshold: 0.5,
|
threshold: 0.5,
|
||||||
})
|
})
|
||||||
|
|
||||||
const elements = document.querySelectorAll('.post-container')
|
const observePost = (node: Node) => {
|
||||||
elements.forEach((el) => observer.observe(el))
|
if (
|
||||||
|
node instanceof HTMLElement &&
|
||||||
|
node.classList.contains('post-container')
|
||||||
|
)
|
||||||
|
observer.observe(node)
|
||||||
|
}
|
||||||
|
|
||||||
const postContainer = document.querySelector('#feed')
|
const unobservePost = (node: Node) => {
|
||||||
if (postContainer) {
|
if (
|
||||||
const mutationObserver = new MutationObserver((mutations) => {
|
node instanceof HTMLElement &&
|
||||||
mutations.forEach((mutation) => {
|
node.classList.contains('post-container')
|
||||||
if (mutation.type === 'childList') {
|
)
|
||||||
mutation.addedNodes.forEach((node) => {
|
observer.unobserve(node)
|
||||||
if (
|
}
|
||||||
node instanceof HTMLElement &&
|
|
||||||
node.classList.contains('post-container')
|
document.querySelectorAll('.post-container').forEach(observePost)
|
||||||
) {
|
|
||||||
observer.observe(node)
|
const feed = document.getElementById('feed')
|
||||||
}
|
if (!feed) return
|
||||||
})
|
|
||||||
mutation.removedNodes.forEach((node) => {
|
new MutationObserver((mutations) => {
|
||||||
if (
|
mutations.forEach(({ addedNodes, removedNodes }) => {
|
||||||
node instanceof HTMLElement &&
|
addedNodes.forEach(observePost)
|
||||||
node.classList.contains('post-container')
|
removedNodes.forEach(unobservePost)
|
||||||
) {
|
|
||||||
observer.unobserve(node)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
}).observe(feed, { childList: true, subtree: false })
|
||||||
|
})
|
||||||
|
|
||||||
mutationObserver.observe(postContainer, {
|
$effect(() => {
|
||||||
childList: true,
|
if (listComp) {
|
||||||
subtree: true,
|
untrack(() => {
|
||||||
|
if (postFeeds.value[feedId].lastSeen != 0) {
|
||||||
|
listComp?.scrollToIndex(postFeeds.value[feedId].lastSeen, true)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
await tick()
|
|
||||||
$virtualizer.measure()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
<ul class="flex flex-col list-none" bind:this={listEl}>
|
||||||
|
{#key posts}
|
||||||
<ul
|
{#if posts?.length == 0}
|
||||||
class="flex flex-col list-none {$userSettings.view == 'card'
|
<div class="h-full grid place-items-center">
|
||||||
? 'gap-3 md:gap-4'
|
<Placeholder
|
||||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
icon={ArchiveBox}
|
||||||
>
|
title="No posts"
|
||||||
{#if posts?.length == 0}
|
description="There are no posts that match this filter."
|
||||||
<div class="h-full grid place-items-center">
|
>
|
||||||
<Placeholder
|
<Button href="/communities">
|
||||||
icon={ArchiveBox}
|
{#snippet prefix()}
|
||||||
title="No posts"
|
<Icon src={Plus} size="16" mini />
|
||||||
description="There are no posts that match this filter."
|
{/snippet}
|
||||||
>
|
<span>Follow some communities</span>
|
||||||
<Button href="/communities">
|
</Button>
|
||||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
</Placeholder>
|
||||||
<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}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{:else}
|
||||||
{/if}
|
<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}
|
{#if error}
|
||||||
<div
|
<div
|
||||||
class="flex flex-col justify-center items-center
|
class="flex flex-col justify-center items-center
|
||||||
@@ -263,18 +218,20 @@
|
|||||||
color="primary"
|
color="primary"
|
||||||
{loading}
|
{loading}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
on:click={() => loadMore()}
|
onclick={() => loadMore()}
|
||||||
>
|
>
|
||||||
{$t('message.retry')}
|
{$t('message.retry')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{:else if hasMore}
|
{:else if hasMore}
|
||||||
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
<div class="w-full flex flex-col gap-2 animate-pulse pt-6">
|
||||||
<div class="w-96 max-w-full h-8"></div>
|
<div
|
||||||
<div class="w-full h-48"></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="!bg-transparent h-8 flex justify-between">
|
||||||
<div class="w-48 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"></div>
|
<div class="w-24 h-8 bg-slate-100 dark:bg-zinc-800 rounded-md"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -284,23 +241,23 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
community_name: feedData.community_name ?? 'undefined',
|
community_name: feedData.community_name ?? 'undefined',
|
||||||
})}
|
})}
|
||||||
<Button slot="action" color="tertiary">
|
{#snippet action()}
|
||||||
<Icon src={ChevronDoubleUp} size="16" micro slot="prefix" />
|
<Button color="tertiary">
|
||||||
{$t('routes.post.scrollToTop')}
|
{#snippet prefix()}
|
||||||
</Button>
|
<Icon src={ChevronDoubleUp} size="16" micro />
|
||||||
|
{/snippet}
|
||||||
|
{$t('routes.post.scrollToTop')}
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
</EndPlaceholder>
|
</EndPlaceholder>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
.skeleton * {
|
|
||||||
@apply bg-slate-100 dark:bg-zinc-800 rounded-md;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes popIn {
|
@keyframes popIn {
|
||||||
from {
|
from {
|
||||||
transform: translateY(24px);
|
transform: translateY(24px);
|
||||||
|
|||||||
+6
-6
@@ -1,6 +1,6 @@
|
|||||||
import { userSettings } from "$lib/settings"
|
import { settings } from '$lib/settings.svelte'
|
||||||
import type { PostView } from "lemmy-js-client"
|
import type { PostView } from 'lemmy-js-client'
|
||||||
import { get } from "svelte/store"
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export type PostViewWithCrossposts = PostView & {
|
export type PostViewWithCrossposts = PostView & {
|
||||||
withCrossposts: true
|
withCrossposts: true
|
||||||
@@ -29,8 +29,8 @@ export const combineCrossposts = (
|
|||||||
posts?.forEach((post) => {
|
posts?.forEach((post) => {
|
||||||
if (
|
if (
|
||||||
!post ||
|
!post ||
|
||||||
(get(userSettings).hidePosts.deleted && post.post.deleted) ||
|
(settings.hidePosts.deleted && post.post.deleted) ||
|
||||||
(get(userSettings).hidePosts.removed && post.post.removed)
|
(settings.hidePosts.removed && post.post.removed)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if (!post?.post?.url) {
|
if (!post?.post?.url) {
|
||||||
@@ -54,4 +54,4 @@ export const combineCrossposts = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { run, preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
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 type { Community, Post, PostView } from 'lemmy-js-client'
|
||||||
import { Select, Spinner, Switch, toast } from 'mono-svelte'
|
import { Select, Spinner, Switch, toast } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
@@ -14,9 +16,9 @@
|
|||||||
Link,
|
Link,
|
||||||
XMark,
|
XMark,
|
||||||
} from 'svelte-hero-icons'
|
} 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 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 { Checkbox, TextInput } from 'mono-svelte'
|
||||||
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
||||||
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
|
||||||
@@ -32,49 +34,63 @@
|
|||||||
} from '$lib/components/error/ErrorContainer.svelte'
|
} from '$lib/components/error/ErrorContainer.svelte'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
||||||
|
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||||
|
|
||||||
export let edit = false
|
interface Props {
|
||||||
|
edit?: boolean
|
||||||
/**
|
/**
|
||||||
* The post to edit
|
* The post to edit
|
||||||
*/
|
*/
|
||||||
export let editingPost: Post | undefined = undefined
|
editingPost?: Post | undefined
|
||||||
|
passedCommunity?: Community | undefined
|
||||||
export let passedCommunity: Community | undefined = undefined
|
passedData?: {
|
||||||
|
community: Community | null
|
||||||
export let data: {
|
title: string
|
||||||
community: Community | null
|
body: string
|
||||||
title: string
|
image: FileList | null
|
||||||
body: string
|
thumbnail?: string
|
||||||
image: FileList | null
|
url?: string
|
||||||
thumbnail?: string
|
nsfw: boolean
|
||||||
url?: string
|
loading: boolean
|
||||||
nsfw: boolean
|
alt_text?: string
|
||||||
loading: boolean
|
language_id?: number | string
|
||||||
alt_text?: string
|
}
|
||||||
language_id?: number
|
formtitle?: import('svelte').Snippet
|
||||||
} = {
|
onsubmit?: (post: PostView) => void
|
||||||
community: null,
|
|
||||||
title: '',
|
|
||||||
body: '',
|
|
||||||
image: null,
|
|
||||||
thumbnail: undefined,
|
|
||||||
url: undefined,
|
|
||||||
nsfw: false,
|
|
||||||
loading: false,
|
|
||||||
alt_text: undefined,
|
|
||||||
language_id: undefined,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// weird select menu language handling
|
||||||
// @ts-ignore
|
// @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 saveDraft = edit ? false : true
|
||||||
let communitySearch = passedCommunity?.name ?? ''
|
let communitySearch = $state(passedCommunity?.name ?? '')
|
||||||
|
|
||||||
let communities: Community[] = []
|
let communities: Community[] = $state([])
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (editingPost) {
|
if (editingPost) {
|
||||||
@@ -117,7 +133,7 @@
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!data.title || !$profile?.jwt) return
|
if (!data.title || !profile.data?.jwt) return
|
||||||
if (data.url && data.url != '') {
|
if (data.url && data.url != '') {
|
||||||
try {
|
try {
|
||||||
new URL(data.url)
|
new URL(data.url)
|
||||||
@@ -153,7 +169,7 @@
|
|||||||
|
|
||||||
console.log(`Edited post ${post?.post_view.post.id}`)
|
console.log(`Edited post ${post?.post_view.post.id}`)
|
||||||
|
|
||||||
dispatcher('submit', post.post_view)
|
onsubmit?.(post.post_view)
|
||||||
} else {
|
} else {
|
||||||
const post = await client().createPost({
|
const post = await client().createPost({
|
||||||
community_id: data.community!.id,
|
community_id: data.community!.id,
|
||||||
@@ -171,7 +187,7 @@
|
|||||||
console.log(`Uploaded post ${post?.post_view.post.id}`)
|
console.log(`Uploaded post ${post?.post_view.post.id}`)
|
||||||
|
|
||||||
saveDraft = false
|
saveDraft = false
|
||||||
dispatcher('submit', post.post_view)
|
onsubmit?.(post.post_view)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
pushError({ message: errorMessage(err as any), scope: 'post-form' })
|
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) => {
|
const generateTitle = async (url: string | undefined) => {
|
||||||
if (!url) return
|
if (!url) return
|
||||||
@@ -224,15 +240,17 @@
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
let generation = {
|
let generation = $state({
|
||||||
loading: false,
|
loading: false,
|
||||||
generatable: false,
|
generatable: false,
|
||||||
title: '',
|
title: '',
|
||||||
}
|
})
|
||||||
|
|
||||||
let addAltText = false
|
let addAltText = $state(false)
|
||||||
|
|
||||||
$: generation.generatable = canGenerateTitle(data.url)
|
run(() => {
|
||||||
|
generation.generatable = canGenerateTitle(data.url)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if uploadingImage}
|
{#if uploadingImage}
|
||||||
@@ -240,32 +258,32 @@
|
|||||||
<UploadModal
|
<UploadModal
|
||||||
bind:open={uploadingImage}
|
bind:open={uploadingImage}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
on:upload={(e) => {
|
onupload={(e) => {
|
||||||
if (e.detail) data.url = e.detail[0]
|
if (e) data.url = e[0]
|
||||||
uploadingImage = false
|
uploadingImage = false
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
<form onsubmit={preventDefault(submit)} class="flex flex-col gap-4 h-full">
|
||||||
<slot name="formtitle">
|
{#if formtitle}{@render formtitle()}{:else}
|
||||||
<Header class="font-bold text-xl">
|
<Header class="font-bold text-xl">
|
||||||
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
||||||
</Header>
|
</Header>
|
||||||
</slot>
|
{/if}
|
||||||
<ErrorContainer scope="post-form" />
|
<ErrorContainer scope="post-form" />
|
||||||
{#if !edit && data}
|
{#if !edit && data}
|
||||||
{#if !data.community}
|
{#if !data.community}
|
||||||
<ObjectAutocomplete
|
<ObjectAutocomplete
|
||||||
bind:q={communitySearch}
|
bind:q={communitySearch}
|
||||||
bind:items={communities}
|
items={communities}
|
||||||
jwt={$profile?.jwt}
|
jwt={profile.data?.jwt}
|
||||||
listing_type="All"
|
listing_type="All"
|
||||||
label={$t('form.post.community')}
|
label={$t('form.post.community')}
|
||||||
required
|
required
|
||||||
on:select={(e) => {
|
onselect={(e) => {
|
||||||
const c = e.detail
|
const c = e
|
||||||
if (!c) {
|
if (!c) {
|
||||||
data.community = null
|
data.community = null
|
||||||
return
|
return
|
||||||
@@ -281,16 +299,17 @@
|
|||||||
<span class="font-medium text-sm">{$t('form.post.community')}</span>
|
<span class="font-medium text-sm">{$t('form.post.community')}</span>
|
||||||
<Button
|
<Button
|
||||||
class="w-full !bg-white dark:!bg-black h-[38px]"
|
class="w-full !bg-white dark:!bg-black h-[38px]"
|
||||||
on:click={() => (data.community = null)}
|
onclick={() => (data.community = null)}
|
||||||
alignment="left"
|
alignment="left"
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<Avatar
|
{#snippet prefix()}
|
||||||
url={data.community.icon}
|
<Avatar
|
||||||
alt={data.community.name}
|
url={data?.community?.icon}
|
||||||
width={24}
|
alt={data.community?.name}
|
||||||
slot="prefix"
|
width={24}
|
||||||
/>
|
/>
|
||||||
|
{/snippet}
|
||||||
<div class="flex flex-col gap-0">
|
<div class="flex flex-col gap-0">
|
||||||
<span class="text-xs">{data.community.name}</span>
|
<span class="text-xs">{data.community.name}</span>
|
||||||
<span class="text-[10px] leading-3">
|
<span class="text-[10px] leading-3">
|
||||||
@@ -311,7 +330,7 @@
|
|||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
label={$t('form.post.body')}
|
label={$t('form.post.body')}
|
||||||
bind:value={data.body}
|
bind:value={data.body}
|
||||||
placeholder={placeholders.get('post')}
|
placeholder={placeholders.get('body')}
|
||||||
previewButton
|
previewButton
|
||||||
/>
|
/>
|
||||||
{#if data.url !== undefined}
|
{#if data.url !== undefined}
|
||||||
@@ -324,46 +343,47 @@
|
|||||||
/>
|
/>
|
||||||
<div class="flex items-center gap-2 actions">
|
<div class="flex items-center gap-2 actions">
|
||||||
<div
|
<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>
|
</div>
|
||||||
{#if data.url}
|
{#if data.url}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => (addAltText = !addAltText)}
|
onclick={() => (addAltText = !addAltText)}
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
size="sm"
|
size="sm"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
class="text-xs"
|
class="text-xs"
|
||||||
>
|
>
|
||||||
<Icon
|
{#snippet prefix()}
|
||||||
src={ChatBubbleBottomCenterText}
|
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||||
size="15"
|
{/snippet}{$t('form.post.altText')}
|
||||||
micro
|
|
||||||
slot="prefix"
|
|
||||||
/>{$t('form.post.altText')}
|
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => (uploadingImage = !uploadingImage)}
|
onclick={() => (uploadingImage = !uploadingImage)}
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
size="sm"
|
size="sm"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
class="text-xs"
|
class="text-xs"
|
||||||
>
|
>
|
||||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Photo} size="15" micro />
|
||||||
|
{/snippet}
|
||||||
{$t('form.post.uploadImage')}
|
{$t('form.post.uploadImage')}
|
||||||
</Button>
|
</Button>
|
||||||
{#if generation.generatable}
|
{#if generation.generatable}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => generateTitle(data.url)}
|
onclick={() => generateTitle(data.url)}
|
||||||
loading={generation.loading}
|
loading={generation.loading}
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
size="sm"
|
size="sm"
|
||||||
color="ghost"
|
color="ghost"
|
||||||
class="text-xs"
|
class="text-xs"
|
||||||
>
|
>
|
||||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={Sparkles} size="15" micro />
|
||||||
|
{/snippet}
|
||||||
{$t('form.post.generateTitle')}
|
{$t('form.post.generateTitle')}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -373,7 +393,7 @@
|
|||||||
<div class="flex flex-row gap-2 flex-wrap">
|
<div class="flex flex-row gap-2 flex-wrap">
|
||||||
{#if data.url === undefined}
|
{#if data.url === undefined}
|
||||||
<Button
|
<Button
|
||||||
on:click={async () => {
|
onclick={async () => {
|
||||||
data.url = ''
|
data.url = ''
|
||||||
try {
|
try {
|
||||||
const url = new URL(await navigator.clipboard.readText())
|
const url = new URL(await navigator.clipboard.readText())
|
||||||
@@ -388,7 +408,7 @@
|
|||||||
{$t('form.post.addUrl')}
|
{$t('form.post.addUrl')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
data.url = ''
|
data.url = ''
|
||||||
uploadingImage = true
|
uploadingImage = true
|
||||||
}}
|
}}
|
||||||
@@ -400,7 +420,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if data.language_id === undefined}
|
{#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 />
|
<Icon src={Language} size="16" micro />
|
||||||
{$t('form.post.setLanguage')}
|
{$t('form.post.setLanguage')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -413,18 +433,18 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<Switch bind:checked={data.nsfw}>{$t('form.post.nsfw')}</Switch>
|
<Switch bind:checked={data.nsfw}>{$t('form.post.nsfw')}</Switch>
|
||||||
{#if data.language_id !== undefined}
|
{#if data.language_id !== undefined}
|
||||||
{#if $site}
|
{#if site.data}
|
||||||
<Select
|
<Select
|
||||||
class="w-max"
|
class="w-max"
|
||||||
label={$t('settings.app.lang.title')}
|
label={$t('settings.app.lang.title')}
|
||||||
bind:value={data.language_id}
|
bind:value={data.language_id}
|
||||||
>
|
>
|
||||||
<option value={undefined}>
|
<Option value={undefined}>
|
||||||
<Icon src={XMark} size="16" micro />
|
<Icon src={XMark} size="16" micro />
|
||||||
{$t('form.post.unset')}
|
{$t('form.post.unset')}
|
||||||
</option>
|
</Option>
|
||||||
{#each $site?.all_languages as language}
|
{#each site.data?.all_languages as language}
|
||||||
<option value={language.id.toString()}>{language.name}</option>
|
<Option value={language.id.toString()}>{language.name}</Option>
|
||||||
{/each}
|
{/each}
|
||||||
</Select>
|
</Select>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -433,7 +453,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<div class="mt-auto" />
|
<div class="mt-auto"></div>
|
||||||
<div class="flex flex-row items-center gap-2 w-full">
|
<div class="flex flex-row items-center gap-2 w-full">
|
||||||
<Button
|
<Button
|
||||||
submit
|
submit
|
||||||
@@ -448,7 +468,7 @@
|
|||||||
|
|
||||||
{#if !edit}
|
{#if !edit}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
toast({ content: $t('toast.restoredFromDraft') })
|
toast({ content: $t('toast.restoredFromDraft') })
|
||||||
const draft = getSessionStorage('postDraft')
|
const draft = getSessionStorage('postDraft')
|
||||||
if (draft && !edit) {
|
if (draft && !edit) {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { client, getInstance } from '$lib/lemmy.js'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import type { View } from '$lib/settings'
|
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 { 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 type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||||
me.person.id == comment.creator.id
|
me.person.id == comment.creator.id
|
||||||
@@ -10,17 +13,18 @@ export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
|||||||
export const bestImageURL = (
|
export const bestImageURL = (
|
||||||
post: Post,
|
post: Post,
|
||||||
compact: boolean = true,
|
compact: boolean = true,
|
||||||
width: number = 1024
|
width: number = 1024,
|
||||||
) => {
|
) => {
|
||||||
if (post.thumbnail_url) return optimizeImageURL(post.thumbnail_url, width)
|
if (post.url) return optimizeImageURL(post.url, width)
|
||||||
else if (post.url) return optimizeImageURL(post.url, width)
|
else if (post.thumbnail_url)
|
||||||
|
return optimizeImageURL(post.thumbnail_url, width)
|
||||||
|
|
||||||
return post.url ?? ''
|
return post.url ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export const optimizeImageURL = (
|
export const optimizeImageURL = (
|
||||||
urlStr: string,
|
urlStr: string,
|
||||||
width: number = 1024
|
width: number = 1024,
|
||||||
): string => {
|
): string => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(urlStr)
|
const url = new URL(urlStr)
|
||||||
@@ -32,8 +36,8 @@ export const optimizeImageURL = (
|
|||||||
'thumbnail',
|
'thumbnail',
|
||||||
findClosestNumber(
|
findClosestNumber(
|
||||||
[128, 196, 256, 512, 728, 1024, 1536],
|
[128, 196, 256, 512, 728, 1024, 1536],
|
||||||
width
|
width,
|
||||||
).toString()
|
).toString(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +61,8 @@ export const isYoutubeLink = (url?: string): RegExpMatchArray | null => {
|
|||||||
return url?.match?.(YOUTUBE_REGEX)
|
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 MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||||
export type IframeType = 'youtube' | 'video' | 'none'
|
export type IframeType = 'youtube' | 'video' | 'none'
|
||||||
@@ -82,7 +87,7 @@ export const iframeType = (url: string): IframeType => {
|
|||||||
export async function hidePost(
|
export async function hidePost(
|
||||||
id: number,
|
id: number,
|
||||||
hide: boolean,
|
hide: boolean,
|
||||||
jwt: string
|
jwt: string,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const res = await client({ auth: jwt }).hidePost({
|
const res = await client({ auth: jwt }).hidePost({
|
||||||
hide: hide,
|
hide: hide,
|
||||||
|
|||||||
@@ -8,18 +8,28 @@
|
|||||||
Link as LinkIcon,
|
Link as LinkIcon,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { optimizeImageURL } from '../helpers'
|
import { optimizeImageURL } from '../helpers'
|
||||||
import PostLinkSources from './PostLinkSources.svelte'
|
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import type { View } from '$lib/settings'
|
import type { View } from '$lib/settings.svelte'
|
||||||
|
|
||||||
export let url: string
|
interface Props {
|
||||||
export let thumbnail_url: string | undefined = undefined
|
url: string
|
||||||
export let nsfw: boolean = false
|
thumbnail_url?: string | undefined
|
||||||
export let embed_title: string | undefined = undefined
|
nsfw?: boolean
|
||||||
export let embed_description: string | undefined = undefined
|
embed_title?: string | undefined
|
||||||
export let view: View = 'cozy'
|
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>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -27,55 +37,38 @@
|
|||||||
For embed-type posts. Displays embed card or a compact link.
|
For embed-type posts. Displays embed card or a compact link.
|
||||||
-->
|
-->
|
||||||
{#if embed_title && view != 'compact'}
|
{#if embed_title && view != 'compact'}
|
||||||
<Material
|
<a target="_blank" href={url} class="group/link">
|
||||||
color="distinct"
|
<Material
|
||||||
class="flex flex-col-reverse sm:flex-row
|
color="distinct"
|
||||||
|
class="flex flex-col-reverse sm:flex-row
|
||||||
overflow-hidden gap-4 embed-card z-0 relative
|
overflow-hidden gap-4 embed-card z-0 relative
|
||||||
dark:border-t-zinc-800 border-opacity-80 max-w-full"
|
dark:border-t-zinc-800 border-opacity-80 max-w-full
|
||||||
rounding="xl"
|
dark:bg-zinc-950 group-hover/link:bg-slate-50 group-hover/link:dark:bg-zinc-900 transition-colors"
|
||||||
element="article"
|
rounding="2xl"
|
||||||
>
|
element="article"
|
||||||
{#if thumbnail_url}
|
>
|
||||||
<img
|
{#if thumbnail_url}
|
||||||
src={optimizeImageURL(thumbnail_url, 64)}
|
<img
|
||||||
alt=""
|
src={optimizeImageURL(thumbnail_url, 64)}
|
||||||
class="-z-10 absolute w-full object-cover h-full opacity-10 brightness-150
|
alt=""
|
||||||
dark:brightness-90 dark:opacity-20 blur-2xl
|
class="-z-10 absolute w-full object-cover h-full opacity-10 brightness-150
|
||||||
-inset-px"
|
dark:brightness-90 dark:opacity-20 blur-2xl -inset-px"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="flex flex-col gap-2 mb-2">
|
<div class="flex flex-col gap-2">
|
||||||
{#if richURL}
|
{#if richURL}
|
||||||
<Link
|
<div
|
||||||
href={url}
|
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs font-medium"
|
||||||
target="_blank"
|
>
|
||||||
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs"
|
{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
|
<source
|
||||||
srcset={optimizeImageURL(thumbnail_url, 256)}
|
srcset={optimizeImageURL(thumbnail_url, 256)}
|
||||||
media="(max-width: 256px)"
|
media="(max-width: 256px)"
|
||||||
@@ -90,82 +83,41 @@
|
|||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
src={optimizeImageURL(thumbnail_url, -1)}
|
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}
|
width={600}
|
||||||
height={400}
|
height={400}
|
||||||
alt={embed_title}
|
alt=" "
|
||||||
class:blur-3xl={nsfw}
|
class:blur-3xl={nsfw}
|
||||||
/>
|
/>
|
||||||
</picture>
|
</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}
|
{/if}
|
||||||
</Button>
|
</Material>
|
||||||
</div>
|
</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}
|
{/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') => {
|
const youtubeDomain = (place: 'youtube' | 'invidious' | 'piped') => {
|
||||||
switch (place) {
|
switch (place) {
|
||||||
case 'youtube': {
|
case 'youtube': {
|
||||||
return 'www.youtube-nocookie.com'
|
return 'www.youtube-nocookie.com'
|
||||||
}
|
}
|
||||||
case 'invidious': {
|
case 'invidious': {
|
||||||
return get(userSettings).embeds.invidious || 'yewtu.be'
|
return settings.embeds.invidious || 'yewtu.be'
|
||||||
}
|
}
|
||||||
case 'piped': {
|
case 'piped': {
|
||||||
return get(userSettings).embeds.piped || 'piped.video'
|
return settings.embeds.piped || 'piped.video'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,15 +34,9 @@
|
|||||||
type IconSource,
|
type IconSource,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { optimizeImageURL, type IframeType, type MediaType } from '../helpers'
|
import { optimizeImageURL, type IframeType, type MediaType } from '../helpers'
|
||||||
import { userSettings } from '$lib/settings'
|
import { settings } from '$lib/settings.svelte'
|
||||||
import { get } from 'svelte/store'
|
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) => {
|
const urlToEmbed = (inputUrl: string) => {
|
||||||
if (type == 'video') {
|
if (type == 'video') {
|
||||||
return inputUrl
|
return inputUrl
|
||||||
@@ -56,7 +50,7 @@
|
|||||||
if (autoplay) url.searchParams.set('autoplay', '1')
|
if (autoplay) url.searchParams.set('autoplay', '1')
|
||||||
|
|
||||||
return `https://${youtubeDomain(
|
return `https://${youtubeDomain(
|
||||||
$userSettings.embeds.youtube
|
settings.embeds.youtube,
|
||||||
)}/embed/${videoID}?${url.searchParams.toString()}`
|
)}/embed/${videoID}?${url.searchParams.toString()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +58,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const typeData = (
|
const typeData = (
|
||||||
type: IframeType
|
type: IframeType,
|
||||||
): {
|
): {
|
||||||
icon: IconSource
|
icon: IconSource
|
||||||
text: string
|
text: string
|
||||||
@@ -91,8 +85,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: data = typeData(type)
|
interface Props {
|
||||||
$: embedUrl = urlToEmbed(url)
|
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>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -101,8 +113,8 @@
|
|||||||
-->
|
-->
|
||||||
{#if opened}
|
{#if opened}
|
||||||
{#if type == 'video'}
|
{#if type == 'video'}
|
||||||
<!-- svelte-ignore a11y-media-has-caption -->
|
<!-- svelte-ignore a11y_media_has_caption -->
|
||||||
<video {autoplay} controls class="rounded-xl aspect-video {$$props.class}">
|
<video {autoplay} controls class="rounded-xl aspect-video {clazz}">
|
||||||
<source src={url} />
|
<source src={url} />
|
||||||
</video>
|
</video>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -112,12 +124,12 @@
|
|||||||
frameborder="0"
|
frameborder="0"
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||||
allowfullscreen
|
allowfullscreen
|
||||||
class="aspect-video rounded-xl dark:bg-zinc-900 {$$props.class ?? ''}"
|
class="aspect-video rounded-xl dark:bg-zinc-900 {clazz ?? ''}"
|
||||||
/>
|
></iframe>
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<button
|
<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"
|
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}
|
{#if thumbnail}
|
||||||
@@ -129,7 +141,7 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div
|
<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"
|
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}
|
{/if}
|
||||||
<Icon src={data.icon} solid size="48" />
|
<Icon src={data.icon} solid size="48" />
|
||||||
<h1 class="font-bold text-xl">{data.text}</h1>
|
<h1 class="font-bold text-xl">{data.text}</h1>
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
<script lang="ts">
|
<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 type { Post } from 'lemmy-js-client'
|
||||||
import { bestImageURL, postLink } from '../helpers'
|
import { bestImageURL, postLink } from '../helpers'
|
||||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||||
import { Button, modal } from 'mono-svelte'
|
import { Button, modal } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
|
||||||
export let post: Post
|
interface Props {
|
||||||
export let blur: boolean = false
|
post: Post
|
||||||
|
blur?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
let imageLoaded: boolean | null = null
|
let { post, blur = false }: Props = $props()
|
||||||
|
|
||||||
|
let imageLoaded: boolean | null = $state(null)
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
imageLoaded = false
|
imageLoaded = false
|
||||||
@@ -18,16 +24,16 @@
|
|||||||
|
|
||||||
<!--disabled preloads here since most people will hover over every image while scrolling-->
|
<!--disabled preloads here since most people will hover over every image while scrolling-->
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={$userSettings.expandImages ? 'button' : 'a'}
|
this={settings.expandImages ? 'button' : 'a'}
|
||||||
href={postLink(post)}
|
href={postLink(post)}
|
||||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
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"
|
data-sveltekit-preload-data="off"
|
||||||
aria-label={post.name}
|
aria-label={post.name}
|
||||||
on:click={() => showImage(bestImageURL(post, false, -1))}
|
onclick={() => showImage(bestImageURL(post, false, -1))}
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
>
|
>
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
<!-- svelte-ignore a11y_missing_attribute -->
|
||||||
<img
|
<img
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
fetchpriority="auto"
|
fetchpriority="auto"
|
||||||
@@ -37,22 +43,18 @@
|
|||||||
/>
|
/>
|
||||||
<picture class="max-h-[inherit]">
|
<picture class="max-h-[inherit]">
|
||||||
<source
|
<source
|
||||||
srcset={bestImageURL(post, false, 256)}
|
srcset={bestImageURL(post, false, 512)}
|
||||||
media="(max-width: 256px)"
|
media="(max-width: 256px)"
|
||||||
/>
|
/>
|
||||||
<source
|
<source
|
||||||
srcset={bestImageURL(post, false, 512)}
|
srcset={bestImageURL(post, false, 1024)}
|
||||||
media="(max-width: 512px)"
|
media="(max-width: 512px)"
|
||||||
/>
|
/>
|
||||||
<source
|
<source
|
||||||
srcset={bestImageURL(post, false, 1024)}
|
srcset={bestImageURL(post, false, 1536)}
|
||||||
media="(max-width: 1024px)"
|
media="(max-width: 1024px)"
|
||||||
/>
|
/>
|
||||||
<source
|
<!-- svelte-ignore a11y_missing_attribute -->
|
||||||
srcset={bestImageURL(post, false, 1512)}
|
|
||||||
media="(max-width: 1512px)"
|
|
||||||
/>
|
|
||||||
<!-- svelte-ignore a11y-missing-attribute -->
|
|
||||||
<img
|
<img
|
||||||
src={bestImageURL(post, false, -1)}
|
src={bestImageURL(post, false, -1)}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@@ -63,20 +65,20 @@
|
|||||||
height={300}
|
height={300}
|
||||||
class:blur-[64px]={blur}
|
class:blur-[64px]={blur}
|
||||||
alt={post.alt_text ?? ''}
|
alt={post.alt_text ?? ''}
|
||||||
on:load={() => (imageLoaded = true)}
|
onload={() => (imageLoaded = true)}
|
||||||
/>
|
/>
|
||||||
</picture>
|
</picture>
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
<div
|
<div
|
||||||
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
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
|
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"
|
*: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}
|
{#if post.alt_text}
|
||||||
<Button
|
<Button
|
||||||
on:click={(e) => {
|
onclick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
modal({
|
modal({
|
||||||
title: 'Alt',
|
title: 'Alt',
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import ExpandableImage, {
|
import ExpandableImage, {
|
||||||
showImage,
|
showImage,
|
||||||
} from '$lib/components/ui/ExpandableImage.svelte'
|
} 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 type { Post } from 'lemmy-js-client'
|
||||||
import PostIframe from './PostIframe.svelte'
|
import PostIframe from './PostIframe.svelte'
|
||||||
import { Button, Material, modal } from 'mono-svelte'
|
import { Button, Material, modal } from 'mono-svelte'
|
||||||
@@ -18,11 +18,21 @@
|
|||||||
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||||
import PostImage from './PostImage.svelte'
|
import PostImage from './PostImage.svelte'
|
||||||
|
|
||||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
interface Props {
|
||||||
export let post: Post
|
view?: View
|
||||||
export let type: MediaType = 'none'
|
post: Post
|
||||||
export let opened: boolean | undefined = undefined
|
type?: MediaType
|
||||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
opened?: boolean | undefined
|
||||||
|
blur?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
view = 'cozy',
|
||||||
|
post,
|
||||||
|
type = 'none',
|
||||||
|
opened = undefined,
|
||||||
|
blur = post.nsfw && settings.nsfwBlur,
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -31,9 +41,9 @@
|
|||||||
- A media item (pictures, videos) (large form factor posts only)
|
- A media item (pictures, videos) (large form factor posts only)
|
||||||
- Embed link/card.
|
- Embed link/card.
|
||||||
-->
|
-->
|
||||||
{#if type == 'image' && (view == 'cozy' || view == 'card')}
|
{#if type == 'image' && view == 'cozy'}
|
||||||
<PostImage {post} {blur} />
|
<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
|
<PostIframe
|
||||||
thumbnail={post.thumbnail_url}
|
thumbnail={post.thumbnail_url}
|
||||||
type={iframeType(post.url)}
|
type={iframeType(post.url)}
|
||||||
@@ -43,7 +53,7 @@
|
|||||||
{:else if type == 'embed' && post.url}
|
{:else if type == 'embed' && post.url}
|
||||||
<PostLink
|
<PostLink
|
||||||
url={post.url}
|
url={post.url}
|
||||||
thumbnail_url={view != 'list' ? post.thumbnail_url : undefined}
|
thumbnail_url={post.thumbnail_url}
|
||||||
nsfw={post.nsfw}
|
nsfw={post.nsfw}
|
||||||
embed_description={post.embed_description}
|
embed_description={post.embed_description}
|
||||||
embed_title={post.embed_title}
|
embed_title={post.embed_title}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@
|
|||||||
type MediaType,
|
type MediaType,
|
||||||
} from '$lib/components/lemmy/post/helpers.js'
|
} from '$lib/components/lemmy/post/helpers.js'
|
||||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
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 { isImage } from '$lib/ui/image'
|
||||||
import type { Post } from 'lemmy-js-client'
|
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 {
|
import {
|
||||||
DocumentText,
|
DocumentText,
|
||||||
Icon,
|
Icon,
|
||||||
@@ -18,48 +20,48 @@
|
|||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
} from 'svelte-hero-icons'
|
} 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) =>
|
const thumbnailSize = (view: View) =>
|
||||||
view == 'compact' ? 'w-22 h-22 sm:w-28' : 'w-24 h-24 sm:w-32'
|
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>
|
</script>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@component
|
@component
|
||||||
Thumbnails for compact and list view posts.
|
Thumbnails for compact and list view posts.
|
||||||
-->
|
-->
|
||||||
<div
|
<div class="{size} relative group/media {clazz ?? ''}" {style}>
|
||||||
class="{size} relative group/media {$$props.class ?? ''}"
|
|
||||||
style={$$props.style ?? ''}
|
|
||||||
>
|
|
||||||
{#if post.alt_text}
|
{#if post.alt_text}
|
||||||
<Popover
|
<Button
|
||||||
openOnHover
|
rounding="pill"
|
||||||
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
|
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
|
ALT
|
||||||
slot="target"
|
</Button>
|
||||||
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>
|
|
||||||
{/if}
|
{/if}
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
|
this={!settings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||||
href={postLink(post)}
|
href={postLink(post)}
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
if (type == 'image') {
|
if (type == 'image') {
|
||||||
showImage(bestImageURL(post, false, -1))
|
showImage(bestImageURL(post, false, -1))
|
||||||
}
|
}
|
||||||
@@ -69,19 +71,19 @@
|
|||||||
>
|
>
|
||||||
{#if post.thumbnail_url || isImage(post.url)}
|
{#if post.thumbnail_url || isImage(post.url)}
|
||||||
<div class="relative overflow-hidden rounded-xl">
|
<div class="relative overflow-hidden rounded-xl">
|
||||||
<picture class="relative">
|
<picture>
|
||||||
<img
|
<img
|
||||||
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
|
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
|
||||||
loading="lazy"
|
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}"
|
transition-colors {size}"
|
||||||
alt={post.name}
|
alt={post.alt_text ?? ' '}
|
||||||
class:blur-xl={blur}
|
class:blur-xl={blur}
|
||||||
/>
|
/>
|
||||||
{#if type != 'image'}
|
{#if type != 'image'}
|
||||||
<div
|
<div
|
||||||
class="absolute w-8 h-8 bottom-0 left-0 m-1 rounded-xl text-slate-800 dark:text-zinc-200
|
class="absolute w-8 h-8 m-1 bottom-0 left-0 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
|
bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700
|
||||||
grid place-items-center"
|
grid place-items-center"
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
|
|||||||
@@ -1,17 +1,28 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
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 type { Community, ListingType, Person } from 'lemmy-js-client'
|
||||||
import { MenuButton, Search } from 'mono-svelte'
|
import { MenuButton, Search } from 'mono-svelte'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import { Icon, XCircle } from 'svelte-hero-icons'
|
import { Icon, XCircle } from 'svelte-hero-icons'
|
||||||
import { fly } from 'svelte/transition'
|
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
|
let {
|
||||||
export let listing_type: ListingType = 'Subscribed'
|
q = $bindable(''),
|
||||||
export let showWhenEmpty: boolean = false
|
instance = undefined,
|
||||||
|
listing_type = 'Subscribed',
|
||||||
|
showWhenEmpty = false,
|
||||||
|
...rest
|
||||||
|
}: Props = $props()
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ select: Person | undefined }>()
|
const dispatcher = createEventDispatcher<{ select: Person | undefined }>()
|
||||||
</script>
|
</script>
|
||||||
@@ -29,34 +40,34 @@
|
|||||||
return results.users.map((c) => c.person)
|
return results.users.map((c) => c.person)
|
||||||
}}
|
}}
|
||||||
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
|
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
|
||||||
on:select
|
|
||||||
bind:query={q}
|
bind:query={q}
|
||||||
{showWhenEmpty}
|
{...rest}
|
||||||
{...$$restProps}
|
|
||||||
let:item
|
|
||||||
let:select
|
|
||||||
>
|
>
|
||||||
<div class="w-full h-full" slot="noresults">
|
{#snippet noresults()}
|
||||||
{#if showWhenEmpty}
|
<div class="w-full h-full">
|
||||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
{#if showWhenEmpty}
|
||||||
<Icon src={XCircle} size="16" mini />
|
<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">
|
<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>
|
</div>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{:else}
|
</div>
|
||||||
<span class="mx-auto my-auto">No results.</span>
|
{/snippet}
|
||||||
{/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>
|
|
||||||
</Search>
|
</Search>
|
||||||
@@ -11,15 +11,24 @@
|
|||||||
import { userLink } from '$lib/lemmy/generic'
|
import { userLink } from '$lib/lemmy/generic'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
|
|
||||||
export let user: PersonView
|
interface Props {
|
||||||
export let view: 'cozy' | 'compact' = 'compact'
|
user: PersonView
|
||||||
export let showCounts: boolean = true
|
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>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class={clazz}>
|
||||||
class={$$props.class ??
|
|
||||||
'py-4 flex flex-col gap-4 text-sm max-w-full relative'}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="flex
|
class="flex
|
||||||
{view == 'cozy'
|
{view == 'cozy'
|
||||||
@@ -32,9 +41,9 @@
|
|||||||
? 'flex-col gap-2'
|
? 'flex-col gap-2'
|
||||||
: 'flex-row'} gap-2 items-center"
|
: '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} />
|
<Avatar url={user.person.avatar} width={32} alt={user.person.name} />
|
||||||
</slot>
|
{/if}
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="font-medium text-base">
|
<div class="font-medium text-base">
|
||||||
{user.person.display_name ?? user.person.name}
|
{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 { env } from '$env/dynamic/public'
|
||||||
|
|
||||||
import type { IconSource } from 'svelte-hero-icons'
|
import type { IconSource } from 'svelte-hero-icons'
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
const badges = parseBadge()
|
const badges = parseBadge()
|
||||||
|
|
||||||
const getEnvBadge = (
|
const getEnvBadge = (
|
||||||
actor_id: string
|
actor_id: string,
|
||||||
):
|
):
|
||||||
| {
|
| {
|
||||||
classes: string
|
classes: string
|
||||||
@@ -50,30 +50,48 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import Logo from '$lib/components/ui/Logo.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 type { Person } from 'lemmy-js-client'
|
||||||
import { Icon, Language, NoSymbol } from 'svelte-hero-icons'
|
import { Icon, Language, NoSymbol } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let user: Person
|
interface Props {
|
||||||
export let avatar: boolean = false
|
user: Person
|
||||||
export let avatarSize: number = 24
|
avatar?: boolean
|
||||||
export let badges: boolean = true
|
avatarSize?: number
|
||||||
export let inComment: boolean = false
|
badges?: boolean
|
||||||
export let showInstance: boolean =
|
inComment?: boolean
|
||||||
$userSettings.showInstances.user ||
|
showInstance?: boolean
|
||||||
($userSettings.showInstances.comments && inComment)
|
displayName?: any
|
||||||
export let displayName = $userSettings.displayNames
|
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>
|
</script>
|
||||||
|
|
||||||
<a
|
<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}"
|
href="/u/{user.name}@{new URL(user.actor_id).hostname}"
|
||||||
data-sveltekit-preload-data="tap"
|
data-sveltekit-preload-data="tap"
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
{#if avatar}
|
{#if avatar}
|
||||||
<Avatar
|
<Avatar
|
||||||
url={user.avatar}
|
url={user.avatar}
|
||||||
@@ -94,7 +112,7 @@
|
|||||||
</span>
|
</span>
|
||||||
{#if showInstance}
|
{#if showInstance}
|
||||||
<span
|
<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}
|
@{new URL(user.actor_id).hostname}
|
||||||
@@ -122,7 +140,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<slot name="badges" />
|
{@render extraBadges?.()}
|
||||||
{/if}
|
{/if}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,31 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { preventDefault } from 'svelte/legacy'
|
||||||
|
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import { TextInput } from 'mono-svelte'
|
import { TextInput } from 'mono-svelte'
|
||||||
|
|
||||||
let query: string = ''
|
let query: string = $state('')
|
||||||
let loading = false
|
let loading = $state(false)
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
loading = true
|
loading = true
|
||||||
goto(`/search?q=${query}`).then(() => (loading = false))
|
goto(`/search?q=${query}`).then(() => (loading = false))
|
||||||
}
|
}
|
||||||
|
interface Props {
|
||||||
|
class?: string
|
||||||
|
children?: import('svelte').Snippet<[any]>
|
||||||
|
}
|
||||||
|
|
||||||
|
let { class: clazz = '', children }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form on:submit|preventDefault={search} class="w-full h-full {$$props.class}">
|
<form onsubmit={preventDefault(search)} class="w-full h-full {clazz}">
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={query}
|
bind:value={query}
|
||||||
class="w-full h-full {$$props.class}"
|
class="w-full h-full {clazz}"
|
||||||
placeholder={$t('nav.search')}
|
placeholder={$t('nav.search')}
|
||||||
autofocus
|
autofocus
|
||||||
/>
|
/>
|
||||||
</form>
|
</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 { marked } from 'marked'
|
||||||
import {
|
import {
|
||||||
MdCode,
|
MdCode,
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
MdListItem,
|
MdListItem,
|
||||||
MdSubscript,
|
MdSubscript,
|
||||||
MdSuperscript,
|
MdSuperscript,
|
||||||
|
MdText,
|
||||||
} from './renderers/index'
|
} from './renderers/index'
|
||||||
import { linkify, subSupscriptExtension } from './renderers/plugins'
|
import { linkify, subSupscriptExtension } from './renderers/plugins'
|
||||||
import containerExtension from './renderers/spoiler/spoiler'
|
import containerExtension from './renderers/spoiler/spoiler'
|
||||||
@@ -85,30 +86,74 @@
|
|||||||
subscript: MdSubscript,
|
subscript: MdSubscript,
|
||||||
superscript: MdSuperscript,
|
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>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import SvelteMarkdown from 'svelte-markdown'
|
import SvelteMarkdown from 'svelte-markdown'
|
||||||
|
import { setContext } from 'svelte'
|
||||||
|
|
||||||
export let source: string = ''
|
interface RendererOptions {
|
||||||
export let inline: boolean = false
|
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
|
options.inline = inline
|
||||||
|
|
||||||
export let noStyle: boolean = false
|
let tokens = $derived.by(() => marked.lexer(source))
|
||||||
|
|
||||||
$: tokens = marked.lexer(source)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="{noStyle
|
class="{noStyle
|
||||||
? ''
|
? ''
|
||||||
: 'break-words flex flex-col gap-2 leading-[1.5]'} {$$props.class}"
|
: 'break-words flex flex-col gap-2 leading-[1.5]'} {clazz}"
|
||||||
style={$$props.style}
|
{style}
|
||||||
>
|
>
|
||||||
<SvelteMarkdown
|
<SvelteMarkdown
|
||||||
bind:source={tokens}
|
source={tokens}
|
||||||
{renderers}
|
renderers={inline ? inlineRenderers : renderers}
|
||||||
{options}
|
{options}
|
||||||
isInline={inline || undefined}
|
isInline={inline || undefined}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<script lang="ts">
|
<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 MultiSelect from '$lib/components/input/Switch.svelte'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import { t } from '$lib/translations'
|
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 { ImageInput, toast } from 'mono-svelte'
|
||||||
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
||||||
import { createEventDispatcher, tick } from 'svelte'
|
import { createEventDispatcher, tick } from 'svelte'
|
||||||
@@ -21,20 +23,10 @@
|
|||||||
Strikethrough,
|
Strikethrough,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
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
|
let textArea: HTMLTextAreaElement | undefined = $state()
|
||||||
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
|
|
||||||
|
|
||||||
function replaceTextAtIndices(
|
function replaceTextAtIndices(
|
||||||
str: string,
|
str: string,
|
||||||
@@ -46,6 +38,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wrapSelection(start: string, end: string) {
|
function wrapSelection(start: string, end: string) {
|
||||||
|
if (!textArea) return
|
||||||
const startPos = textArea.selectionStart
|
const startPos = textArea.selectionStart
|
||||||
const endPos = textArea.selectionEnd
|
const endPos = textArea.selectionEnd
|
||||||
|
|
||||||
@@ -66,10 +59,8 @@
|
|||||||
value = textArea.value
|
value = textArea.value
|
||||||
}
|
}
|
||||||
|
|
||||||
let uploadingImage = false
|
let uploadingImage = $state(false)
|
||||||
let image: any
|
let image = $state<any>(null)
|
||||||
|
|
||||||
export let previewing = false
|
|
||||||
|
|
||||||
const shortcuts = {
|
const shortcuts = {
|
||||||
KeyB: () => wrapSelection('**', '**'),
|
KeyB: () => wrapSelection('**', '**'),
|
||||||
@@ -78,9 +69,9 @@
|
|||||||
KeyH: () => wrapSelection('\n# ', ''),
|
KeyH: () => wrapSelection('\n# ', ''),
|
||||||
KeyK: () => wrapSelection('[](', ')'),
|
KeyK: () => wrapSelection('[](', ')'),
|
||||||
Enter: (e: any) => {
|
Enter: (e: any) => {
|
||||||
dispatcher('confirm', value)
|
onconfirm?.(value)
|
||||||
const newEvent = new Event('submit', { cancelable: true })
|
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>
|
</script>
|
||||||
|
|
||||||
{#if uploadingImage && images}
|
{#if uploadingImage && images}
|
||||||
<ImageUploadModal
|
<ImageUploadModal
|
||||||
bind:open={uploadingImage}
|
bind:open={uploadingImage}
|
||||||
bind:image
|
bind:image
|
||||||
on:upload={(e) => {
|
onupload={(e) => {
|
||||||
e.detail.forEach((i) => {
|
e.forEach((i) => {
|
||||||
wrapSelection(`\n\n`, '')
|
wrapSelection(`\n\n`, '')
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
@@ -108,12 +134,12 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
{#if label || $$slots.label}
|
{#if label || customLabel}
|
||||||
<Label>
|
<Label>
|
||||||
{#if label}
|
{#if label}
|
||||||
{label}
|
{label}
|
||||||
{:else if $$slots.label}
|
{:else if customLabel}
|
||||||
<slot name="label" />
|
{@render customLabel?.()}
|
||||||
{/if}
|
{/if}
|
||||||
</Label>
|
</Label>
|
||||||
{/if}
|
{/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
|
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
|
focus-within:border-primary-900 focus-within:dark:border-primary-100 focus-within:ring ring-slate-300
|
||||||
dark:ring-zinc-700 rounded-xl
|
dark:ring-zinc-700 rounded-xl
|
||||||
overflow-hidden transition-colors {$$props.class}"
|
overflow-hidden transition-colors {clazz}"
|
||||||
class:mt-1={label}
|
class:mt-1={label}
|
||||||
>
|
>
|
||||||
{#if previewing}
|
{#if previewing}
|
||||||
@@ -135,68 +161,68 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
<!--Toolbar-->
|
<!--Toolbar-->
|
||||||
<div
|
<div
|
||||||
class="[&>*]:flex-shrink-0 flex flex-row overflow-auto p-1.5 gap-1.5 border-b
|
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'
|
? 'opacity-60 pointer-events-none'
|
||||||
: ''}"
|
: ''}"
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('**', '**')}
|
onclick={() => wrapSelection('**', '**')}
|
||||||
title="Bold"
|
title="Bold"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={Bold} size="16" mini />
|
<Icon src={Bold} size="16" mini />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('*', '*')}
|
onclick={() => wrapSelection('*', '*')}
|
||||||
title="Italic"
|
title="Italic"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={Italic} size="16" micro />
|
<Icon src={Italic} size="16" micro />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('[', '](https://example.com)')}
|
onclick={() => wrapSelection('[', '](https://example.com)')}
|
||||||
title="Link"
|
title="Link"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={Link} size="16" micro />
|
<Icon src={Link} size="16" micro />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('\n# ', '')}
|
onclick={() => wrapSelection('\n# ', '')}
|
||||||
title="Header"
|
title="Header"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={H1} size="16" micro />
|
<Icon src={H1} size="16" micro />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('~~', '~~')}
|
onclick={() => wrapSelection('~~', '~~')}
|
||||||
title="Strikethrough"
|
title="Strikethrough"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={Strikethrough} size="16" micro />
|
<Icon src={Strikethrough} size="16" micro />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('\n> ', '')}
|
onclick={() => wrapSelection('\n> ', '')}
|
||||||
title="Quote"
|
title="Quote"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<span class="font-bold font-serif text-lg">"</span>
|
<span class="font-bold font-serif text-lg">"</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('\n- ', '')}
|
onclick={() => wrapSelection('\n- ', '')}
|
||||||
title="List"
|
title="List"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={ListBullet} micro size="16" />
|
<Icon src={ListBullet} micro size="16" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('`', '`')}
|
onclick={() => wrapSelection('`', '`')}
|
||||||
title="Code"
|
title="Code"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
<Icon src={CodeBracket} micro size="16" />
|
<Icon src={CodeBracket} micro size="16" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() =>
|
onclick={() =>
|
||||||
wrapSelection('::: spoiler <spoiler title>\n', '\n:::')}
|
wrapSelection('::: spoiler <spoiler title>\n', '\n:::')}
|
||||||
title="Spoiler"
|
title="Spoiler"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
@@ -204,7 +230,7 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
<Icon src={ExclamationTriangle} micro size="16" />
|
<Icon src={ExclamationTriangle} micro size="16" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('~', '~')}
|
onclick={() => wrapSelection('~', '~')}
|
||||||
title="Subscript"
|
title="Subscript"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
@@ -214,7 +240,7 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => wrapSelection('^', '^')}
|
onclick={() => wrapSelection('^', '^')}
|
||||||
title="Superscript"
|
title="Superscript"
|
||||||
size="square-md"
|
size="square-md"
|
||||||
>
|
>
|
||||||
@@ -225,7 +251,7 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
</Button>
|
</Button>
|
||||||
{#if images}
|
{#if images}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => (uploadingImage = !uploadingImage)}
|
onclick={() => (uploadingImage = !uploadingImage)}
|
||||||
title="Image"
|
title="Image"
|
||||||
size="square-md"
|
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"
|
class="bg-inherit z-0 border-0 rounded-none !ring-0 focus:!ring-transparent !transition-none resize-none"
|
||||||
bind:value
|
bind:value
|
||||||
bind:element={textArea}
|
bind:element={textArea}
|
||||||
on:keydown={(e) => {
|
onkeydown={(e) => {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
if (e.ctrlKey || e.metaKey) {
|
if (e.ctrlKey || e.metaKey) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -250,9 +276,8 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:input={adjustHeight}
|
oninput={adjustHeight}
|
||||||
on:focus
|
onpaste={(e) => {
|
||||||
on:paste={(e) => {
|
|
||||||
if (!e.clipboardData?.files) return
|
if (!e.clipboardData?.files) return
|
||||||
const files = Array.from(e.clipboardData.files)
|
const files = Array.from(e.clipboardData.files)
|
||||||
if (files[0]?.type.startsWith('image/')) {
|
if (files[0]?.type.startsWith('image/')) {
|
||||||
@@ -261,7 +286,7 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
{rows}
|
{rows}
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -276,7 +301,7 @@ overflow-hidden transition-colors {$$props.class}"
|
|||||||
optionNames={[$t('form.edit'), $t('form.preview')]}
|
optionNames={[$t('form.edit'), $t('form.preview')]}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
import { Button, Material, toast } from 'mono-svelte'
|
import { Button, Material, toast } from 'mono-svelte'
|
||||||
import { Icon, ClipboardDocument } from 'svelte-hero-icons'
|
import { Icon, ClipboardDocument } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let raw: string
|
interface Props {
|
||||||
|
raw: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { raw }: Props = $props()
|
||||||
|
|
||||||
function parseCodeblock(src: string): {
|
function parseCodeblock(src: string): {
|
||||||
code: string
|
code: string
|
||||||
@@ -21,7 +25,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: codeblock = parseCodeblock(raw)
|
let codeblock = $derived(parseCodeblock(raw))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Material
|
<Material
|
||||||
@@ -36,7 +40,7 @@
|
|||||||
<Button
|
<Button
|
||||||
size="square-sm"
|
size="square-sm"
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
on:click={() => {
|
onclick={() => {
|
||||||
navigator?.clipboard?.writeText(codeblock.code)
|
navigator?.clipboard?.writeText(codeblock.code)
|
||||||
toast({ content: $t('toast.copied') })
|
toast({ content: $t('toast.copied') })
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,20 +1,25 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let depth: number = 0
|
interface Props {
|
||||||
export let raw: string | undefined = undefined
|
depth?: number
|
||||||
|
raw?: string | undefined
|
||||||
|
children?: import('svelte').Snippet
|
||||||
|
}
|
||||||
|
|
||||||
|
let { depth = 0, raw = undefined, children }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if depth === 1}
|
{#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}
|
{: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}
|
{: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}
|
{: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}
|
{: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}
|
{:else if depth === 6}
|
||||||
<h6 class="font-semibold text-base"><slot></slot></h6>
|
<h6 class="font-semibold text-base">{@render children?.()}</h6>
|
||||||
{:else}
|
{:else}
|
||||||
{raw}
|
{raw}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let text: string
|
interface Props {
|
||||||
|
text: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { text }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -6,36 +6,64 @@
|
|||||||
optimizeImageURL,
|
optimizeImageURL,
|
||||||
} from '$lib/components/lemmy/post/helpers'
|
} from '$lib/components/lemmy/post/helpers'
|
||||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
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
|
let loaded: boolean = $state(
|
||||||
export let title: string | undefined = undefined
|
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
|
||||||
export let text: string = ''
|
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>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
|
class="w-auto h-auto max-h-96 rounded-2xl p-2 border border-slate-200 dark:border-zinc-800
|
||||||
inline-block"
|
inline-block"
|
||||||
>
|
>
|
||||||
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
{#if loaded}
|
||||||
<PostIframe
|
{#if type == 'video' || type == 'embed' || type == 'iframe'}
|
||||||
type={iframeType(href)}
|
<PostIframe
|
||||||
url={href}
|
type={iframeType(href)}
|
||||||
opened={true}
|
url={href}
|
||||||
autoplay={false}
|
opened={true}
|
||||||
class="w-auto h-auto max-h-80 inline-block rounded-lg"
|
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}
|
{:else}
|
||||||
<button
|
<button
|
||||||
class="inline"
|
onclick={() => (loaded = true)}
|
||||||
on:click={() => showImage(optimizeImageURL(href, -1), text)}
|
class="w-40 h-40 flex flex-col justify-center items-center gap-4 p-2 group"
|
||||||
|
title={$t('common.download')}
|
||||||
>
|
>
|
||||||
<img
|
<Icon
|
||||||
src={optimizeImageURL(href, 1024)}
|
src={ArrowDownTray}
|
||||||
{title}
|
size="24"
|
||||||
alt={text}
|
class="text-primary-900 dark:text-primary-100"
|
||||||
class="object-contain w-auto h-auto max-h-80 inline rounded-lg"
|
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { photonify } from './plugins'
|
import { photonify } from './plugins'
|
||||||
|
|
||||||
export let href = ''
|
interface Props {
|
||||||
export let title = undefined
|
href?: string
|
||||||
|
title?: any
|
||||||
|
children?: import('svelte').Snippet
|
||||||
|
}
|
||||||
|
|
||||||
|
let { href = '', title = undefined, children }: Props = $props()
|
||||||
|
|
||||||
export const parseURL = (href: string) => {
|
export const parseURL = (href: string) => {
|
||||||
try {
|
try {
|
||||||
@@ -12,7 +17,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: photonified = photonify(href)
|
let photonified = $derived(photonify(href))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
@@ -20,5 +25,5 @@
|
|||||||
{title}
|
{title}
|
||||||
class="hover:underline text-sky-600 dark:text-sky-500"
|
class="hover:underline text-sky-600 dark:text-sky-500"
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</a>
|
</a>
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let ordered: boolean
|
interface Props {
|
||||||
export let start: number
|
ordered: boolean
|
||||||
|
start: number
|
||||||
|
children?: import('svelte').Snippet
|
||||||
|
}
|
||||||
|
|
||||||
|
let { ordered, start, children }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if ordered}
|
{#if ordered}
|
||||||
@@ -8,12 +13,12 @@
|
|||||||
{start}
|
{start}
|
||||||
class="pl-5 list-decimal *:marker:font-medium *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
class="pl-5 list-decimal *:marker:font-medium *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</ol>
|
</ol>
|
||||||
{:else}
|
{:else}
|
||||||
<ul
|
<ul
|
||||||
class="list-disc pl-4 *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
class="list-disc pl-4 *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</ul>
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
export let tokens
|
let { tokens, children } = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</li>
|
</li>
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
<script>
|
<script>
|
||||||
import { options } from '../Markdown.svelte'
|
import { options } from '../Markdown.svelte'
|
||||||
|
/**
|
||||||
|
* @typedef {Object} Props
|
||||||
|
* @property {import('svelte').Snippet} [children]
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @type {Props} */
|
||||||
|
let { children } = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p class="leading-[1.5] {options.inline ? '' : 'max-w'}">
|
<p class="leading-[1.5] break-words {options.inline ? '' : 'max-w'}">
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<style>
|
<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">
|
<blockquote class="border-l-2 dark:border-zinc-700 border-slate-300 p-1 px-3">
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</blockquote>
|
</blockquote>
|
||||||
@@ -6,7 +6,11 @@
|
|||||||
import { Icon } from 'svelte-hero-icons'
|
import { Icon } from 'svelte-hero-icons'
|
||||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||||
|
|
||||||
export let raw: string
|
interface Props {
|
||||||
|
raw: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { raw }: Props = $props()
|
||||||
|
|
||||||
function extractTitle(text: string) {
|
function extractTitle(text: string) {
|
||||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||||
@@ -25,12 +29,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: data = extractTitle(raw)
|
let data = $derived(extractTitle(raw))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Expandable class="border-y border-slate-200 dark:border-zinc-800 py-2">
|
<Expandable class="border-y border-slate-200 dark:border-zinc-800 py-2">
|
||||||
<div slot="title" class="text-left">
|
{#snippet title()}
|
||||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
<div class="text-left">
|
||||||
</div>
|
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||||
|
</div>
|
||||||
|
{/snippet}
|
||||||
<SvelteMarkdown source={data.content} {renderers} {options} />
|
<SvelteMarkdown source={data.content} {renderers} {options} />
|
||||||
</Expandable>
|
</Expandable>
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let text: string
|
interface Props {
|
||||||
|
text: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { text }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<sub>{text}</sub>
|
<sub>{text}</sub>
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let text: string
|
interface Props {
|
||||||
|
text: string
|
||||||
|
}
|
||||||
|
|
||||||
|
let { text }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<sup>{text}</sup>
|
<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 MdListItem from './MdListItem.svelte'
|
||||||
import MdSubscript from './MdSubscript.svelte'
|
import MdSubscript from './MdSubscript.svelte'
|
||||||
import MdSuperscript from './MdSuperscript.svelte'
|
import MdSuperscript from './MdSuperscript.svelte'
|
||||||
|
import MdText from './MdText.svelte'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
MdCode,
|
MdCode,
|
||||||
@@ -36,4 +37,5 @@ export {
|
|||||||
MdListItem,
|
MdListItem,
|
||||||
MdSubscript,
|
MdSubscript,
|
||||||
MdSuperscript,
|
MdSuperscript,
|
||||||
|
MdText,
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ export const linkify = markedLinkifyIt(
|
|||||||
|
|
||||||
if (!self.re.community) {
|
if (!self.re.community) {
|
||||||
self.re.community = new RegExp(
|
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)) {
|
if (self.re.community.test(tail)) {
|
||||||
@@ -63,7 +63,7 @@ export const linkify = markedLinkifyIt(
|
|||||||
|
|
||||||
if (!self.re.user) {
|
if (!self.re.user) {
|
||||||
self.re.user = new RegExp(
|
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)) {
|
if (self.re.user.test(tail)) {
|
||||||
@@ -86,7 +86,7 @@ export const linkify = markedLinkifyIt(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
fuzzyEmail: false,
|
fuzzyEmail: false,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const regexes = {
|
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">
|
<table class="overflow-auto w-full table-fixed rounded-xl">
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</table>
|
</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">
|
<script lang="ts">
|
||||||
export let header: boolean
|
interface Props {
|
||||||
export let align:
|
header: boolean
|
||||||
| 'left'
|
align?: 'left' | 'center' | 'right' | 'justify' | 'char' | null | undefined
|
||||||
| 'center'
|
children?: import('svelte').Snippet
|
||||||
| 'right'
|
}
|
||||||
| 'justify'
|
|
||||||
| 'char'
|
let { header, align = undefined, children }: Props = $props()
|
||||||
| null
|
|
||||||
| undefined = undefined
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if header}
|
{#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"
|
class="bg-slate-50 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||||
{align}
|
{align}
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</th>
|
</th>
|
||||||
{:else}
|
{:else}
|
||||||
<td
|
<td
|
||||||
class="bg-slate-25 dark:bg-zinc-950 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
class="bg-slate-25 dark:bg-zinc-950 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||||
{align}
|
{align}
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</td>
|
</td>
|
||||||
{/if}
|
{/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">
|
<script lang="ts">
|
||||||
import { findClosestNumber } from '$lib/util.js'
|
import { findClosestNumber } from '$lib/util.svelte.js'
|
||||||
import { createAvatar } from '@dicebear/core'
|
import { createAvatar } from '@dicebear/core'
|
||||||
import * as initials from '@dicebear/initials'
|
import * as initials from '@dicebear/initials'
|
||||||
|
import type { ClassValue } from 'svelte/elements'
|
||||||
|
|
||||||
const sizes = [16, 24, 32, 48, 64, 96, 128, 256, 512]
|
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 = (
|
const optimizeUrl = (
|
||||||
url: string | undefined,
|
url: string | undefined,
|
||||||
res: number
|
res: number,
|
||||||
): string | undefined => {
|
): string | undefined => {
|
||||||
if (url === undefined) return
|
if (url === undefined) return
|
||||||
|
|
||||||
@@ -25,7 +18,7 @@
|
|||||||
if (res > -1) {
|
if (res > -1) {
|
||||||
urlObj.searchParams.append(
|
urlObj.searchParams.append(
|
||||||
'thumbnail',
|
'thumbnail',
|
||||||
findClosestNumber(sizes, res).toString()
|
findClosestNumber(sizes, res).toString(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,29 +28,53 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: optimizedURLs = [2, 3, 6, -1].map((n) =>
|
interface Props {
|
||||||
optimizeUrl(url, (res || width) * n)
|
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>
|
</script>
|
||||||
|
|
||||||
{#if optimizedURLs[0] != undefined}
|
{#if optimizedURLs[0] != undefined}
|
||||||
<img
|
<img
|
||||||
{...$$restProps}
|
{...rest}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||||
src={optimizedURLs[0]}
|
src={optimizedURLs[0]}
|
||||||
{alt}
|
{alt}
|
||||||
{width}
|
{width}
|
||||||
{title}
|
{title}
|
||||||
class="aspect-square object-cover overflow-hidden {$$props.class} flex-shrink-0"
|
class={['aspect-square object-cover overflow-hidden flex-shrink-0', clazz]}
|
||||||
style="width: {width}px; height: {width}px; {$$props.style || undefined}"
|
style="width: {width}px; height: {width}px; {style}"
|
||||||
class:rounded-full={circle}
|
class:rounded-full={circle}
|
||||||
class:rounded-md={!circle}
|
class:rounded-md={!circle}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<div
|
<div
|
||||||
style="width: {width}px; height: {width}px;"
|
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-full={circle}
|
||||||
class:rounded-md={!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
|
<div
|
||||||
class="flex flex-row items-center
|
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">
|
<span class="font-medium text-left">
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</span>
|
</span>
|
||||||
<hr class="border-slate-200 flex-1 w-full dark:border-zinc-800" />
|
<hr class="border-slate-200 flex-1 w-full dark:border-zinc-800" />
|
||||||
<slot name="action" />
|
{@render action?.()}
|
||||||
</div>
|
</div>
|
||||||
@@ -1,15 +1,25 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from './Avatar.svelte'
|
import Avatar from './Avatar.svelte'
|
||||||
|
|
||||||
export let name: string
|
interface Props {
|
||||||
export let label: string | undefined = undefined
|
name: string
|
||||||
export let icon: string | undefined = undefined
|
label?: string | undefined
|
||||||
|
icon?: string | undefined
|
||||||
|
customIcon?: import('svelte').Snippet
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
name,
|
||||||
|
label = undefined,
|
||||||
|
icon = undefined,
|
||||||
|
customIcon,
|
||||||
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-row gap-2 items-center">
|
<div class="flex flex-row gap-2 items-center">
|
||||||
<slot name="icon">
|
{#if customIcon}{@render customIcon()}{:else}
|
||||||
<Avatar url={icon} width={32} />
|
<Avatar url={icon} width={32} />
|
||||||
</slot>
|
{/if}
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<span class="font-semibold text-base">{name}</span>
|
<span class="font-semibold text-base">{name}</span>
|
||||||
<span class="text-sm">{label}</span>
|
<span class="text-sm">{label}</span>
|
||||||
|
|||||||
@@ -5,50 +5,58 @@
|
|||||||
import LabelStat from './LabelStat.svelte'
|
import LabelStat from './LabelStat.svelte'
|
||||||
import { optimizeImageURL } from '../lemmy/post/helpers'
|
import { optimizeImageURL } from '../lemmy/post/helpers'
|
||||||
import FormattedNumber from '../util/FormattedNumber.svelte'
|
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
|
interface Props {
|
||||||
export let name: string
|
avatar?: string | undefined
|
||||||
export let bio: string | undefined = undefined
|
|
||||||
export let banner: string | undefined = undefined
|
|
||||||
export let url: string | undefined = undefined
|
|
||||||
export let stats: {
|
|
||||||
name: string
|
name: string
|
||||||
value: string
|
bio?: string | undefined
|
||||||
format?: boolean
|
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>
|
</script>
|
||||||
|
|
||||||
<Material
|
<div {...rest} class="z-10 relative text-sm contents {clazz}">
|
||||||
color="transparent"
|
{#if banner}
|
||||||
padding="none"
|
<img
|
||||||
rounding="xl"
|
src={banner}
|
||||||
{...$$restProps}
|
class="w-full object-cover h-48 rounded-t-xl bg-white dark:bg-zinc-900 rounded-xl"
|
||||||
class="z-10 relative border-slate-200 dark:border-zinc-700 {$$props.class}"
|
class:blur-3xl={!banner}
|
||||||
>
|
height="192"
|
||||||
{#if banner || avatar}
|
alt="User banner"
|
||||||
<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>
|
|
||||||
{/if}
|
{/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">
|
<div class="flex-1 flex flex-row items-center text-left gap-4">
|
||||||
<Avatar
|
<Avatar
|
||||||
width={64}
|
width={64}
|
||||||
@@ -60,7 +68,7 @@
|
|||||||
<svelte:element
|
<svelte:element
|
||||||
this={url ? 'a' : 'span'}
|
this={url ? 'a' : 'span'}
|
||||||
href={url}
|
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'
|
? 'hover:underline hover:text-primary-900 hover:dark:text-primary-100'
|
||||||
: ''}"
|
: ''}"
|
||||||
>
|
>
|
||||||
@@ -69,39 +77,59 @@
|
|||||||
<span
|
<span
|
||||||
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
|
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>
|
</span>
|
||||||
|
|
||||||
{#if $$slots.actions}
|
{#if actions}
|
||||||
<div class="flex flex-col mt-2">
|
<div class="flex flex-col mt-2">
|
||||||
<slot name="actions" />
|
{@render actions?.()}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{#if bio}
|
{#if bio}
|
||||||
<div class="relative w-full {center ? 'text-center' : 'text-left'}">
|
<div class="relative w-full {center ? 'text-center' : 'text-left'}">
|
||||||
<div
|
<Expandable class="py-2">
|
||||||
class="p-4 relative bg-white/30 dark:bg-zinc-900/30 border border-slate-300
|
{#snippet title(open)}
|
||||||
dark:border-zinc-800 border-opacity-50 rounded-xl
|
{#if bio.split('\n')?.[0]?.startsWith('#') || open}
|
||||||
max-w-full w-full"
|
{$t('nav.menu.about')}
|
||||||
>
|
{:else}
|
||||||
<PostBody class="text-sm" view="list" body={bio} clickThrough />
|
<div
|
||||||
</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>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="space-y-3 p-4 pt-0">
|
<div class="space-y-3 py-4 pt-0">
|
||||||
{#if stats.length > 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}
|
{#each stats as stat}
|
||||||
<div
|
<div class="">
|
||||||
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 text-xs font-medium"
|
||||||
<div class="text-primary-900 dark:text-primary-100">
|
>
|
||||||
{stat.name}
|
{stat.name}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-xl font-semibold">
|
<div class="text-lg font-semibold">
|
||||||
{#if stat.format ?? true}
|
{#if stat.format ?? true}
|
||||||
<FormattedNumber
|
<FormattedNumber
|
||||||
number={Number(stat.value)}
|
number={Number(stat.value)}
|
||||||
@@ -115,9 +143,9 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
</Material>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.banner-mask {
|
.banner-mask {
|
||||||
|
|||||||
@@ -1,41 +1,55 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Disclosure } from 'mono-svelte'
|
import { Disclosure } from 'mono-svelte'
|
||||||
import { Minus, Plus, Icon } from 'svelte-hero-icons'
|
import { Minus, Plus, Icon } from 'svelte-hero-icons'
|
||||||
export let open: boolean = false
|
interface Props {
|
||||||
export let icon: boolean = true
|
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>
|
</script>
|
||||||
|
|
||||||
<Disclosure
|
<Disclosure {extended} bind:open class=" gap-2 {clazz}">
|
||||||
bind:open
|
{#snippet summary()}
|
||||||
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}
|
|
||||||
<div
|
<div
|
||||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||||
/>
|
>
|
||||||
</div>
|
<div class="flex flex-row gap-1 items-center w-full">
|
||||||
<slot name="extended" slot="extended" />
|
{@render title?.(open)}
|
||||||
<slot name="content">
|
</div>
|
||||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
{#if icon}
|
||||||
<slot />
|
<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>
|
</div>
|
||||||
</slot>
|
{/snippet}
|
||||||
|
{#if content}{@render content()}{:else}
|
||||||
|
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</Disclosure>
|
</Disclosure>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" module>
|
||||||
import { pushState } from '$app/navigation'
|
import { pushState } from '$app/navigation'
|
||||||
|
|
||||||
export function showImage(url: string, alt: string = '') {
|
export function showImage(url: string, alt: string = '') {
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/state'
|
||||||
import { Button, Material, toast } from 'mono-svelte'
|
import { Button, Material, toast } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
ArrowDownTray,
|
ArrowDownTray,
|
||||||
@@ -24,128 +24,81 @@
|
|||||||
import { focusTrap } from 'svelte-focus-trap'
|
import { focusTrap } from 'svelte-focus-trap'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
|
|
||||||
/**
|
interface Props {
|
||||||
* The full-resolution image URL
|
/**
|
||||||
*/
|
* The full-resolution image URL
|
||||||
export let alt: string = ''
|
*/
|
||||||
|
alt?: string
|
||||||
let zoomed = false
|
class?: string
|
||||||
let sharing = false
|
children?: import('svelte').Snippet
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let { alt = '', class: clazz = '', children }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $page.state.openImage || '' != ''}
|
{#if page.state.openImage || '' != ''}
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
<!-- svelte-ignore a11y-positive-tabindex -->
|
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||||
<div
|
<div
|
||||||
class="fixed top-0 left-0 w-screen h-[100svh] overflow-auto bg-white/50 dark:bg-black/50
|
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"
|
flex flex-col z-[100] backdrop-blur-sm"
|
||||||
transition:fade={{ duration: 150 }}
|
transition:fade={{ duration: 150 }}
|
||||||
on:click={() => history.back()}
|
onclick={() => history.back()}
|
||||||
on:keydown={(e) => {
|
onkeydown={(e) => {
|
||||||
if (e.key == 'Escape') history.back()
|
if (e.key == 'Escape') history.back()
|
||||||
}}
|
}}
|
||||||
use:focusTrap
|
use:focusTrap
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
width={400}
|
width={800}
|
||||||
height={400}
|
height={800}
|
||||||
src={$page.state.openImage}
|
src={page.state.openImage}
|
||||||
class="{zoomed
|
class={[
|
||||||
? 'object-cover'
|
'max-w-full mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900',
|
||||||
: '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}
|
|
||||||
transition:scale={{ start: 0.95, easing: expoOut, duration: 250 }}
|
transition:scale={{ start: 0.95, easing: expoOut, duration: 250 }}
|
||||||
{alt}
|
{alt}
|
||||||
/>
|
/>
|
||||||
<div
|
<div class="sticky z-10 bottom-4 left-1/2 -translate-x-1/2 w-max">
|
||||||
class="sticky z-10 bottom-4 left-1/2 -translate-x-1/2 w-max"
|
|
||||||
transition:fly={{ duration: 350, y: 14, easing: backOut }}
|
|
||||||
>
|
|
||||||
<Material
|
<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"
|
rounding="full"
|
||||||
padding="none"
|
padding="none"
|
||||||
color="uniform"
|
color="uniform"
|
||||||
on:click={(e) => e.stopPropagation()}
|
onclick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
download
|
onclick={() => {
|
||||||
href={$page.state.openImage}
|
navigator.clipboard.writeText(page.state.openImage)
|
||||||
color="tertiary"
|
toast({ content: $t('toast.copied') })
|
||||||
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') })
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
size="square-lg"
|
size="square-lg"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
title={$t('post.actions.more.share')}
|
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>
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
onclick={() => history.back()}
|
||||||
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()}
|
|
||||||
color="tertiary"
|
color="tertiary"
|
||||||
size="square-lg"
|
size="square-lg"
|
||||||
rounding="pill"
|
rounding="pill"
|
||||||
title={$t('post.image.close')}
|
title={$t('post.image.close')}
|
||||||
>
|
>
|
||||||
<Icon src={XMark} size="20" micro slot="prefix" />
|
{#snippet prefix()}
|
||||||
|
<Icon src={XMark} size="20" micro />
|
||||||
|
{/snippet}
|
||||||
</Button>
|
</Button>
|
||||||
</Material>
|
</Material>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button on:click={() => history.back()} class="contents {$$props.class}">
|
<button onclick={() => history.back()} class="contents {clazz}">
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</button>
|
</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