chore: Release v0.2.0-beta.0 (#1504)
This commit is contained in:
@@ -29,41 +29,12 @@ body:
|
||||
description: If possible, please provide a video that demonstrates the bug.
|
||||
validations:
|
||||
required: false
|
||||
- type: dropdown
|
||||
id: app-type
|
||||
attributes:
|
||||
label: App Type
|
||||
options:
|
||||
- Web
|
||||
- Electron / App
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: The version of the app you are using.
|
||||
placeholder: 1.0.0
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: os
|
||||
- type: textarea
|
||||
id: environment
|
||||
attributes:
|
||||
label: Operating System
|
||||
options:
|
||||
- Windows 11
|
||||
- Windows 10
|
||||
- macOS
|
||||
- Linux
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: browser-info
|
||||
attributes:
|
||||
label: Browser Info
|
||||
description: If you are using the web version, please provide your browser info.
|
||||
placeholder: Browser name and version
|
||||
label: Environment
|
||||
description: Please provide the environment in which you are using the application. You can find this information by going to Settings > About and clicking the copy button next to the version tag.
|
||||
|
||||
- type: checkboxes
|
||||
id: checkboxes
|
||||
|
||||
Vendored
+3
-2
@@ -9,8 +9,9 @@
|
||||
"tailwindCSS.experimental.classRegex": [
|
||||
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
|
||||
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
|
||||
// ["tw\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
|
||||
["tw`([^`]*)`", "([^`]*)"]
|
||||
["tw`([^`]*)`", "([^`]*)"],
|
||||
["[a-zA-Z]+[cC]lass[nN]ame[\"'`]?:\\s*[\"'`]([^\"'`]*)[\"'`]", "([^\"'`]*)"],
|
||||
["[a-zA-Z]+[cC]lass[nN]ame\\s*=\\s*[\"'`]([^\"'`]*)[\"'`]", "([^\"'`]*)"]
|
||||
],
|
||||
// If you do not want to autofix some rules on save
|
||||
// You can put this in your user settings or workspace settings
|
||||
|
||||
+88
-1
@@ -1,26 +1,49 @@
|
||||
# CHANGELOG
|
||||
|
||||
## [0.1.2-beta.0](https://github.com/RSSNext/follow/compare/v0.1.1-beta.1...v0.1.2-beta.0) (2024-11-01)
|
||||
# [0.2.0-beta.0](https://github.com/RSSNext/follow/compare/v0.1.2-beta.0...v0.2.0-beta.0) (2024-11-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* determining app is updated logic ([f61dc56](https://github.com/RSSNext/follow/commit/f61dc5664635a5d01be66da27682774f2c73b494))
|
||||
* `defineSettingPageData` remove func wrapper ([d0d4f05](https://github.com/RSSNext/follow/commit/d0d4f0564715c1786e71b0f009e86aa3a9dc4b7c))
|
||||
* add changelog ([4de6355](https://github.com/RSSNext/follow/commit/4de6355bb77ae7b00416be6827a5b71a3a724dfa))
|
||||
* add manifest to purge cache ([2f8dc0b](https://github.com/RSSNext/follow/commit/2f8dc0bc8561ebf9bb40160de8658eac799b31b0))
|
||||
* add missing event bus ([33b3ac4](https://github.com/RSSNext/follow/commit/33b3ac4c53faa617080cbcf3039cbee7fdeb1931))
|
||||
* add rsshub discover error boundary ([665c009](https://github.com/RSSNext/follow/commit/665c009bf8aec87ead601428410f56ba6756a8db))
|
||||
* add Supsense wrapper for app upgrade provider ([58f1791](https://github.com/RSSNext/follow/commit/58f1791526620f470aa11c776fd7b245d54c45ab))
|
||||
* add turbo build in ci ([7b848cd](https://github.com/RSSNext/follow/commit/7b848cd08aa4f97b1df35666166561d6fc30c5c9))
|
||||
* adjust activation toast style ([e81245e](https://github.com/RSSNext/follow/commit/e81245e395ce1829f0c185a5a184c4cba8f8406c))
|
||||
* allow select from all sidebar ([198bb17](https://github.com/RSSNext/follow/commit/198bb17d838729ec0c406a2c6eed2fba97b196b3))
|
||||
* app upgrade toast open link should in new window ([fc81546](https://github.com/RSSNext/follow/commit/fc81546bed6b07626215a57543a735001728f520))
|
||||
* app upgraded toast href error ([#1444](https://github.com/RSSNext/follow/issues/1444)) ([c875d69](https://github.com/RSSNext/follow/commit/c875d697b2a1cd9e49f3c91397531a82928e1bc8))
|
||||
* assets rewrite ([#1204](https://github.com/RSSNext/follow/issues/1204)) ([488e8ef](https://github.com/RSSNext/follow/commit/488e8effc6f00769df7dbf68d4e6d1e4e950b8e7))
|
||||
* auto archived list flash ([#1269](https://github.com/RSSNext/follow/issues/1269)) ([8d2478c](https://github.com/RSSNext/follow/commit/8d2478c6a93aa9f5a99fddc55bbb8e532e1a0fe1))
|
||||
* auto load achieved entries when show achieved button is available ([074a60d](https://github.com/RSSNext/follow/commit/074a60d3cf93bcede88ea4d70b07cf7480be4229))
|
||||
* **boost:** card text align center ([632d5d4](https://github.com/RSSNext/follow/commit/632d5d42d67999523e602fb18f59ca72543b7d7a))
|
||||
* build pre script ([8bd2de8](https://github.com/RSSNext/follow/commit/8bd2de84b898ffc1a4863d29d7056a0b9e7a9e2f))
|
||||
* can not exit entry by close button ([e654c3a](https://github.com/RSSNext/follow/commit/e654c3ac165e5eb276ba51dc4ae0ab2da230a9d1)), closes [#1311](https://github.com/RSSNext/follow/issues/1311)
|
||||
* can not play bilibili video ([11ff813](https://github.com/RSSNext/follow/commit/11ff813c450fb519292b187a15236abe7d900abb)), closes [#1376](https://github.com/RSSNext/follow/issues/1376)
|
||||
* **ci:** concurrency group ([fb0152e](https://github.com/RSSNext/follow/commit/fb0152eaec76b28ed9fc26381917ca7ec2aecb0b))
|
||||
* **ci:** forge build error ([#1500](https://github.com/RSSNext/follow/issues/1500)) ([a5e3e02](https://github.com/RSSNext/follow/commit/a5e3e0228c7088e78061801466267ebdbd288e2c))
|
||||
* **ci:** turbo not found ([c812bd7](https://github.com/RSSNext/follow/commit/c812bd71aabc63b5c9ebbe032f25aba5ac51bd64))
|
||||
* **ci:** windows build ([9f72c26](https://github.com/RSSNext/follow/commit/9f72c263a6945fe90899f85f732c0866c7f61b25))
|
||||
* **cmdk:** change default cmdk search type to feed ([4a8fdea](https://github.com/RSSNext/follow/commit/4a8fdea84a4df90313f8c577d77d3944a34aa149))
|
||||
* correct z-index in toast ([6507744](https://github.com/RSSNext/follow/commit/6507744847b6ceee093adb17076292993d525313))
|
||||
* csrf token singleton ([b4e935f](https://github.com/RSSNext/follow/commit/b4e935fba0b2f874a5c24006d5afdd54f50f3e76))
|
||||
* css editor lazy and input composition handler ([5c6004a](https://github.com/RSSNext/follow/commit/5c6004a0905c6207c6119de0d37e9a5baf744dab))
|
||||
* ctx sub menu z-index higher than root ([8daec12](https://github.com/RSSNext/follow/commit/8daec12d2c1e61260b8917ee43066b752d4c9f06))
|
||||
* debug html ([e9afc79](https://github.com/RSSNext/follow/commit/e9afc7944f4dc42be2ea530b4852e9c2f6207ac8))
|
||||
* debug proxy page ([#1439](https://github.com/RSSNext/follow/issues/1439)) ([c8d1230](https://github.com/RSSNext/follow/commit/c8d1230be753109bd7eaef45e7d0ad0399d8bd4d))
|
||||
* detecting windows11 ([#1170](https://github.com/RSSNext/follow/issues/1170)) ([2813f1d](https://github.com/RSSNext/follow/commit/2813f1d6540fcb215287dd32cbc0f8cf87cb1cb0))
|
||||
* disable `pointerDownOutside` trigger `onDismiss` ([#1215](https://github.com/RSSNext/follow/issues/1215)) ([2bf5245](https://github.com/RSSNext/follow/commit/2bf5245126bc9ef890c06afe5a825d1e1ab4059c))
|
||||
* disable auto load archive for inbox and list ([7825e16](https://github.com/RSSNext/follow/commit/7825e16b6d1230ba2c13e5ef00474fc05cc510e5))
|
||||
* **discover:** card text truncate ([557e912](https://github.com/RSSNext/follow/commit/557e91228af27251663904dfd3211c535b5b5415))
|
||||
* dnd responsive ([1f51abe](https://github.com/RSSNext/follow/commit/1f51abe3ed2fbca66e6d9ab2ab63ef71b7b9eda4))
|
||||
* entry action deps ([4eba28b](https://github.com/RSSNext/follow/commit/4eba28b76fc62133ecd0e4746b3bb0b4d341b338))
|
||||
* entry thumbnail keep origin aspect ratio ([6e04e6e](https://github.com/RSSNext/follow/commit/6e04e6eacd6346bd2869c683ec417932a0d13807))
|
||||
* entry title bar margin-left in zen mode ([25abd8f](https://github.com/RSSNext/follow/commit/25abd8ff1c42a37b741676e1b3a3312f99decb8a))
|
||||
* entry title can selectable, fixed [#1428](https://github.com/RSSNext/follow/issues/1428) ([6320c00](https://github.com/RSSNext/follow/commit/6320c00373a98846cdd92235b044fa1fd1b8266e))
|
||||
* **entry-column:** pre-render cached entries ([5065c8e](https://github.com/RSSNext/follow/commit/5065c8e52dcba1a8d8f16ce3729b7c2eb7f5a192))
|
||||
* escape for seo meta tags ([9564257](https://github.com/RSSNext/follow/commit/9564257564e417e18bdeedded9397d469e6daf14)), closes [#1232](https://github.com/RSSNext/follow/issues/1232)
|
||||
* **external:** add global 404 page ([5e49b81](https://github.com/RSSNext/follow/commit/5e49b8114e0446b734a54eea3291721d8f9656b3))
|
||||
@@ -28,37 +51,72 @@
|
||||
* **external:** remove duplicate border bottom ([32f68ee](https://github.com/RSSNext/follow/commit/32f68ee1987182271295292bff92f482c151b78b))
|
||||
* **external:** set auth config first ([ef46c70](https://github.com/RSSNext/follow/commit/ef46c70a9849c315cc8d827f4ad8a3c004003bac))
|
||||
* **external:** should hard go back to app home ([6786e20](https://github.com/RSSNext/follow/commit/6786e203031f18be0ca386dcaf1dddf4d05ae95b))
|
||||
* fallback for code can not render to html ([08acded](https://github.com/RSSNext/follow/commit/08acded2d549bc80d2ed8f180a6d89cc3a3c861a)), closes [#1142](https://github.com/RSSNext/follow/issues/1142)
|
||||
* form button align center ([589c6e4](https://github.com/RSSNext/follow/commit/589c6e469b3fecb1c46f1ec2735494da3367abec))
|
||||
* group date item z index ([8c5c62e](https://github.com/RSSNext/follow/commit/8c5c62e0d698f3a0d72a2ef0595e44986c95320b))
|
||||
* handle tipUsers migration for older feed versions ([#1384](https://github.com/RSSNext/follow/issues/1384)) ([2ca6d80](https://github.com/RSSNext/follow/commit/2ca6d807e3c0626eca79dd6789ae20cdc0639fc3))
|
||||
* handling default port in proxy configuration ([0bd76a2](https://github.com/RSSNext/follow/commit/0bd76a24a240951782d44b7e38040c305bb2b9b9))
|
||||
* hide cache control in web ([961bd0f](https://github.com/RSSNext/follow/commit/961bd0fccd63e7e9a21c9bea62cd426bac9a8423))
|
||||
* hide to tray on close window ([392135b](https://github.com/RSSNext/follow/commit/392135b8c4b4ec00aa49e66b28bcb0e77390683a))
|
||||
* hot key switch view ([45d0fd9](https://github.com/RSSNext/follow/commit/45d0fd914f374bb7217e9a48c48bc1df4a5a8c6e))
|
||||
* html table to markdown error ([#1288](https://github.com/RSSNext/follow/issues/1288)) ([8d1ca24](https://github.com/RSSNext/follow/commit/8d1ca24f18859f5651559c77cef6fc30ce228f00))
|
||||
* **i18n:** remove `external` ns in renderer ([229b3e1](https://github.com/RSSNext/follow/commit/229b3e18f50c81c916f877a2a65325e3dcaa783a))
|
||||
* **i18n:** update label for notification badge settings in zh-CN locale and others ([#1455](https://github.com/RSSNext/follow/issues/1455)) ([ec82f03](https://github.com/RSSNext/follow/commit/ec82f036b44a3d0d463c48c1d793fc517def1d07))
|
||||
* immer object extensible ([6ad35ad](https://github.com/RSSNext/follow/commit/6ad35ad6712a68db9e231bf5733a2956ccecda90))
|
||||
* initializeDayjs in server ([d408581](https://github.com/RSSNext/follow/commit/d408581a13ad78d5a871d98f3ff0ff9bb5e45ae5)), closes [#1198](https://github.com/RSSNext/follow/issues/1198)
|
||||
* inline image style ([1d0eca1](https://github.com/RSSNext/follow/commit/1d0eca1ca16621634d0d0957b1d4d6c5f037498c)), closes [#1318](https://github.com/RSSNext/follow/issues/1318)
|
||||
* input and toast font style use user custom font ([#1322](https://github.com/RSSNext/follow/issues/1322)) ([c40becf](https://github.com/RSSNext/follow/commit/c40becff782e129c42984b354f2004b82c7f2615))
|
||||
* md lint ([c8e556a](https://github.com/RSSNext/follow/commit/c8e556a3ac861cab4a4a7aff1aa2fa51aaca1f42))
|
||||
* missing site url in feed selector ([ea677ac](https://github.com/RSSNext/follow/commit/ea677ac6a3a43489a9508a32ecb22fa38ecf4f27))
|
||||
* modal bottom buttons align ([#1216](https://github.com/RSSNext/follow/issues/1216)) ([b97096d](https://github.com/RSSNext/follow/commit/b97096dbd06bb7687b6c1313de45d8e91dee25af))
|
||||
* modal close button overlaps the select content ([#1166](https://github.com/RSSNext/follow/issues/1166)) ([3c103ed](https://github.com/RSSNext/follow/commit/3c103ed15daeb1f57a001d615c047c303087ba46))
|
||||
* **modal:** close button can not click on electron ([c544dfc](https://github.com/RSSNext/follow/commit/c544dfcc8d4613e8d4f6025dd8a60cf679881680))
|
||||
* **modal:** drawer modal layout symmetric padding ([7141e86](https://github.com/RSSNext/follow/commit/7141e869dfc9328e3eeeda909ea2ffc7e6dd0e34))
|
||||
* **modal:** fixed close modal button position ([78e9424](https://github.com/RSSNext/follow/commit/78e942473fff309e372708b56a59a9009d5bb0e9))
|
||||
* **modal:** modal dismiss action ([b05ff50](https://github.com/RSSNext/follow/commit/b05ff50f14660f20ed881f6aeabb732d80c9539c))
|
||||
* **modal:** repeat user profile dialog ([#1155](https://github.com/RSSNext/follow/issues/1155)) ([ad86372](https://github.com/RSSNext/follow/commit/ad86372bfb345b6f921da783c401be30cdbe4b89))
|
||||
* not showing feed certification icon on the sidebar ([#1442](https://github.com/RSSNext/follow/issues/1442)) ([b395891](https://github.com/RSSNext/follow/commit/b395891b66a581254f24aae75d0d61869fb6fb33))
|
||||
* only show ComboboxOptions when there are suggestions ([136aa20](https://github.com/RSSNext/follow/commit/136aa205794b6193826d1839350e65228d2b4f20))
|
||||
* optimize some styles ([9b99bf4](https://github.com/RSSNext/follow/commit/9b99bf4428cf6f1ca3218a3074a944af4d014f57))
|
||||
* optimize the animation of the Follow button on the User Profile Modal ([#1156](https://github.com/RSSNext/follow/issues/1156)) ([87717d6](https://github.com/RSSNext/follow/commit/87717d642607cca4254f11d673a8a910fc6ab076))
|
||||
* pass a component for Trans ([7d38cb6](https://github.com/RSSNext/follow/commit/7d38cb6d2f814d3b6012b66ba6024c05b6edcf2d))
|
||||
* pnpm lockfile ([fdc547a](https://github.com/RSSNext/follow/commit/fdc547a5aaeb11aa13d6321ea60f1d3a4e01a8b4))
|
||||
* power icon align ([11059f6](https://github.com/RSSNext/follow/commit/11059f639ee955a0f10cbd97cb6eed85e335fed7))
|
||||
* preferred title not working in entry column ([#1268](https://github.com/RSSNext/follow/issues/1268)) ([4bdf28e](https://github.com/RSSNext/follow/commit/4bdf28ea766242c74af051e36a9ef205f02eb874))
|
||||
* prevent default for cmd+k ([81d49f0](https://github.com/RSSNext/follow/commit/81d49f0893100de85a22d114765f76e7c9dea36c))
|
||||
* prevent default scrolling behavior while using arrow keys to switch between entries ([#1447](https://github.com/RSSNext/follow/issues/1447)) ([ed5ee50](https://github.com/RSSNext/follow/commit/ed5ee50fe2676309e5451d73531baf59bbf0d746))
|
||||
* prevent withdrawal of zero amount to avoid unnecessary fees ([#1422](https://github.com/RSSNext/follow/issues/1422)) ([6584526](https://github.com/RSSNext/follow/commit/65845268f9940247d3b645b1588d1564ec0b4cff))
|
||||
* **profile-menu:** limit max-char ([8a72a97](https://github.com/RSSNext/follow/commit/8a72a97c0ce145a65583fafe792ae99a634c52c3))
|
||||
* reduce timeline refresh, fixed [#1474](https://github.com/RSSNext/follow/issues/1474) ([6fc9d09](https://github.com/RSSNext/follow/commit/6fc9d09c586618efb2d1b62b062fa04e26dc7986))
|
||||
* reduce upgrade toast duration and disable prompt on nightly version, fixed 1450 ([7f2ac96](https://github.com/RSSNext/follow/commit/7f2ac967ebc900e57b09bf4c945412e84943ebb2))
|
||||
* refetch wallet data on mount ([2d11eb2](https://github.com/RSSNext/follow/commit/2d11eb2d92fb57222b14df987b57a75eb9262fc5))
|
||||
* relogin ([80515f6](https://github.com/RSSNext/follow/commit/80515f67652a77fbdbe20a2a3298fd916515a8d7))
|
||||
* remove `useSingleton` ([d1d3fcf](https://github.com/RSSNext/follow/commit/d1d3fcf493bf26ce58cd33fedd7320cfcfe8ef5f))
|
||||
* remove cache-control header ([#1202](https://github.com/RSSNext/follow/issues/1202)) ([c683bda](https://github.com/RSSNext/follow/commit/c683bdaef63716659ca78875022ff38350e50b82))
|
||||
* remove gcore icon ([#1220](https://github.com/RSSNext/follow/issues/1220)) ([486fa20](https://github.com/RSSNext/follow/commit/486fa202ee9488981a733f235f95c90a073e7166))
|
||||
* remove immer set to avoid object extensible ([7e5a791](https://github.com/RSSNext/follow/commit/7e5a79155a083a8242579dee18d019049b7ad6f5))
|
||||
* remove vercel header rewrite for assets ([79e6f48](https://github.com/RSSNext/follow/commit/79e6f483265216773e0ccf5ac0690d06300d3e80))
|
||||
* response error toast style ([7748588](https://github.com/RSSNext/follow/commit/77485886089e9faea54cf80a96a48a0bedd2a39e))
|
||||
* scroll bar z index ([5057999](https://github.com/RSSNext/follow/commit/50579995367b871e84768c5983b3302f75f8e077)), closes [#1233](https://github.com/RSSNext/follow/issues/1233)
|
||||
* **server:** complie esmodule ([c438119](https://github.com/RSSNext/follow/commit/c438119ea8208f4da14da2294a381a6c34a14e25))
|
||||
* **server:** serialize data ([2410b84](https://github.com/RSSNext/follow/commit/2410b843af3d16f77e88482d9c73f25c1dd3431a))
|
||||
* **server:** use `xss` to serialize data ([93f58ec](https://github.com/RSSNext/follow/commit/93f58ecfd8fadfa67f56ebfe629e73f44bb94a49))
|
||||
* set referer ([29557f3](https://github.com/RSSNext/follow/commit/29557f370f37f7f5c7d1f7ccd7157a4449f7e5ca))
|
||||
* set windows env ([1ea103b](https://github.com/RSSNext/follow/commit/1ea103b7ee1689ba9683c341a2afacacf2884fbd))
|
||||
* setting loader type error ([da8aad7](https://github.com/RSSNext/follow/commit/da8aad7327d45cd899f8091cb0315ff2497b2ab9))
|
||||
* setting loader type error ([#1469](https://github.com/RSSNext/follow/issues/1469)) ([6ef5622](https://github.com/RSSNext/follow/commit/6ef5622a32eaaebfeec32cca1000bf908f742e34))
|
||||
* **share:** normal list item layout ([3a0c039](https://github.com/RSSNext/follow/commit/3a0c0393e01e09ebf86ab1415b3d84bca6d2b882))
|
||||
* **share:** og image grid width and image align top to description ([14e37da](https://github.com/RSSNext/follow/commit/14e37da0cebbdb1b283c562c21acc2f8ba385bf9))
|
||||
* **shortcut:** add cmd+k to guide ([e9ab9b6](https://github.com/RSSNext/follow/commit/e9ab9b6f379abe426ac751961e3767c8aa20b663))
|
||||
* should remove app skeleton in error page ([4073632](https://github.com/RSSNext/follow/commit/4073632dbf236e19926e013d5048f59f90d9b3ae))
|
||||
* shouldLoadArchivedEntries condition ([94b097f](https://github.com/RSSNext/follow/commit/94b097fd25533b5d1437bf1054dbe44af7828099))
|
||||
* show action limit message ([2ac52eb](https://github.com/RSSNext/follow/commit/2ac52ebda3b4cb06e00ce2759f2cac7cd5d86f3d)), closes [#1360](https://github.com/RSSNext/follow/issues/1360)
|
||||
* show scrollbar when list table overflows in settings menu ([#1266](https://github.com/RSSNext/follow/issues/1266)) ([47b200f](https://github.com/RSSNext/follow/commit/47b200f7f3340b5b262674c71e876328ec758192))
|
||||
* sidebar copy feed url, fixed [#1361](https://github.com/RSSNext/follow/issues/1361) ([4e84196](https://github.com/RSSNext/follow/commit/4e841964e6573fa20ae214538b04dd0dc18a6f5e))
|
||||
* **store:** immer draft should to raw ([3a3992d](https://github.com/RSSNext/follow/commit/3a3992d63f0f62cd37aa5accb4910ad79e3190e8))
|
||||
* **store:** singleton store guard ([5a8725b](https://github.com/RSSNext/follow/commit/5a8725b50767bb6faddca6e0af6cef2cfb28da29))
|
||||
* **stream:** prevent request if no ids ([a92ef49](https://github.com/RSSNext/follow/commit/a92ef49dedf480f519525cf8f25a0e5383b27059))
|
||||
* the volume bar can click and adjust style. ([#1474](https://github.com/RSSNext/follow/issues/1474)) ([c409a5c](https://github.com/RSSNext/follow/commit/c409a5c7945eb178fca5274dd6ac64f82025821d))
|
||||
* theme cannot be switched ([#1157](https://github.com/RSSNext/follow/issues/1157)) ([d5be028](https://github.com/RSSNext/follow/commit/d5be0287ad03e47635be057222ca7155a033ae80))
|
||||
* **toc:** fix text truncate in title line ([f9b1a61](https://github.com/RSSNext/follow/commit/f9b1a61c0185b449184b34df5f3a3869a4e722a4))
|
||||
* **toc:** should focus when toc item clicked ([f51dfdd](https://github.com/RSSNext/follow/commit/f51dfddc9ef40f4a7f226f32f9357e03a04f6ee0))
|
||||
@@ -66,8 +124,13 @@
|
||||
* try fix dayjs init ([093f80d](https://github.com/RSSNext/follow/commit/093f80d9da223c567125285cc0f312f419bb4042))
|
||||
* ts import ([14311dd](https://github.com/RSSNext/follow/commit/14311dde0a9cb14e797e1a0f654a11f8502e58f8))
|
||||
* turbo build cmd ([0b9c279](https://github.com/RSSNext/follow/commit/0b9c279fccd25231b90810359125571f817b7f7c))
|
||||
* **ui:** resolve conflict between video progress bar and swiper drag … ([#1337](https://github.com/RSSNext/follow/issues/1337)) ([aa9206f](https://github.com/RSSNext/follow/commit/aa9206f5b1e3ea0c008f912ef22cdaa406546251))
|
||||
* **ui:** use safe inset top to fix windows overlays, fixed [#1184](https://github.com/RSSNext/follow/issues/1184) ([dc85570](https://github.com/RSSNext/follow/commit/dc855703289ac98db76f4a57760fcd66047b8dd1))
|
||||
* **ui:** user profile follow button style ([d629215](https://github.com/RSSNext/follow/commit/d629215305a0ec9323dea0db929582e9609a82f6))
|
||||
* update daily claim amount reference in tooltip ([#1487](https://github.com/RSSNext/follow/issues/1487)) ([3792c2d](https://github.com/RSSNext/follow/commit/3792c2d850d9fc3f96ea4591784b61c631ee7e86))
|
||||
* update version toast ([25e7cea](https://github.com/RSSNext/follow/commit/25e7cea3c139335960c3de2922cf0ffa9c9c6c39)), closes [#1450](https://github.com/RSSNext/follow/issues/1450)
|
||||
* **upgrade:** changelog container should w-full ([1551bf6](https://github.com/RSSNext/follow/commit/1551bf648c511cbf615f515b2e2d93077b0e42b4))
|
||||
* vercel do not support `__` prefix for api route ([45a66e0](https://github.com/RSSNext/follow/commit/45a66e0f972d18831795d92b1d3c1f3893f396dc))
|
||||
* vercel rewrite config ([#1203](https://github.com/RSSNext/follow/issues/1203)) ([c954d61](https://github.com/RSSNext/follow/commit/c954d61f074e282a9a86cbf1d1546748871c20e7))
|
||||
|
||||
|
||||
@@ -75,23 +138,45 @@
|
||||
|
||||
* add app skeleton to avoid blank page when js loaded ([e2ed162](https://github.com/RSSNext/follow/commit/e2ed162b67d53452af01fe3a7aad3d70c995ff8d))
|
||||
* add appearance to set thumbnail ratio ([1d3f6bc](https://github.com/RSSNext/follow/commit/1d3f6bc910e3878debca3a7576f3891e6947b443))
|
||||
* add application tray functionality ([#1416](https://github.com/RSSNext/follow/issues/1416)) ([76a6e38](https://github.com/RSSNext/follow/commit/76a6e38376a01dbeee83161cdce9fe5e205b1523))
|
||||
* add follow user button in profile modal ([#1147](https://github.com/RSSNext/follow/issues/1147)) ([7c60d5e](https://github.com/RSSNext/follow/commit/7c60d5e91dd4a21872217427bd99fe8eae688ce1))
|
||||
* add hydrate data type-safe helper ([cb6a65b](https://github.com/RSSNext/follow/commit/cb6a65b7cc1651d86b83b5b4089a7145cd59b0be))
|
||||
* add random color for user fallback bg ([dcbae89](https://github.com/RSSNext/follow/commit/dcbae89020e88947be693c100c644ee603519e96))
|
||||
* add sentry trace id ([40843ac](https://github.com/RSSNext/follow/commit/40843ac79f390d0db81490522475a3557f57b2e4))
|
||||
* add server announcement toast ([7b34357](https://github.com/RSSNext/follow/commit/7b3435749b8516466eae388172694f22d6b26a83))
|
||||
* add updatelog modal ([84228bc](https://github.com/RSSNext/follow/commit/84228bc5c8755c4b957bc901e6e552ef176ed00c))
|
||||
* adjust more ui ([08929ab](https://github.com/RSSNext/follow/commit/08929ab3ae15758850d04b82f7773358579c4a78))
|
||||
* **app:** support cache limit and clean cache ([dee294d](https://github.com/RSSNext/follow/commit/dee294dda589ca9e2eaee8a7e55197635b6323c7))
|
||||
* bring rehypeUrlToAnchor back ([6f0cc4d](https://github.com/RSSNext/follow/commit/6f0cc4d566c9f2f552f0fedf1a8e570a817e0f56)), closes [#1373](https://github.com/RSSNext/follow/issues/1373)
|
||||
* **discover:** enhance RSSHub recommendations with filters ([#1481](https://github.com/RSSNext/follow/issues/1481)) ([eb70126](https://github.com/RSSNext/follow/commit/eb70126b8283b6e0b246f86751e588a37cb34902))
|
||||
* **discover:** improve trending style and discover no image placeholer ([86be1a2](https://github.com/RSSNext/follow/commit/86be1a2e46d3298157cece0731e687a462f833d5))
|
||||
* dnd ([#1471](https://github.com/RSSNext/follow/issues/1471)) ([c9333d5](https://github.com/RSSNext/follow/commit/c9333d5004c170955ab96b9f7f5a2825e1042271))
|
||||
* entry image gallery modal ([e0d3e17](https://github.com/RSSNext/follow/commit/e0d3e17da4ee17217d7b78871b546f43af87d893))
|
||||
* export database ([85b4502](https://github.com/RSSNext/follow/commit/85b4502f9c113b8de73ccf4a167aa514a3c149ea))
|
||||
* **external:** move `login` and `redirect` route to external ([7916803](https://github.com/RSSNext/follow/commit/791680332d5e1c2c52eda792dd7ff69281f25adb))
|
||||
* **external:** new open by deeplink logic ([71fcf50](https://github.com/RSSNext/follow/commit/71fcf50d0fd3ac30f8e9c45db90314672904a615))
|
||||
* fetch stream entry content ([1739208](https://github.com/RSSNext/follow/commit/173920802edf1f4e13eee68bf5d541391ca6ebf9))
|
||||
* focusable ([eb01d03](https://github.com/RSSNext/follow/commit/eb01d030129f6196d6e9855be42a218be9d5668b))
|
||||
* hide trend ([2b92599](https://github.com/RSSNext/follow/commit/2b92599e18d3d33fd0371d4d3a5f3e3a6d94aeb6))
|
||||
* **icon:** use gradient fallback background ([e827002](https://github.com/RSSNext/follow/commit/e8270025e469d9a0463d267d3da591a2991951bd))
|
||||
* **integration:** add outline integration ([#1229](https://github.com/RSSNext/follow/issues/1229)) ([0d0266b](https://github.com/RSSNext/follow/commit/0d0266b25189a74efdc63ce0062f3a379d4a0729))
|
||||
* List delete add secondary confirmation ([#1254](https://github.com/RSSNext/follow/issues/1254)) ([14f2bac](https://github.com/RSSNext/follow/commit/14f2bac8f3ba7e8f2dbd3958a4394c5b11ea2537))
|
||||
* load archived entries automatically ([5fe9e0c](https://github.com/RSSNext/follow/commit/5fe9e0c0e24460ca0fe435db03b753e9dcd3df17))
|
||||
* **mark-all-button:** add countdown to auto-confirm message ([#1414](https://github.com/RSSNext/follow/issues/1414)) ([e1a5fc6](https://github.com/RSSNext/follow/commit/e1a5fc63f20c941140071789c9b67685da19ea5c))
|
||||
* move hideExtraBadge ([2f14c30](https://github.com/RSSNext/follow/commit/2f14c30307a895bc866ac57989df1dc624eab4e6))
|
||||
* **obsidian:** use readability content when available ([b4a3197](https://github.com/RSSNext/follow/commit/b4a3197e6ebd39bb259a6bc67f408569354a205e))
|
||||
* prefer origin addresses for content images ([d4d4345](https://github.com/RSSNext/follow/commit/d4d43451dec839b64239e1835b2ac1a1aa2478be))
|
||||
* **reader:** support custom css, fixed [#256](https://github.com/RSSNext/follow/issues/256) ([b251fa9](https://github.com/RSSNext/follow/commit/b251fa9421417c75d71707c8f08850f2cc902e1a))
|
||||
* **renderer:** prevent currently executing async entry action from being executed again ([#1348](https://github.com/RSSNext/follow/issues/1348)) ([be82fe2](https://github.com/RSSNext/follow/commit/be82fe2a8ce37bac7205a1a43abeca396fdadba6))
|
||||
* replace twMacro with unplugin-ast ([#1462](https://github.com/RSSNext/follow/issues/1462)) ([05da9ca](https://github.com/RSSNext/follow/commit/05da9ca7d3d1f66bd22250599df8b66ea0fd3a43))
|
||||
* reset feed ([#1419](https://github.com/RSSNext/follow/issues/1419)) ([9066758](https://github.com/RSSNext/follow/commit/9066758c322b8b31c1a9a137be017283fa92bea8))
|
||||
* separate packaging for macOS x64 and arm64 architectures ([#1389](https://github.com/RSSNext/follow/issues/1389)) ([3e8de30](https://github.com/RSSNext/follow/commit/3e8de308a3b3a07c58ab3fd7d26aad5aa2328c99))
|
||||
* show progress in searching ([e592e97](https://github.com/RSSNext/follow/commit/e592e97c9e0e6da8451c09b9b5f27612e6dbb971)), closes [#1457](https://github.com/RSSNext/follow/issues/1457)
|
||||
* support markdown for announcement content ([539ec03](https://github.com/RSSNext/follow/commit/539ec03293fc6e3a11dbec69bbf78fe1c5dd2e8c))
|
||||
* support zen mode sidebar entry timeline selector ([4ab132c](https://github.com/RSSNext/follow/commit/4ab132c593a7acce0167d02f6025030775a9fac5))
|
||||
* unified feed title ([b86afe5](https://github.com/RSSNext/follow/commit/b86afe5a9789ad13c5a026adf553d2c6bc333bff))
|
||||
* update og image ([c58df35](https://github.com/RSSNext/follow/commit/c58df35d1f48e7374973a393c9b7efea38d12494))
|
||||
* update og image ([142f9f5](https://github.com/RSSNext/follow/commit/142f9f57ce2697ab82fd5e1dd2cee7d0f7500721))
|
||||
* use FeedTitle ([73d2c30](https://github.com/RSSNext/follow/commit/73d2c30416ad3f2da626db003996c0fb036025ac))
|
||||
* **ux:** support native space key to page down, fixed [#1121](https://github.com/RSSNext/follow/issues/1121) ([baa66fe](https://github.com/RSSNext/follow/commit/baa66feaf19416d2b9e5efe6b79f6af1b3966404))
|
||||
* zen mode and hide extra badge ([7ba07ad](https://github.com/RSSNext/follow/commit/7ba07adff1e7cd3292cc308f3e70803fe11fb8ce))
|
||||
@@ -99,6 +184,8 @@
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* batch profile ([#1464](https://github.com/RSSNext/follow/issues/1464)) ([a3e9c0e](https://github.com/RSSNext/follow/commit/a3e9c0edc83628d9c0ceb998d95184c5fd635f6f))
|
||||
* optmize masonry perfermance ([d1748c6](https://github.com/RSSNext/follow/commit/d1748c6ce93f7075270d8cc6e88cbd944d165d50))
|
||||
* resolve feed item select area performance problem ([f87c0ff](https://github.com/RSSNext/follow/commit/f87c0ff2abfc430719894765796ca457c3f8e7f0))
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import crypto from "node:crypto"
|
||||
|
||||
import type { VercelRequest, VercelResponse } from "@vercel/node"
|
||||
import getRawBody from "raw-body"
|
||||
|
||||
export default async function handler(request: VercelRequest, response: VercelResponse) {
|
||||
const { WEBHOOK_SECRET: INTEGRATION_SECRET } = process.env
|
||||
|
||||
if (typeof INTEGRATION_SECRET != "string") {
|
||||
return response.status(400).json({
|
||||
code: "invalid_secret",
|
||||
error: "No integration secret found",
|
||||
})
|
||||
}
|
||||
|
||||
const rawBody = await getRawBody(request)
|
||||
const bodySignature = sha1(rawBody, INTEGRATION_SECRET)
|
||||
|
||||
if (bodySignature !== request.headers["x-vercel-signature"]) {
|
||||
return response.status(403).json({
|
||||
code: "invalid_signature",
|
||||
error: "signature didn't match",
|
||||
})
|
||||
}
|
||||
|
||||
const json = JSON.parse(rawBody.toString("utf-8"))
|
||||
|
||||
switch (json.type) {
|
||||
// https://vercel.com/docs/observability/webhooks-overview/webhooks-api#deployment.succeeded
|
||||
case "deployment.succeeded": {
|
||||
const { target } = json.payload || json.data
|
||||
|
||||
if (target === "production") {
|
||||
await purgeCloudflareCache()
|
||||
} else {
|
||||
console.info(`Skipping non-production deployment: ${target}`, json)
|
||||
}
|
||||
}
|
||||
// ...
|
||||
}
|
||||
|
||||
return response.status(200).end("OK")
|
||||
}
|
||||
|
||||
function sha1(data: Buffer, secret: string): string {
|
||||
return crypto.createHmac("sha1", secret).update(data).digest("hex")
|
||||
}
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false,
|
||||
},
|
||||
}
|
||||
|
||||
async function purgeCloudflareCache() {
|
||||
const { CF_TOKEN, CF_ZONE_ID } = process.env
|
||||
|
||||
if (typeof CF_TOKEN !== "string" || typeof CF_ZONE_ID !== "string") {
|
||||
throw new TypeError("No Cloudflare token or zone ID found")
|
||||
}
|
||||
|
||||
const apiUrl = `https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/purge_cache`
|
||||
|
||||
const manifestPath = await fetch(
|
||||
`https://app.follow.is/assets/manifest.txt?t=${Date.now()}`,
|
||||
).then((res) => res.text())
|
||||
|
||||
const allPath = manifestPath.split("\n").map((path) => `https://app.follow.is/${path}`)
|
||||
|
||||
// Function to delay execution
|
||||
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
||||
|
||||
const taskPromise = [] as Promise<Response>[]
|
||||
// Batch processing
|
||||
for (let i = 0; i < allPath.length; i += 30) {
|
||||
const batch = allPath.slice(i, i + 30)
|
||||
|
||||
const r = fetch(apiUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: CF_TOKEN,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
files: batch,
|
||||
}),
|
||||
})
|
||||
|
||||
taskPromise.push(r)
|
||||
|
||||
// Delay for 0.5 seconds between batches
|
||||
if (i + 30 < allPath.length) {
|
||||
await delay(500)
|
||||
}
|
||||
}
|
||||
|
||||
const result = await Promise.allSettled(taskPromise)
|
||||
console.info(`Success: ${result.filter((r) => r.status === "fulfilled").length}`)
|
||||
console.info(`Failed: ${result.filter((r) => r.status === "rejected").length}`)
|
||||
}
|
||||
@@ -25,17 +25,18 @@
|
||||
"@egoist/tipc": "0.3.2",
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@electron-toolkit/utils": "^3.0.0",
|
||||
"@eneris/push-receiver": "4.2.0",
|
||||
"@eneris/push-receiver": "4.3.0",
|
||||
"@follow/shared": "workspace:*",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@sentry/electron": "5.6.0",
|
||||
"@sentry/electron": "5.7.0",
|
||||
"builder-util-runtime": "9.2.10",
|
||||
"electron-context-menu": "4.0.4",
|
||||
"electron-log": "5.2.0",
|
||||
"electron-squirrel-startup": "1.0.1",
|
||||
"electron-updater": "^6.3.9",
|
||||
"fast-folder-size": "2.3.0",
|
||||
"font-list": "1.5.1",
|
||||
"i18next": "^23.16.0",
|
||||
"i18next": "^23.16.4",
|
||||
"linkedom": "^0.18.5",
|
||||
"lowdb": "7.0.1",
|
||||
"msedge-tts": "1.3.4",
|
||||
@@ -45,9 +46,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/node": "^22.7.5",
|
||||
"electron": "33.0.0",
|
||||
"@types/node": "^22.8.7",
|
||||
"electron": "33.0.2",
|
||||
"electron-devtools-installer": "3.2.0",
|
||||
"hono": "4.6.5"
|
||||
"hono": "4.6.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
// 5min
|
||||
export const UNREAD_BACKGROUND_POLLING_INTERVAL = 1000 * 60 * 5
|
||||
|
||||
// https://github.com/electron/electron/issues/25081
|
||||
export const START_IN_TRAY_ARGS = "--start-in-tray"
|
||||
|
||||
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url"
|
||||
const __dirname = fileURLToPath(new URL(".", import.meta.url))
|
||||
const iconMap = {
|
||||
prod: path.join(__dirname, "../../resources/icon.png"),
|
||||
dev: path.join(__dirname, "../../resources/icon-dev.png"),
|
||||
dev: path.join(__dirname, "../../static/icon-dev.png"),
|
||||
}
|
||||
export const getIconPath = () => iconMap[process.env.NODE_ENV === "development" ? "dev" : "prod"]
|
||||
export const getTrayIconPath = () => path.join(__dirname, "../../resources/tray-icon.png")
|
||||
|
||||
+14
-8
@@ -11,9 +11,15 @@ import { initializeAppStage0, initializeAppStage1 } from "./init"
|
||||
import { updateProxy } from "./lib/proxy"
|
||||
import { handleUrlRouting } from "./lib/router"
|
||||
import { store } from "./lib/store"
|
||||
import { registerAppTray } from "./lib/tray"
|
||||
import { setAuthSessionToken, updateNotificationsToken } from "./lib/user"
|
||||
import { registerUpdater } from "./updater"
|
||||
import { createMainWindow, getMainWindow, windowStateStoreKey } from "./window"
|
||||
import {
|
||||
createMainWindow,
|
||||
getMainWindow,
|
||||
getMainWindowOrCreate,
|
||||
windowStateStoreKey,
|
||||
} from "./window"
|
||||
|
||||
if (isDev) console.info("[main] env loaded:", env)
|
||||
|
||||
@@ -65,6 +71,7 @@ function bootstrap() {
|
||||
|
||||
updateProxy()
|
||||
registerUpdater()
|
||||
registerAppTray()
|
||||
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
// remove Electron, Follow from user agent
|
||||
@@ -81,8 +88,10 @@ function bootstrap() {
|
||||
details.requestHeaders["Origin"] = "https://app.follow.is"
|
||||
} else {
|
||||
const refererMatch = imageRefererMatches.find((item) => item.url.test(details.url))
|
||||
const referer = refererMatch?.referer || details.url
|
||||
details.requestHeaders["Referer"] = referer
|
||||
const referer = refererMatch?.referer
|
||||
if (referer) {
|
||||
details.requestHeaders["Referer"] = referer
|
||||
}
|
||||
}
|
||||
|
||||
callback({ cancel: false, requestHeaders: details.requestHeaders })
|
||||
@@ -91,11 +100,8 @@ function bootstrap() {
|
||||
app.on("activate", () => {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
mainWindow = createMainWindow()
|
||||
}
|
||||
|
||||
if (mainWindow) mainWindow.show()
|
||||
mainWindow = getMainWindowOrCreate()
|
||||
mainWindow.show()
|
||||
})
|
||||
|
||||
app.on("open-url", (_, url) => {
|
||||
|
||||
@@ -9,6 +9,7 @@ import { app, nativeTheme, Notification, shell } from "electron"
|
||||
import contextMenu from "electron-context-menu"
|
||||
|
||||
import { getIconPath } from "./helper"
|
||||
import { clearCacheCronJob } from "./lib/cleaner"
|
||||
import { t } from "./lib/i18n"
|
||||
import { store } from "./lib/store"
|
||||
import { updateNotificationsToken } from "./lib/user"
|
||||
@@ -59,6 +60,7 @@ export const initializeAppStage1 = () => {
|
||||
registerMenuAndContextMenu()
|
||||
|
||||
registerPushNotifications()
|
||||
clearCacheCronJob()
|
||||
}
|
||||
|
||||
let contextMenuDisposer: () => void
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ofetch } from "ofetch"
|
||||
|
||||
import type { AppType } from "../../../../packages/shared/src/hono"
|
||||
import { logger } from "../logger"
|
||||
import { getAuthSessionToken } from "./user"
|
||||
import { getAuthSessionToken, getUser } from "./user"
|
||||
|
||||
const abortController = new AbortController()
|
||||
export const apiFetch = ofetch.create({
|
||||
@@ -33,10 +33,12 @@ export const apiClient = hc<AppType>("", {
|
||||
fetch: async (input, options = {}) => apiFetch(input.toString(), options),
|
||||
headers() {
|
||||
const authSessionToken = getAuthSessionToken()
|
||||
const user = getUser()
|
||||
return {
|
||||
"X-App-Version": PKG.version,
|
||||
"X-App-Dev": process.env.NODE_ENV === "development" ? "1" : "0",
|
||||
Cookie: authSessionToken ? `authjs.session-token=${authSessionToken}` : "",
|
||||
"User-Agent": `Follow/${PKG.version}${user?.id ? ` uid: ${user.id}` : ""}`,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { callWindowExpose } from "@follow/shared/bridge"
|
||||
import { dialog } from "electron"
|
||||
import { statSync } from "node:fs"
|
||||
import fsp from "node:fs/promises"
|
||||
import { createRequire } from "node:module"
|
||||
import path from "node:path"
|
||||
import { promisify } from "node:util"
|
||||
|
||||
import { callWindowExpose } from "@follow/shared/bridge"
|
||||
import { app, dialog } from "electron"
|
||||
|
||||
import { logger } from "~/logger"
|
||||
import { getMainWindow } from "~/window"
|
||||
|
||||
import { t } from "./i18n"
|
||||
import { store, StoreKey } from "./store"
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const fastFolderSize = require("fast-folder-size") as any as typeof import("fast-folder-size")
|
||||
|
||||
export const clearAllDataAndConfirm = async () => {
|
||||
const win = getMainWindow()
|
||||
@@ -53,3 +64,75 @@ export const clearAllData = async () => {
|
||||
caller.toast.error(`Error resetting app data: ${error.message}`)
|
||||
}
|
||||
}
|
||||
const fastFolderSizeAsync = promisify(fastFolderSize)
|
||||
export const getCacheSize = async () => {
|
||||
const cachePath = path.join(app.getPath("userData"), "cache")
|
||||
|
||||
// Size is in bytes
|
||||
const sizeInBytes = await fastFolderSizeAsync(cachePath)
|
||||
return sizeInBytes || 0
|
||||
}
|
||||
|
||||
const getCachedFilesRecursive = async (dir: string, result: string[] = []) => {
|
||||
const files = await fsp.readdir(dir)
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir, file)
|
||||
const stat = await fsp.stat(filePath)
|
||||
if (stat.isDirectory()) {
|
||||
const files = await getCachedFilesRecursive(filePath)
|
||||
result.push(...files)
|
||||
} else {
|
||||
result.push(filePath)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
export const clearCacheCronJob = () => {
|
||||
if (timer) {
|
||||
timer = clearInterval(timer)
|
||||
}
|
||||
timer = setInterval(
|
||||
async () => {
|
||||
const hasLimit = store.get(StoreKey.CacheSizeLimit)
|
||||
|
||||
if (!hasLimit) {
|
||||
return
|
||||
}
|
||||
|
||||
const cacheSize = await getCacheSize()
|
||||
|
||||
const limitByteSize = hasLimit * 1024 * 1024
|
||||
if (cacheSize > limitByteSize) {
|
||||
const shouldCleanSize = cacheSize - limitByteSize - 1024 * 1024 * 50 // 50MB
|
||||
|
||||
const cachePath = path.join(app.getPath("userData"), "cache")
|
||||
const files = await getCachedFilesRecursive(cachePath)
|
||||
// Sort by last modified
|
||||
files.sort((a, b) => {
|
||||
const aStat = statSync(a)
|
||||
const bStat = statSync(b)
|
||||
return bStat.mtime.getTime() - aStat.mtime.getTime()
|
||||
})
|
||||
|
||||
let cleanedSize = 0
|
||||
for (const file of files) {
|
||||
const fileSize = statSync(file).size
|
||||
cleanedSize += fileSize
|
||||
if (cleanedSize >= shouldCleanSize) {
|
||||
logger.info(`Cleaned ${cleanedSize} bytes cache`)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
10 * 60 * 1000,
|
||||
) // 10 min
|
||||
|
||||
return () => {
|
||||
if (!timer) return
|
||||
timer = clearInterval(timer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,14 @@ describe("proxy", () => {
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("should handle default port", () => {
|
||||
// https://github.com/RSSNext/Follow/issues/1197
|
||||
const proxy = "http://example.com:80"
|
||||
const result = setProxyConfig(proxy)
|
||||
expect(store.set).toHaveBeenCalledWith("proxy", "http://example.com")
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("should return false for invalid proxy", () => {
|
||||
const proxy = "invalid-proxy"
|
||||
const result = setProxyConfig(proxy)
|
||||
|
||||
@@ -43,12 +43,12 @@ const normalizeProxyUri = (userProxy: string) => {
|
||||
|
||||
try {
|
||||
const proxyUrl = new URL(firstInput)
|
||||
if (!URL_SCHEME.has(proxyUrl.protocol) || !proxyUrl.hostname || !proxyUrl.port) {
|
||||
if (!URL_SCHEME.has(proxyUrl.protocol) || !proxyUrl.hostname) {
|
||||
return
|
||||
}
|
||||
// There are multiple ways to specify a proxy in Electron,
|
||||
// but for security reasons, we only support simple proxy URLs for now.
|
||||
return `${proxyUrl.protocol}//${proxyUrl.hostname}:${proxyUrl.port}`
|
||||
return `${proxyUrl.protocol}//${proxyUrl.hostname}${proxyUrl.port ? `:${proxyUrl.port}` : ""}`
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ const createOrGetDb = () => {
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
export enum StoreKey {
|
||||
CacheSizeLimit = "cacheSizeLimit",
|
||||
}
|
||||
|
||||
export const store = {
|
||||
get: (key: string) => {
|
||||
const db = createOrGetDb()
|
||||
@@ -26,4 +31,9 @@ export const store = {
|
||||
db.data[key] = value
|
||||
db.write()
|
||||
},
|
||||
delete: (key: string) => {
|
||||
const db = createOrGetDb()
|
||||
delete db.data[key]
|
||||
db.write()
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { name } from "@pkg"
|
||||
import { app, Menu, nativeImage, Tray } from "electron"
|
||||
|
||||
import { isMacOS } from "~/env"
|
||||
import { getTrayIconPath } from "~/helper"
|
||||
|
||||
import { getMainWindowOrCreate } from "../window"
|
||||
import { t } from "./i18n"
|
||||
import { store } from "./store"
|
||||
|
||||
// https://www.electronjs.org/docs/latest/tutorial/tray
|
||||
|
||||
let tray: Tray | null = null
|
||||
|
||||
export const registerAppTray = () => {
|
||||
if (!getTrayConfig()) return
|
||||
if (tray) {
|
||||
destroyAppTray()
|
||||
}
|
||||
|
||||
const icon = nativeImage.createFromPath(getTrayIconPath())
|
||||
// See https://stackoverflow.com/questions/41664208/electron-tray-icon-change-depending-on-dark-theme/41998326#41998326
|
||||
const trayIcon = icon.resize({ width: 16 })
|
||||
trayIcon.setTemplateImage(true)
|
||||
tray = new Tray(trayIcon)
|
||||
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: t("menu.open", { name }),
|
||||
click: showWindow,
|
||||
},
|
||||
{ label: t("menu.quit", { name }), click: () => app.quit() },
|
||||
])
|
||||
tray.setContextMenu(contextMenu)
|
||||
tray.setToolTip(app.getName())
|
||||
tray.on("click", showWindow)
|
||||
}
|
||||
|
||||
const showWindow = () => {
|
||||
const mainWindow = getMainWindowOrCreate()
|
||||
if (!mainWindow) return
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore()
|
||||
} else {
|
||||
mainWindow.show()
|
||||
}
|
||||
}
|
||||
|
||||
const destroyAppTray = () => {
|
||||
if (tray) {
|
||||
tray.destroy()
|
||||
tray = null
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_MINIMIZE_TO_TRAY = isMacOS ? false : true
|
||||
|
||||
export const getTrayConfig = (): boolean => store.get("minimizeToTray") ?? DEFAULT_MINIMIZE_TO_TRAY
|
||||
|
||||
export const setTrayConfig = (input: boolean) => {
|
||||
store.set("minimizeToTray", input)
|
||||
if (input) {
|
||||
registerAppTray()
|
||||
} else {
|
||||
destroyAppTray()
|
||||
}
|
||||
}
|
||||
+18
-2
@@ -1,3 +1,4 @@
|
||||
import { callWindowExpose } from "@follow/shared/bridge"
|
||||
import { dispatchEventOnWindow } from "@follow/shared/event"
|
||||
import { name } from "@pkg"
|
||||
import type { BrowserWindow, MenuItem, MenuItemConstructorOptions } from "electron"
|
||||
@@ -58,7 +59,8 @@ export const registerAppMenu = () => {
|
||||
const mainWindow = getMainWindow()
|
||||
if (!mainWindow) return
|
||||
mainWindow.show()
|
||||
dispatchEventOnWindow(mainWindow, "QuickAdd")
|
||||
const caller = callWindowExpose(mainWindow)
|
||||
caller.quickAdd()
|
||||
},
|
||||
},
|
||||
|
||||
@@ -70,7 +72,9 @@ export const registerAppMenu = () => {
|
||||
const mainWindow = getMainWindow()
|
||||
if (!mainWindow) return
|
||||
mainWindow.show()
|
||||
dispatchEventOnWindow(mainWindow, "Discover")
|
||||
|
||||
const caller = callWindowExpose(mainWindow)
|
||||
caller.goToDiscover()
|
||||
},
|
||||
},
|
||||
|
||||
@@ -130,6 +134,18 @@ export const registerAppMenu = () => {
|
||||
{ role: "zoomIn", label: t("menu.zoomIn") },
|
||||
{ role: "zoomOut", label: t("menu.zoomOut") },
|
||||
{ type: "separator" },
|
||||
{
|
||||
type: "normal",
|
||||
label: t("menu.zenMode"),
|
||||
accelerator: "Ctrl+Shift+Z",
|
||||
click: () => {
|
||||
const mainWindow = getMainWindow()
|
||||
if (!mainWindow) return
|
||||
|
||||
const caller = callWindowExpose(mainWindow)
|
||||
caller.zenMode()
|
||||
},
|
||||
},
|
||||
{ role: "togglefullscreen", label: t("menu.toggleFullScreen") },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -8,7 +8,10 @@ import type { BrowserWindow } from "electron"
|
||||
import { app, clipboard, dialog, screen } from "electron"
|
||||
|
||||
import { registerMenuAndContextMenu } from "~/init"
|
||||
import { clearAllData } from "~/lib/cleaner"
|
||||
import { clearAllData, getCacheSize } from "~/lib/cleaner"
|
||||
import { store, StoreKey } from "~/lib/store"
|
||||
import { registerAppTray } from "~/lib/tray"
|
||||
import { logger } from "~/logger"
|
||||
|
||||
import { isWindows11 } from "../env"
|
||||
import { downloadFile } from "../lib/download"
|
||||
@@ -222,6 +225,7 @@ export const appRoute = {
|
||||
switchAppLocale: t.procedure.input<string>().action(async ({ input }) => {
|
||||
i18n.changeLanguage(input)
|
||||
registerMenuAndContextMenu()
|
||||
registerAppTray()
|
||||
|
||||
app.commandLine.appendSwitch("lang", input)
|
||||
}),
|
||||
@@ -267,6 +271,27 @@ ${content}
|
||||
return { success: false, error: errorMessage }
|
||||
}
|
||||
}),
|
||||
|
||||
getCacheSize: t.procedure.action(async () => {
|
||||
return getCacheSize()
|
||||
}),
|
||||
getCacheLimit: t.procedure.action(async () => {
|
||||
return store.get(StoreKey.CacheSizeLimit)
|
||||
}),
|
||||
|
||||
clearCache: t.procedure.action(async () => {
|
||||
const cachePath = path.join(app.getPath("userData"), "cache")
|
||||
await fsp.rm(cachePath, { recursive: true, force: true })
|
||||
}),
|
||||
|
||||
limitCacheSize: t.procedure.input<number>().action(async ({ input }) => {
|
||||
logger.info("set limitCacheSize", input)
|
||||
if (input === 0) {
|
||||
store.delete(StoreKey.CacheSizeLimit)
|
||||
} else {
|
||||
store.set(StoreKey.CacheSizeLimit, input)
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
interface Sender extends Electron.WebContents {
|
||||
|
||||
@@ -4,10 +4,6 @@ import { setDockCount } from "../lib/dock"
|
||||
import { sleep } from "../lib/utils"
|
||||
import { t } from "./_instance"
|
||||
|
||||
const timerMap = {
|
||||
unread: undefined as any,
|
||||
}
|
||||
|
||||
const pollingMap = {
|
||||
unread: false,
|
||||
}
|
||||
@@ -27,8 +23,8 @@ async function updateUnreadCount() {
|
||||
}
|
||||
|
||||
export async function pollingUpdateUnreadCount() {
|
||||
if (timerMap.unread) {
|
||||
timerMap.unread = clearTimeout(timerMap.unread)
|
||||
if (pollingMap.unread) {
|
||||
return
|
||||
}
|
||||
|
||||
pollingMap.unread = true
|
||||
@@ -42,5 +38,4 @@ export async function pollingUpdateUnreadCount() {
|
||||
|
||||
export async function cancelPollingUpdateUnreadCount() {
|
||||
pollingMap.unread = false
|
||||
timerMap.unread = clearTimeout(timerMap.unread)
|
||||
}
|
||||
|
||||
+33
-41
@@ -1,57 +1,49 @@
|
||||
import type { ActionContext } from "@egoist/tipc/main"
|
||||
import type { MenuItemConstructorOptions, MessageBoxOptions } from "electron"
|
||||
import { dialog, Menu, ShareMenu } from "electron"
|
||||
|
||||
import { t } from "./_instance"
|
||||
|
||||
type MenuItem = ActionMenuItem | { type: "separator" }
|
||||
export interface ActionMenuItem {
|
||||
type: "text"
|
||||
label: string
|
||||
enabled?: boolean
|
||||
|
||||
shortcut?: string
|
||||
icon?: string
|
||||
submenu?: MenuItem[]
|
||||
checked?: boolean
|
||||
type SerializableMenuItem = Omit<MenuItemConstructorOptions, "click" | "submenu"> & {
|
||||
// id: string
|
||||
submenu?: SerializableMenuItem[]
|
||||
}
|
||||
|
||||
function normalizeMenuItems(
|
||||
items: SerializableMenuItem[],
|
||||
context: ActionContext,
|
||||
path = [] as number[],
|
||||
): MenuItemConstructorOptions[] {
|
||||
return items.map((item, index) => {
|
||||
const curPath = [...path, index]
|
||||
return {
|
||||
...item,
|
||||
click() {
|
||||
context.sender.send("menu-click", {
|
||||
id: item.id,
|
||||
path: curPath,
|
||||
})
|
||||
},
|
||||
submenu: item.submenu ? normalizeMenuItems(item.submenu, context, curPath) : undefined,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const menuRoute = {
|
||||
showContextMenu: t.procedure
|
||||
.input<{
|
||||
items: Array<MenuItem>
|
||||
items: SerializableMenuItem[]
|
||||
}>()
|
||||
.action(async ({ input, context }) => {
|
||||
const menu = Menu.buildFromTemplate(transformMenuItems(input.items))
|
||||
|
||||
function transformMenuItems(items: MenuItem[], parentIndex?: number) {
|
||||
return items.map((item, index) => {
|
||||
if (item.type === "separator") {
|
||||
return {
|
||||
type: "separator" as const,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
label: item.label,
|
||||
enabled: item.enabled ?? true,
|
||||
accelerator: item.shortcut?.replace("Meta", "CmdOrCtrl"),
|
||||
checked: typeof item.checked === "boolean" ? item.checked : undefined,
|
||||
type: typeof item.checked === "boolean" ? "checkbox" : undefined,
|
||||
click() {
|
||||
context.sender.send(
|
||||
"menu-click",
|
||||
parentIndex !== undefined ? `${parentIndex}-${index}` : `${index}`,
|
||||
)
|
||||
},
|
||||
submenu: item.submenu ? transformMenuItems(item.submenu, index) : undefined,
|
||||
} as MenuItemConstructorOptions
|
||||
})
|
||||
}
|
||||
.action(({ input, context }) => {
|
||||
const defer = Promise.withResolvers<void>()
|
||||
const normalizedMenuItems = normalizeMenuItems(input.items, context)
|
||||
|
||||
// See https://www.electronjs.org/docs/latest/api/menu
|
||||
const menu = Menu.buildFromTemplate(normalizedMenuItems)
|
||||
menu.popup({
|
||||
callback: () => {
|
||||
context.sender.send("menu-closed")
|
||||
},
|
||||
callback: () => defer.resolve(),
|
||||
})
|
||||
return defer.promise
|
||||
}),
|
||||
|
||||
/** @deprecated */
|
||||
|
||||
@@ -2,6 +2,9 @@ import { createRequire } from "node:module"
|
||||
|
||||
import { app, nativeTheme } from "electron"
|
||||
|
||||
import { START_IN_TRAY_ARGS } from "~/constants/app"
|
||||
import { getTrayConfig, setTrayConfig } from "~/lib/tray"
|
||||
|
||||
import { setDockCount } from "../lib/dock"
|
||||
import { setProxyConfig, updateProxy } from "../lib/proxy"
|
||||
import { store } from "../lib/store"
|
||||
@@ -10,12 +13,12 @@ import { t } from "./_instance"
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
export const settingRoute = {
|
||||
getLoginItemSettings: t.procedure
|
||||
.input<void>()
|
||||
.action(async () => await app.getLoginItemSettings()),
|
||||
getLoginItemSettings: t.procedure.input<void>().action(async () => app.getLoginItemSettings()),
|
||||
setLoginItemSettings: t.procedure.input<boolean>().action(async ({ input }) => {
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: input,
|
||||
openAsHidden: true,
|
||||
args: [START_IN_TRAY_ARGS],
|
||||
})
|
||||
}),
|
||||
openSettingWindow: t.procedure.action(async () => createSettingWindow()),
|
||||
@@ -37,6 +40,8 @@ export const settingRoute = {
|
||||
|
||||
store.set("appearance", input)
|
||||
}),
|
||||
getMinimizeToTray: t.procedure.action(async () => getTrayConfig()),
|
||||
setMinimizeToTray: t.procedure.input<boolean>().action(async ({ input }) => setTrayConfig(input)),
|
||||
setDockBadge: t.procedure.input<number>().action(async ({ input }) => {
|
||||
setDockCount(input)
|
||||
}),
|
||||
|
||||
@@ -4,11 +4,13 @@ import { fileURLToPath } from "node:url"
|
||||
import { is } from "@electron-toolkit/utils"
|
||||
import { callWindowExpose } from "@follow/shared/bridge"
|
||||
import type { BrowserWindowConstructorOptions } from "electron"
|
||||
import { BrowserWindow, screen, shell } from "electron"
|
||||
import { app, BrowserWindow, screen, shell } from "electron"
|
||||
|
||||
import { START_IN_TRAY_ARGS } from "./constants/app"
|
||||
import { isDev, isMacOS, isWindows, isWindows11 } from "./env"
|
||||
import { getIconPath } from "./helper"
|
||||
import { store } from "./lib/store"
|
||||
import { getTrayConfig } from "./lib/tray"
|
||||
import { logger } from "./logger"
|
||||
import { cancelPollingUpdateUnreadCount, pollingUpdateUnreadCount } from "./tipc/dock"
|
||||
|
||||
@@ -97,7 +99,9 @@ export function createWindow(
|
||||
})
|
||||
|
||||
window.on("ready-to-show", () => {
|
||||
window?.show()
|
||||
const shouldShowWindow =
|
||||
!app.getLoginItemSettings().wasOpenedAsHidden && !process.argv.includes(START_IN_TRAY_ARGS)
|
||||
if (shouldShowWindow) window.show()
|
||||
})
|
||||
|
||||
window.webContents.setWindowOpenHandler((details) => {
|
||||
@@ -214,7 +218,8 @@ export const createMainWindow = () => {
|
||||
windows.mainWindow = window
|
||||
|
||||
window.on("close", (event) => {
|
||||
if (isMacOS) {
|
||||
const minimizeToTray = getTrayConfig()
|
||||
if (isMacOS || minimizeToTray) {
|
||||
event.preventDefault()
|
||||
if (window.isFullScreen()) {
|
||||
window.once("leave-full-screen", () => {
|
||||
@@ -282,7 +287,7 @@ export const getMainWindow = () => windows.mainWindow
|
||||
|
||||
export const getMainWindowOrCreate = () => {
|
||||
if (!windows.mainWindow) {
|
||||
createMainWindow()
|
||||
return createMainWindow()
|
||||
}
|
||||
return windows.mainWindow
|
||||
}
|
||||
|
||||
@@ -1,94 +1,24 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<!-- FOLLOW VITE BUILD INJECT -->
|
||||
|
||||
<script>
|
||||
<script type="module">
|
||||
const host = "https://localhost:2233"
|
||||
|
||||
const createRefreshRuntimeScript = `
|
||||
import RefreshRuntime from "${host}/@react-refresh";
|
||||
RefreshRuntime.injectIntoGlobalHook(window);
|
||||
window.$RefreshReg$ = () => {};
|
||||
window.$RefreshSig$ = () => (type) => type;
|
||||
window.__vite_plugin_react_preamble_installed__ = true;
|
||||
import RefreshRuntime from "${host}/@react-refresh";
|
||||
RefreshRuntime.injectIntoGlobalHook(window);
|
||||
window.$RefreshReg$ = () => {};
|
||||
window.$RefreshSig$ = () => (type) => type;
|
||||
window.__vite_plugin_react_preamble_installed__ = true;
|
||||
`
|
||||
|
||||
const $script = document.createElement("script")
|
||||
$script.innerHTML = createRefreshRuntimeScript
|
||||
$script.type = "module"
|
||||
document.head.appendChild($script)
|
||||
|
||||
createModuleScript(`${host}/@vite/client`)
|
||||
createModuleScript(`${host}/src/main.tsx`)
|
||||
function createModuleScript(src) {
|
||||
const $script = document.createElement("script")
|
||||
$script.src = src
|
||||
$script.type = "module"
|
||||
document.head.appendChild($script)
|
||||
}
|
||||
|
||||
globalThis["__DEBUG_PROXY__"] = true
|
||||
</script>
|
||||
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
|
||||
/>
|
||||
|
||||
<meta name="theme-color" content="#ff5c00" />
|
||||
<!-- favicon -->
|
||||
<link rel="icon" href="/favicon-dev.ico" type="image/x-icon" />
|
||||
<title>Follow</title>
|
||||
<script>
|
||||
function setTheme() {
|
||||
let e = "follow:color-mode",
|
||||
t = document.documentElement,
|
||||
a = localStorage.getItem(e)
|
||||
function h() {
|
||||
return window.matchMedia
|
||||
? window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? "dark"
|
||||
: window.matchMedia("(prefers-color-scheme: light)").matches
|
||||
? "light"
|
||||
: void 0
|
||||
: void 0
|
||||
}
|
||||
if (!a) {
|
||||
t.dataset.theme = h() || "light"
|
||||
return
|
||||
}
|
||||
switch ((a = JSON.parse(a))) {
|
||||
case "dark":
|
||||
t.dataset.theme = "dark"
|
||||
break
|
||||
case "light":
|
||||
t.dataset.theme = "light"
|
||||
break
|
||||
case "system":
|
||||
t.dataset.theme = h() || "light"
|
||||
}
|
||||
}
|
||||
setTheme()
|
||||
</script>
|
||||
<script>
|
||||
;(function () {
|
||||
var e = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches,
|
||||
t = localStorage.getItem("theme") || '"system"'
|
||||
t && t !== '"system"' && (document.documentElement.dataset.theme = t)
|
||||
t && t === '"system"' && e && (document.documentElement.dataset.theme = "dark")
|
||||
})()
|
||||
</script>
|
||||
<title>Debug Proxy</title>
|
||||
<script type="module" src="./__debug_proxy.ts"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">
|
||||
<!-- Skeleton -->
|
||||
<div class="h-full w-full flex">
|
||||
<div class="w-64 shrink-0 h-full"></div>
|
||||
<div class="grow w-full h-full bg-theme-background"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<body></body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
const host = "https://localhost:2233"
|
||||
|
||||
globalThis["__DEBUG_PROXY__"] = true
|
||||
|
||||
fetch(`${host}`)
|
||||
.then((res) => res.text())
|
||||
.then((html) => {
|
||||
const parser = new DOMParser()
|
||||
const doc = parser.parseFromString(html, "text/html")
|
||||
|
||||
const scripts = doc.querySelectorAll("script")
|
||||
|
||||
scripts.forEach((script) => {
|
||||
script.remove()
|
||||
})
|
||||
|
||||
// header meta
|
||||
|
||||
const $meta = doc.head.querySelectorAll("meta")
|
||||
$meta.forEach((meta) => {
|
||||
document.head.append(meta)
|
||||
})
|
||||
|
||||
const $style = doc.head.querySelectorAll("style")
|
||||
$style.forEach((style) => {
|
||||
document.head.append(style)
|
||||
})
|
||||
|
||||
document.body.innerHTML = doc.body.innerHTML
|
||||
|
||||
scripts.forEach((script) => {
|
||||
const $script = document.createElement("script")
|
||||
$script.type = "module"
|
||||
$script.crossOrigin = script.crossOrigin
|
||||
|
||||
if (script.src) {
|
||||
$script.src = new URL(
|
||||
script.src.startsWith("http") ? new URL(script.src).pathname : script.src,
|
||||
host,
|
||||
).toString()
|
||||
} else if (script.innerHTML) {
|
||||
$script.innerHTML = script.innerHTML
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
document.body.append($script)
|
||||
})
|
||||
})
|
||||
+33
-30
@@ -10,16 +10,17 @@
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dnd-kit/core": "^6.1.0",
|
||||
"@egoist/tipc": "0.3.2",
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@follow/electron-main": "workspace:*",
|
||||
"@follow/shared": "workspace:*",
|
||||
"@fontsource/sn-pro": "5.1.0",
|
||||
"@headlessui/react": "2.1.10",
|
||||
"@hono/auth-js": "1.0.11",
|
||||
"@hookform/resolvers": "3.9.0",
|
||||
"@lottiefiles/dotlottie-react": "0.9.1",
|
||||
"@microflash/remark-callout-directives": "4.3.1",
|
||||
"@headlessui/react": "2.2.0",
|
||||
"@hono/auth-js": "1.0.13",
|
||||
"@hookform/resolvers": "3.9.1",
|
||||
"@lottiefiles/dotlottie-react": "0.9.3",
|
||||
"@microflash/remark-callout-directives": "4.3.2",
|
||||
"@openpanel/web": "1.0.1",
|
||||
"@radix-ui/react-avatar": "1.1.1",
|
||||
"@radix-ui/react-context-menu": "2.2.2",
|
||||
@@ -30,32 +31,33 @@
|
||||
"@radix-ui/react-popover": "1.1.2",
|
||||
"@radix-ui/react-slider": "^1.2.1",
|
||||
"@radix-ui/react-slot": "1.1.0",
|
||||
"@sentry/react": "8.34.0",
|
||||
"@shikijs/transformers": "1.22.0",
|
||||
"@tanstack/query-sync-storage-persister": "5.59.13",
|
||||
"@tanstack/react-query": "5.59.14",
|
||||
"@tanstack/react-query-devtools": "5.59.14",
|
||||
"@tanstack/react-query-persist-client": "5.59.14",
|
||||
"@sentry/react": "8.36.0",
|
||||
"@shikijs/transformers": "1.22.2",
|
||||
"@tanstack/query-sync-storage-persister": "5.59.17",
|
||||
"@tanstack/react-query": "5.59.19",
|
||||
"@tanstack/react-query-devtools": "5.59.19",
|
||||
"@tanstack/react-query-persist-client": "5.59.19",
|
||||
"@use-gesture/react": "10.3.1",
|
||||
"@welldone-software/why-did-you-render": "8.0.3",
|
||||
"@yornaath/batshit": "0.10.1",
|
||||
"camelcase-keys": "9.1.3",
|
||||
"click-to-react-component": "1.1.0",
|
||||
"clsx": "2.1.1",
|
||||
"cmdk": "1.0.0",
|
||||
"cmdk": "1.0.3",
|
||||
"dayjs": "1.11.13",
|
||||
"dexie": "4.0.8",
|
||||
"dexie": "4.0.9",
|
||||
"dexie-export-import": "^4.1.2",
|
||||
"dnum": "^2.14.0",
|
||||
"electron-log": "5.2.0",
|
||||
"firebase": "10.14.1",
|
||||
"foxact": "0.2.39",
|
||||
"framer-motion": "11.11.9",
|
||||
"foxact": "0.2.41",
|
||||
"framer-motion": "11.11.11",
|
||||
"franc-min": "6.2.0",
|
||||
"fuse.js": "7.0.0",
|
||||
"hast-util-to-jsx-runtime": "2.3.2",
|
||||
"hast-util-to-mdast": "^10.1.0",
|
||||
"hast-util-to-text": "4.0.2",
|
||||
"i18next": "^23.16.0",
|
||||
"i18next": "^23.16.4",
|
||||
"i18next-browser-languagedetector": "8.0.0",
|
||||
"idb-keyval": "6.2.1",
|
||||
"immer": "10.1.1",
|
||||
@@ -65,8 +67,8 @@
|
||||
"lodash-es": "4.17.21",
|
||||
"masonic": "4.0.1",
|
||||
"mdast-util-gfm-table": "^2.0.0",
|
||||
"mdast-util-to-markdown": "^2.1.0",
|
||||
"nanoid": "5.0.7",
|
||||
"mdast-util-to-markdown": "^2.1.1",
|
||||
"nanoid": "5.0.8",
|
||||
"ofetch": "1.4.1",
|
||||
"path-to-regexp": "8.2.0",
|
||||
"plain-shiki": "0.0.12",
|
||||
@@ -74,9 +76,9 @@
|
||||
"react-blurhash": "^0.3.0",
|
||||
"react-error-boundary": "4.1.2",
|
||||
"react-fast-marquee": "1.6.5",
|
||||
"react-hook-form": "7.53.0",
|
||||
"react-hotkeys-hook": "4.5.1",
|
||||
"react-i18next": "^15.0.3",
|
||||
"react-hook-form": "7.53.1",
|
||||
"react-hotkeys-hook": "4.6.1",
|
||||
"react-i18next": "^15.1.0",
|
||||
"react-intersection-observer": "9.13.1",
|
||||
"react-resizable-layout": "npm:@innei/react-resizable-layout@0.7.3-fork.1",
|
||||
"react-router-dom": "6.27.0",
|
||||
@@ -92,20 +94,21 @@
|
||||
"remark-gh-alerts": "0.0.3",
|
||||
"remark-parse": "11.0.0",
|
||||
"remark-rehype": "11.1.1",
|
||||
"shiki": "1.22.0",
|
||||
"sonner": "^1.5.0",
|
||||
"shiki": "1.22.2",
|
||||
"sonner": "1.5.0",
|
||||
"swiper": "11.1.14",
|
||||
"tldts": "6.1.51",
|
||||
"tldts": "6.1.58",
|
||||
"unified": "11.0.5",
|
||||
"unist-util-visit-parents": "^6.0.1",
|
||||
"use-context-selector": "2.0.0",
|
||||
"use-sync-external-store": "1.2.2",
|
||||
"usehooks-ts": "3.1.0",
|
||||
"vfile": "6.0.3",
|
||||
"zod": "3.23.8",
|
||||
"zustand": "5.0.0"
|
||||
"zustand": "5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/generator": "7.25.7",
|
||||
"@babel/generator": "7.26.2",
|
||||
"@follow/atoms": "workspace:*",
|
||||
"@follow/components": "workspace:*",
|
||||
"@follow/constants": "workspace:*",
|
||||
@@ -114,14 +117,14 @@
|
||||
"@follow/shared": "workspace:*",
|
||||
"@follow/types": "workspace:*",
|
||||
"@follow/utils": "workspace:*",
|
||||
"@hono/node-server": "1.13.2",
|
||||
"@hono/node-server": "1.13.4",
|
||||
"@types/katex": "0.16.7",
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/node": "^22.7.5",
|
||||
"@types/react": "^18.3.11",
|
||||
"@types/node": "^22.8.7",
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"fake-indexeddb": "6.0.0",
|
||||
"happy-dom": "15.7.4",
|
||||
"happy-dom": "15.8.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { cn, getOS } from "@follow/utils/utils"
|
||||
import { useEffect, useLayoutEffect } from "react"
|
||||
import { useEffect } from "react"
|
||||
import { Outlet } from "react-router-dom"
|
||||
|
||||
import { queryClient } from "~/lib/query-client"
|
||||
@@ -29,22 +29,6 @@ function App() {
|
||||
return cleanup
|
||||
}, [])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
// Electron app register in app scope, but web app should register in window scope
|
||||
if (IN_ELECTRON) return
|
||||
const handleOpenSettings = (e) => {
|
||||
if (e.key === "," && (e.metaKey || e.ctrlKey)) {
|
||||
window.router.showSettings()
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
document.addEventListener("keydown", handleOpenSettings)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleOpenSettings)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const windowsElectron = IN_ELECTRON && getOS() === "Windows"
|
||||
return (
|
||||
<RootProviders>
|
||||
@@ -69,6 +53,8 @@ const AppLayer = () => {
|
||||
const appIsReady = useAppIsReady()
|
||||
|
||||
useEffect(() => {
|
||||
document.querySelector("#app-skeleton")?.remove()
|
||||
|
||||
const doneTime = Math.trunc(performance.now())
|
||||
window.analytics?.capture("ui_render_init", {
|
||||
time: doneTime,
|
||||
@@ -76,8 +62,6 @@ const AppLayer = () => {
|
||||
appLog("App is ready", `${doneTime}ms`)
|
||||
|
||||
applyAfterReadyCallbacks()
|
||||
|
||||
document.querySelector("#app-skeleton")?.remove()
|
||||
}, [appIsReady])
|
||||
|
||||
return appIsReady ? <Outlet /> : <AppSkeleton />
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { getOS } from "@follow/utils/utils"
|
||||
import { atom } from "jotai"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { tipcClient } from "~/lib/client"
|
||||
import { createAtomHooks } from "~/lib/jotai"
|
||||
import type { ElectronMenuItem } from "~/lib/native-menu"
|
||||
import { showElectronContextMenu } from "~/lib/native-menu"
|
||||
|
||||
// Atom
|
||||
|
||||
type ContextMenuState =
|
||||
| { open: false }
|
||||
| {
|
||||
open: true
|
||||
position: { x: number; y: number }
|
||||
menuItems: FollowMenuItem[]
|
||||
// Just for abort callback
|
||||
// Also can be optimized by using the `atomWithListeners`
|
||||
abortController: AbortController
|
||||
}
|
||||
|
||||
export const [contextMenuAtom, useContextMenuState, useContextMenuValue, useSetContextMenu] =
|
||||
createAtomHooks(atom<ContextMenuState>({ open: false }))
|
||||
|
||||
const useShowWebContextMenu = () => {
|
||||
const setContextMenu = useSetContextMenu()
|
||||
|
||||
const showWebContextMenu = useCallback(
|
||||
async (menuItems: Array<FollowMenuItem>, e: MouseEvent | React.MouseEvent) => {
|
||||
const abortController = new AbortController()
|
||||
const resolvers = Promise.withResolvers<void>()
|
||||
setContextMenu({
|
||||
open: true,
|
||||
position: { x: e.clientX, y: e.clientY },
|
||||
menuItems,
|
||||
abortController,
|
||||
})
|
||||
|
||||
abortController.signal.addEventListener("abort", () => {
|
||||
resolvers.resolve()
|
||||
})
|
||||
return resolvers.promise
|
||||
},
|
||||
[setContextMenu],
|
||||
)
|
||||
|
||||
return showWebContextMenu
|
||||
}
|
||||
|
||||
// Menu
|
||||
|
||||
type BaseMenuItemText = {
|
||||
type: "text"
|
||||
label: string
|
||||
click?: () => void
|
||||
/** only work in web app */
|
||||
icon?: React.ReactNode
|
||||
shortcut?: string
|
||||
disabled?: boolean
|
||||
checked?: boolean
|
||||
supportMultipleSelection?: boolean
|
||||
}
|
||||
|
||||
type BaseMenuItemSeparator = {
|
||||
type: "separator"
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
type BaseMenuItem = BaseMenuItemText | BaseMenuItemSeparator
|
||||
|
||||
export type FollowMenuItem = BaseMenuItem & {
|
||||
submenu?: FollowMenuItem[]
|
||||
}
|
||||
|
||||
export type MenuItemInput =
|
||||
| (BaseMenuItemText & { hide?: boolean; submenu?: MenuItemInput[] })
|
||||
| (BaseMenuItemSeparator & { hide?: boolean })
|
||||
| null
|
||||
| undefined
|
||||
| false
|
||||
| ""
|
||||
|
||||
function sortShortcutsString(shortcut: string) {
|
||||
const order = ["Shift", "Ctrl", "Meta", "Alt"]
|
||||
let nextShortcut = shortcut
|
||||
if (getOS() === "Windows") {
|
||||
nextShortcut = shortcut.replace("Meta", "Ctrl").replace("meta", "ctrl")
|
||||
}
|
||||
const arr = nextShortcut.split("+")
|
||||
|
||||
const sortedModifiers = arr
|
||||
.filter((key) => order.includes(key))
|
||||
.sort((a, b) => order.indexOf(a) - order.indexOf(b))
|
||||
|
||||
const otherKeys = arr.filter((key) => !order.includes(key))
|
||||
|
||||
return [...sortedModifiers, ...otherKeys].join("+")
|
||||
}
|
||||
|
||||
function normalizeMenuItems(items: MenuItemInput[]): FollowMenuItem[] {
|
||||
return items
|
||||
.filter((item) => item !== null && item !== undefined && item !== false && item !== "")
|
||||
.filter((item) => !item.hide)
|
||||
.map((item) => {
|
||||
if (item.type === "separator") {
|
||||
return item
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
shortcut: item.shortcut ? sortShortcutsString(item.shortcut) : undefined,
|
||||
submenu: item.submenu ? normalizeMenuItems(item.submenu) : undefined,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// MenuItem must have at least one of label, role or type
|
||||
function transformMenuItemsForNative(nextItems: FollowMenuItem[]): ElectronMenuItem[] {
|
||||
return nextItems.map((item) => {
|
||||
if (item.type === "separator") {
|
||||
return { type: "separator" }
|
||||
}
|
||||
return {
|
||||
type: typeof item.checked === "boolean" ? "checkbox" : undefined,
|
||||
label: item.label,
|
||||
click: item.click,
|
||||
enabled:
|
||||
(!item.disabled && item.click !== undefined) || (!!item.submenu && item.submenu.length > 0),
|
||||
accelerator: item.shortcut?.replace("Meta", "CmdOrCtrl"),
|
||||
checked: typeof item.checked === "boolean" ? item.checked : undefined,
|
||||
submenu: item.submenu ? transformMenuItemsForNative(item.submenu) : undefined,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function withDebugMenu(menuItems: Array<FollowMenuItem>, e: MouseEvent | React.MouseEvent) {
|
||||
if (import.meta.env.DEV && e) {
|
||||
menuItems.push(
|
||||
{
|
||||
type: "separator" as const,
|
||||
},
|
||||
{
|
||||
type: "text" as const,
|
||||
label: "Inspect Element",
|
||||
click: () => {
|
||||
tipcClient?.inspectElement({
|
||||
x: e.pageX,
|
||||
y: e.pageY,
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
return menuItems
|
||||
}
|
||||
|
||||
export const useShowContextMenu = () => {
|
||||
const showWebContextMenu = useShowWebContextMenu()
|
||||
|
||||
const showContextMenu = useCallback(
|
||||
async (inputMenu: Array<MenuItemInput>, e: MouseEvent | React.MouseEvent) => {
|
||||
const menuItems = normalizeMenuItems(inputMenu)
|
||||
// only show native menu on macOS electron, because in other platform, the native ui is not good
|
||||
if (IN_ELECTRON && getOS() === "macOS") {
|
||||
withDebugMenu(menuItems, e)
|
||||
await showElectronContextMenu(transformMenuItemsForNative(menuItems))
|
||||
return
|
||||
}
|
||||
await showWebContextMenu(menuItems, e)
|
||||
},
|
||||
[showWebContextMenu],
|
||||
)
|
||||
|
||||
return showContextMenu
|
||||
}
|
||||
@@ -10,6 +10,7 @@ const createDefaultSettings = (): GeneralSettings => ({
|
||||
// Data control
|
||||
dataPersist: true,
|
||||
sendAnonymousData: true,
|
||||
reduceRefetch: true,
|
||||
|
||||
// view
|
||||
unreadOnly: false,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createSettingAtom } from "@follow/atoms/helper/setting.js"
|
||||
import type { UISettings } from "@follow/shared/interface/settings"
|
||||
import { atom, useAtomValue } from "jotai"
|
||||
|
||||
import { internal_feedColumnShowAtom } from "../sidebar"
|
||||
import { jotaiStore } from "@follow/utils/jotai"
|
||||
import { atom, useAtomValue, useSetAtom } from "jotai"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
export const createDefaultSettings = (): UISettings => ({
|
||||
// Sidebar
|
||||
@@ -42,6 +42,8 @@ export const createDefaultSettings = (): UISettings => ({
|
||||
wideMode: false,
|
||||
})
|
||||
|
||||
const zenModeAtom = atom(false)
|
||||
|
||||
export const {
|
||||
useSettingKey: useUISettingKey,
|
||||
useSettingSelector: useUISettingSelector,
|
||||
@@ -61,9 +63,28 @@ export const uiServerSyncWhiteListKeys: (keyof UISettings)[] = [
|
||||
"customCSS",
|
||||
]
|
||||
|
||||
const isZenModeAtom = atom((get) => {
|
||||
const ui = get(__uiSettingAtom)
|
||||
return ui.wideMode && !get(internal_feedColumnShowAtom)
|
||||
})
|
||||
export const useIsZenMode = () => useAtomValue(zenModeAtom)
|
||||
export const getIsZenMode = () => jotaiStore.get(zenModeAtom)
|
||||
|
||||
export const useIsZenMode = () => useAtomValue(isZenModeAtom)
|
||||
export const useSetZenMode = () => {
|
||||
const setZenMode = useSetAtom(zenModeAtom)
|
||||
return useEventCallback((checked: boolean) => {
|
||||
setZenMode(checked)
|
||||
})
|
||||
}
|
||||
|
||||
export const useToggleZenMode = () => {
|
||||
const setZenMode = useSetZenMode()
|
||||
const isZenMode = useIsZenMode()
|
||||
return useEventCallback(() => {
|
||||
const newIsZenMode = !isZenMode
|
||||
document.documentElement.dataset.zenMode = newIsZenMode.toString()
|
||||
setZenMode(newIsZenMode)
|
||||
})
|
||||
}
|
||||
|
||||
export const useRealInWideMode = () => {
|
||||
const wideMode = useUISettingKey("wideMode")
|
||||
const isZenMode = useIsZenMode()
|
||||
return wideMode || isZenMode
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import { atom } from "jotai"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { createAtomHooks } from "~/lib/jotai"
|
||||
|
||||
import { getIsZenMode, useIsZenMode } from "./settings/ui"
|
||||
|
||||
const defaultFeedView = FeedViewType.Articles
|
||||
const viewAtom = atom<FeedViewType | -1>(-1)
|
||||
const [
|
||||
@@ -48,14 +50,20 @@ viewAtom.onMount = () => {
|
||||
setSidebarActiveView(view)
|
||||
}
|
||||
}
|
||||
export const [
|
||||
internal_feedColumnShowAtom,
|
||||
,
|
||||
useFeedColumnShow,
|
||||
,
|
||||
getFeedColumnShow,
|
||||
setFeedColumnShow,
|
||||
] = createAtomHooks(atom(true))
|
||||
const [, , internal_useFeedColumnShow, , internal_getFeedColumnShow, setFeedColumnShow] =
|
||||
createAtomHooks(atom(true))
|
||||
|
||||
export const useFeedColumnShow = () => {
|
||||
const isZenMode = useIsZenMode()
|
||||
return internal_useFeedColumnShow() && !isZenMode
|
||||
}
|
||||
|
||||
export const getFeedColumnShow = () => {
|
||||
const isZenMode = getIsZenMode()
|
||||
return internal_getFeedColumnShow() && !isZenMode
|
||||
}
|
||||
|
||||
export { setFeedColumnShow }
|
||||
|
||||
export const [, , useFeedColumnTempShow, , getFeedColumnTempShow, setFeedColumnTempShow] =
|
||||
createAtomHooks(atom(false))
|
||||
|
||||
@@ -20,6 +20,10 @@ export function ErrorElement() {
|
||||
: JSON.stringify(error)
|
||||
const stack = error instanceof Error ? error.stack : null
|
||||
|
||||
useEffect(() => {
|
||||
document.querySelector("#app-skeleton")?.remove()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
console.error("Error handled by React Router default ErrorBoundary:", error)
|
||||
|
||||
@@ -78,7 +82,7 @@ export function ErrorElement() {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<FeedbackIssue message={message} stack={stack} />
|
||||
<FeedbackIssue message={message} stack={stack} error={error as Error} />
|
||||
<div className="grow" />
|
||||
|
||||
<PoweredByFooter />
|
||||
@@ -89,15 +93,18 @@ export function ErrorElement() {
|
||||
export const FeedbackIssue = ({
|
||||
message,
|
||||
stack,
|
||||
error,
|
||||
}: {
|
||||
message: string
|
||||
stack: string | null | undefined
|
||||
error?: unknown
|
||||
}) => (
|
||||
<p className="mt-8">
|
||||
Still having this issue? Please give feedback in GitHub, thanks!
|
||||
<a
|
||||
className="ml-2 cursor-pointer text-theme-accent-500 duration-200 hover:text-accent"
|
||||
href={getNewIssueUrl({
|
||||
error: error instanceof Error ? error : undefined,
|
||||
title: `Error: ${message}`,
|
||||
body: ["### Error", "", message, "", "### Stack", "", "```", stack, "```"].join("\n"),
|
||||
label: "bug",
|
||||
|
||||
@@ -9,9 +9,10 @@ import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
import { entries } from "~/queries/entries"
|
||||
|
||||
import { CustomSafeError } from "../../errors/CustomSafeError"
|
||||
import type { AppErrorFallbackProps } from "../common/AppErrorBoundary"
|
||||
import { useModalStack } from "../ui/modal/stacked/hooks"
|
||||
import { CustomSafeError, useResetErrorWhenRouteChange } from "./helper"
|
||||
import { useResetErrorWhenRouteChange } from "./helper"
|
||||
import { FeedPreview } from "./previews/FeedPreview"
|
||||
|
||||
const FeedFoundCanBeFollowErrorFallback: FC<AppErrorFallbackProps> = ({ resetError, error }) => {
|
||||
|
||||
@@ -3,8 +3,9 @@ import { Button } from "@follow/components/ui/button/index.js"
|
||||
import type { FC } from "react"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
|
||||
import { CustomSafeError } from "../../errors/CustomSafeError"
|
||||
import type { AppErrorFallbackProps } from "../common/AppErrorBoundary"
|
||||
import { CustomSafeError, useResetErrorWhenRouteChange } from "./helper"
|
||||
import { useResetErrorWhenRouteChange } from "./helper"
|
||||
|
||||
const FeedNotFoundErrorFallback: FC<AppErrorFallbackProps> = ({ resetError, error }) => {
|
||||
if (!(error instanceof FeedNotFound)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ const ModalErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<FeedbackIssue message={message!} stack={stack} />
|
||||
<FeedbackIssue message={message!} stack={stack} error={props.error} />
|
||||
</div>
|
||||
</m.div>
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ const PageErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<FeedbackIssue message={message!} stack={stack} />
|
||||
<FeedbackIssue message={message!} stack={stack} error={props.error} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ const RSSHubErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
</pre>
|
||||
) : null}
|
||||
|
||||
<FeedbackIssue message={message!} stack={stack} />
|
||||
<FeedbackIssue message={message!} stack={stack} error={props.error} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { nextFrame } from "@follow/utils/dom"
|
||||
import type { FC } from "react"
|
||||
import { createElement, useEffect, useRef } from "react"
|
||||
import { useLocation } from "react-router-dom"
|
||||
|
||||
import { createErrorToaster } from "~/lib/error-parser"
|
||||
|
||||
import type { AppErrorFallbackProps } from "../common/AppErrorBoundary"
|
||||
|
||||
export const parseError = (error: unknown): { message?: string; stack?: string } => {
|
||||
@@ -21,16 +18,6 @@ export const parseError = (error: unknown): { message?: string; stack?: string }
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move this
|
||||
export class CustomSafeError extends Error {
|
||||
constructor(message: string, toast?: boolean) {
|
||||
super(message)
|
||||
if (toast) {
|
||||
nextFrame(() => createErrorToaster(message)(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const useResetErrorWhenRouteChange = (resetError: () => void) => {
|
||||
const location = useLocation()
|
||||
const currentPathnameRef = useRef(location.pathname)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Input } from "@follow/components/ui/input/index.js"
|
||||
import { useCorrectZIndex } from "@follow/components/ui/z-index/ctx.js"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from "@headlessui/react"
|
||||
@@ -6,8 +7,6 @@ import { AnimatePresence, m } from "framer-motion"
|
||||
import Fuse from "fuse.js"
|
||||
import { forwardRef, Fragment, useCallback, useEffect, useState } from "react"
|
||||
|
||||
import { useCorrectZIndex } from "../modal/stacked/hooks"
|
||||
|
||||
export type Suggestion = {
|
||||
name: string
|
||||
value: string
|
||||
@@ -87,7 +86,7 @@ export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
||||
{...inputProps}
|
||||
/>
|
||||
<AnimatePresence>
|
||||
{open && (
|
||||
{open && filterableSuggestions.length > 0 && (
|
||||
<ComboboxOptions
|
||||
portal
|
||||
static
|
||||
|
||||
@@ -45,6 +45,7 @@ const ContextMenuSubContent = React.forwardRef<
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"min-w-32 overflow-hidden rounded-md border bg-theme-modal-background-opaque p-1 text-theme-foreground/90 shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:shadow-zinc-800/60",
|
||||
"z-[61]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -14,7 +14,7 @@ export function LottieRenderContainer() {
|
||||
|
||||
return (
|
||||
<RootPortal>
|
||||
<div className="pointer-events-none fixed z-[999]" data-testid="lottie-render-container">
|
||||
<div className="pointer-events-none fixed z-[9999]" data-testid="lottie-render-container">
|
||||
{elements.map((element) => element)}
|
||||
</div>
|
||||
</RootPortal>
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
} from "react"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { useRealInWideMode } from "~/atoms/settings/ui"
|
||||
import {
|
||||
useGetWrappedElementPosition,
|
||||
useWrappedElementPosition,
|
||||
@@ -58,7 +58,7 @@ export const Toc: Component<TocProps> = ({ className, onItemClick }) => {
|
||||
|
||||
const renderContentElementPosition = useWrappedElementPosition()
|
||||
const renderContentElementSize = useWrappedElementSize()
|
||||
const entryContentInWideMode = useUISettingKey("wideMode")
|
||||
const entryContentInWideMode = useRealInWideMode()
|
||||
const shouldShowTitle = useViewport((v) => {
|
||||
if (!entryContentInWideMode) return false
|
||||
const { w } = v
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
TooltipPortal,
|
||||
TooltipTrigger,
|
||||
} from "@follow/components/ui/tooltip/index.jsx"
|
||||
import { useCorrectZIndex } from "@follow/components/ui/z-index/ctx.js"
|
||||
import { useContext } from "react"
|
||||
|
||||
import type { LinkProps } from "../../link"
|
||||
@@ -17,6 +18,7 @@ export const MarkdownLink = (props: LinkProps) => {
|
||||
const populatedFullHref = transformUrl(props.href)
|
||||
|
||||
const parseTimeStamp = isAudio(populatedFullHref)
|
||||
const zIndex = useCorrectZIndex(0)
|
||||
if (parseTimeStamp) {
|
||||
const childrenText = props.children
|
||||
|
||||
@@ -30,6 +32,7 @@ export const MarkdownLink = (props: LinkProps) => {
|
||||
<Tooltip delayDuration={0}>
|
||||
<TooltipTrigger asChild>
|
||||
<a
|
||||
draggable="false"
|
||||
className="follow-link--underline font-semibold text-foreground no-underline"
|
||||
href={populatedFullHref}
|
||||
title={props.title}
|
||||
@@ -45,7 +48,7 @@ export const MarkdownLink = (props: LinkProps) => {
|
||||
</TooltipTrigger>
|
||||
{!!props.href && (
|
||||
<TooltipPortal>
|
||||
<TooltipContent align="start" className="break-all" side="bottom">
|
||||
<TooltipContent align="start" className="break-all" style={{ zIndex }} side="bottom">
|
||||
{populatedFullHref}
|
||||
</TooltipContent>
|
||||
</TooltipPortal>
|
||||
|
||||
@@ -179,7 +179,7 @@ const MediaImpl: FC<MediaProps> = ({
|
||||
onError={errorHandle}
|
||||
className={cn(
|
||||
"size-full object-contain",
|
||||
// "bg-gray-200 dark:bg-neutral-800",
|
||||
inline && "size-auto",
|
||||
popper && "cursor-zoom-in",
|
||||
"duration-200",
|
||||
mediaLoadState === "loaded" ? "opacity-100" : "opacity-0",
|
||||
@@ -226,6 +226,7 @@ const MediaImpl: FC<MediaProps> = ({
|
||||
src,
|
||||
thumbnail,
|
||||
type,
|
||||
inline,
|
||||
])
|
||||
|
||||
if (!type || !src) return null
|
||||
@@ -268,7 +269,7 @@ const MediaImpl: FC<MediaProps> = ({
|
||||
return (
|
||||
<span
|
||||
data-state={type !== "video" ? mediaLoadState : undefined}
|
||||
className={cn("relative block overflow-hidden rounded", className)}
|
||||
className={cn("relative overflow-hidden rounded", inline ? "inline" : "block", className)}
|
||||
style={style}
|
||||
>
|
||||
{!!props.width && !!props.height && !!containerWidth ? (
|
||||
|
||||
@@ -344,6 +344,7 @@ const VolumeControl = () => {
|
||||
return (
|
||||
<ActionIcon
|
||||
label={<VolumeSlider onVolumeChange={controls.volume} volume={volume} />}
|
||||
enableHoverableContent
|
||||
onClick={() => {
|
||||
if (muted) {
|
||||
controls.unmute()
|
||||
@@ -377,7 +378,7 @@ const PlayProgressBar = () => {
|
||||
})
|
||||
return (
|
||||
<Slider.Root
|
||||
className="relative z-[1] flex size-full items-center transition-all duration-200 ease-in-out"
|
||||
className="swiper-no-swiping relative z-[1] flex size-full items-center transition-all duration-200 ease-in-out"
|
||||
min={0}
|
||||
max={state.duration}
|
||||
step={0.01}
|
||||
@@ -420,12 +421,14 @@ const ActionIcon = ({
|
||||
children,
|
||||
shortcut,
|
||||
label,
|
||||
enableHoverableContent,
|
||||
}: {
|
||||
className?: string
|
||||
onClick?: () => void
|
||||
label: React.ReactNode
|
||||
children?: React.ReactNode
|
||||
shortcut?: string
|
||||
enableHoverableContent?: boolean
|
||||
}) => {
|
||||
return (
|
||||
<ActionButton
|
||||
@@ -435,6 +438,7 @@ const ActionIcon = ({
|
||||
onClick={onClick}
|
||||
tooltip={label}
|
||||
shortcut={shortcut}
|
||||
enableHoverableContent={enableHoverableContent}
|
||||
>
|
||||
{children || <i className={className} />}
|
||||
</ActionButton>
|
||||
|
||||
@@ -6,7 +6,7 @@ export const VolumeSlider: FC<{
|
||||
onVolumeChange: (volume: number) => void
|
||||
}> = ({ onVolumeChange, volume }) => (
|
||||
<Slider.Root
|
||||
className="relative flex h-16 w-1 flex-col items-center overflow-hidden rounded p-1"
|
||||
className="relative flex h-16 w-1 flex-col items-center rounded p-1"
|
||||
max={1}
|
||||
step={0.01}
|
||||
orientation="vertical"
|
||||
@@ -18,6 +18,9 @@ export const VolumeSlider: FC<{
|
||||
<Slider.Track className="relative w-1 grow rounded bg-zinc-500">
|
||||
<Slider.Range className="absolute w-full rounded bg-black dark:bg-white" />
|
||||
</Slider.Track>
|
||||
<Slider.Thumb className="block rounded bg-black dark:bg-white" aria-label="Volume" />
|
||||
<Slider.Thumb
|
||||
className="block size-3 rounded-full bg-black dark:bg-white"
|
||||
aria-label="Volume"
|
||||
/>
|
||||
</Slider.Root>
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ export const FixedModalCloseButton: Component<{
|
||||
<TooltipTrigger
|
||||
type="button"
|
||||
className={cn(
|
||||
"center flex size-8 rounded-full bg-background p-1 shadow-sm ring-1 ring-zinc-200 dark:ring-neutral-800",
|
||||
"no-drag-region center flex size-8 rounded-full bg-background p-1 shadow-sm ring-1 ring-zinc-200 dark:ring-neutral-800",
|
||||
className,
|
||||
)}
|
||||
onClick={onClick}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { DragControls } from "framer-motion"
|
||||
import { useAtomValue } from "jotai"
|
||||
import { selectAtom } from "jotai/utils"
|
||||
import type { ResizeCallback, ResizeStartCallback } from "re-resizable"
|
||||
import { useCallback, useContext, useId, useMemo, useRef, useState } from "react"
|
||||
import { useCallback, useContext, useId, useRef, useState } from "react"
|
||||
import { flushSync } from "react-dom"
|
||||
import { useContextSelector } from "use-context-selector"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
@@ -12,7 +10,6 @@ import { jotaiStore } from "~/lib/jotai"
|
||||
|
||||
import { modalStackAtom } from "./atom"
|
||||
import { ModalEventBus } from "./bus"
|
||||
import { MODAL_STACK_Z_INDEX } from "./constants"
|
||||
import { CurrentModalContext, CurrentModalStateContext } from "./context"
|
||||
import type { ModalProps, ModalStackOptions } from "./types"
|
||||
|
||||
@@ -161,17 +158,3 @@ export const useResizeableModal = (
|
||||
}
|
||||
|
||||
export const useIsTopModal = () => useContextSelector(CurrentModalStateContext, (v) => v.isTop)
|
||||
|
||||
export const useCorrectZIndex = (fallbackZIndex = 0) => {
|
||||
const inModal = useCurrentModal()
|
||||
|
||||
return useAtomValue(
|
||||
useMemo(
|
||||
() =>
|
||||
selectAtom(modalStackAtom, (v) =>
|
||||
inModal ? v.length + MODAL_STACK_Z_INDEX + inModal.getIndex() + 1 : fallbackZIndex,
|
||||
),
|
||||
[fallbackZIndex, inModal],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Divider } from "@follow/components/ui/divider/index.js"
|
||||
import { RootPortalProvider } from "@follow/components/ui/portal/provider.js"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
|
||||
import { ZIndexProvider } from "@follow/components/ui/z-index/index.js"
|
||||
import { useRefValue } from "@follow/hooks"
|
||||
import { nextFrame, preventDefault, stopPropagation } from "@follow/utils/dom"
|
||||
import { cn, getOS } from "@follow/utils/utils"
|
||||
import * as Dialog from "@radix-ui/react-dialog"
|
||||
import type { BoundingBox } from "framer-motion"
|
||||
import { produce } from "immer"
|
||||
import { useSetAtom } from "jotai"
|
||||
import { useAtomValue, useSetAtom } from "jotai"
|
||||
import { selectAtom } from "jotai/utils"
|
||||
import { Resizable } from "re-resizable"
|
||||
import type { FC, PropsWithChildren, SyntheticEvent } from "react"
|
||||
import {
|
||||
@@ -405,6 +407,14 @@ const ModalContext: FC<
|
||||
isTop: boolean
|
||||
}
|
||||
> = ({ modalContextProps, isTop, children }) => {
|
||||
const { getIndex } = modalContextProps
|
||||
const zIndex = useAtomValue(
|
||||
useMemo(
|
||||
() => selectAtom(modalStackAtom, (v) => v.length + MODAL_STACK_Z_INDEX + getIndex() + 1),
|
||||
[getIndex],
|
||||
),
|
||||
)
|
||||
|
||||
return (
|
||||
<CurrentModalContext.Provider value={modalContextProps}>
|
||||
<CurrentModalStateContext.Provider
|
||||
@@ -415,7 +425,7 @@ const ModalContext: FC<
|
||||
[isTop],
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
<ZIndexProvider zIndex={zIndex}>{children}</ZIndexProvider>
|
||||
</CurrentModalStateContext.Provider>
|
||||
</CurrentModalContext.Provider>
|
||||
)
|
||||
|
||||
@@ -4,7 +4,15 @@ import type { FC, PropsWithChildren } from "react"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { modalStackAtom } from "./atom"
|
||||
import { useModalStack } from "./hooks"
|
||||
import { ModalInternal } from "./modal"
|
||||
import type { ModalProps } from "./types"
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
presentModal: (modal: ModalProps) => void
|
||||
}
|
||||
}
|
||||
|
||||
export const ModalStackProvider: FC<PropsWithChildren> = ({ children }) => (
|
||||
<>
|
||||
@@ -14,6 +22,9 @@ export const ModalStackProvider: FC<PropsWithChildren> = ({ children }) => (
|
||||
)
|
||||
|
||||
const ModalStack = () => {
|
||||
const { present } = useModalStack()
|
||||
window.presentModal = present
|
||||
|
||||
const stack = useAtomValue(modalStackAtom)
|
||||
|
||||
const topModalIndex = stack.findLastIndex((item) => item.modal)
|
||||
|
||||
@@ -32,6 +32,10 @@ export const shortcuts: Shortcuts = {
|
||||
name: "keys.layout.toggleWideMode",
|
||||
key: "Meta+[",
|
||||
},
|
||||
zenMode: {
|
||||
name: "keys.layout.zenMode",
|
||||
key: "Control+Shift+Z",
|
||||
},
|
||||
},
|
||||
entries: {
|
||||
refetch: {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { afterEach } from "node:test"
|
||||
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { browserDB } from "./db"
|
||||
|
||||
describe("upgradeToV8", () => {
|
||||
afterEach(async () => {
|
||||
await browserDB.delete()
|
||||
})
|
||||
|
||||
it("should set tipUsers to an empty array if tipUsers is not an array", async () => {
|
||||
const insertFeeds = [
|
||||
{ id: 1, tipUsers: {} },
|
||||
{ id: 2, tipUsers: null },
|
||||
{ id: 3, tipUsers: [{ name: "user1" }] },
|
||||
]
|
||||
// @ts-expect-error
|
||||
await browserDB.feeds.bulkAdd(insertFeeds)
|
||||
|
||||
const feeds = await browserDB.feeds.toArray()
|
||||
expect(feeds.length).toEqual(3)
|
||||
expect(feeds[0].tipUsers).toEqual(insertFeeds[0].tipUsers)
|
||||
expect(feeds[1].tipUsers).toEqual(insertFeeds[1].tipUsers)
|
||||
expect(feeds[2].tipUsers).toEqual(insertFeeds[2].tipUsers)
|
||||
|
||||
await browserDB.transaction("rw", [browserDB.feeds], async (tx) => {
|
||||
await browserDB.upgradeToV8(tx)
|
||||
})
|
||||
const feedsAfterMigrate = await browserDB.feeds.toArray()
|
||||
expect(feedsAfterMigrate.length).toEqual(3)
|
||||
expect(feedsAfterMigrate[0].tipUsers).toEqual([])
|
||||
expect(feedsAfterMigrate[1].tipUsers).toEqual(null)
|
||||
expect(feedsAfterMigrate[2].tipUsers).toEqual([{ name: "user1" }])
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,5 @@
|
||||
import "dexie-export-import"
|
||||
|
||||
import type { Transaction } from "dexie"
|
||||
import Dexie from "dexie"
|
||||
|
||||
@@ -10,6 +12,7 @@ import {
|
||||
dbSchemaV5,
|
||||
dbSchemaV6,
|
||||
dbSchemaV7,
|
||||
dbSchemaV8,
|
||||
} from "./db_schema"
|
||||
import type { DB_Cleaner } from "./schemas/cleaner"
|
||||
import type { DB_Entry, DB_EntryRelated } from "./schemas/entry"
|
||||
@@ -49,6 +52,7 @@ class BrowserDB extends Dexie {
|
||||
this.version(5).stores(dbSchemaV5)
|
||||
this.version(6).stores(dbSchemaV6)
|
||||
this.version(7).stores(dbSchemaV7)
|
||||
this.version(8).stores(dbSchemaV8).upgrade(this.upgradeToV8)
|
||||
|
||||
this.entries = this.table("entries")
|
||||
this.feeds = this.table("feeds")
|
||||
@@ -64,10 +68,28 @@ class BrowserDB extends Dexie {
|
||||
const session = trans.table("feedUnreads")
|
||||
session.delete("feedId")
|
||||
}
|
||||
|
||||
async upgradeToV8(trans: Transaction) {
|
||||
// Fix https://github.com/RSSNext/Follow/issues/1308
|
||||
const session = trans.table("feeds")
|
||||
return session.toCollection().modify((feed) => {
|
||||
if (!feed.tipUsers || Array.isArray(feed.tipUsers)) return
|
||||
feed.tipUsers = []
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const browserDB = new BrowserDB()
|
||||
|
||||
export const exportDB = async () => {
|
||||
const blob = await browserDB.export({ prettyJson: true })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement("a")
|
||||
a.href = url
|
||||
a.download = `${LOCAL_DB_NAME}.json`
|
||||
a.click()
|
||||
}
|
||||
|
||||
// ================================================ //
|
||||
// ================================================ //
|
||||
// ================================================ //
|
||||
|
||||
@@ -38,3 +38,5 @@ export const dbSchemaV7 = {
|
||||
...dbSchemaV6,
|
||||
inboxes: "&id",
|
||||
}
|
||||
|
||||
export const dbSchemaV8 = dbSchemaV7
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { nextFrame } from "@follow/utils/dom"
|
||||
|
||||
import { createErrorToaster } from "~/lib/error-parser"
|
||||
|
||||
export class CustomSafeError extends Error {
|
||||
constructor(message: string, toast?: boolean) {
|
||||
super(message)
|
||||
if (toast) {
|
||||
nextFrame(() => createErrorToaster(message)(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,20 @@
|
||||
import {
|
||||
SimpleIconsEagle,
|
||||
SimpleIconsInstapaper,
|
||||
SimpleIconsObsidian,
|
||||
SimpleIconsOmnivore,
|
||||
SimpleIconsOutline,
|
||||
SimpleIconsReadwise,
|
||||
} from "@follow/components/ui/platform-icon/icons.js"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import type { CombinedEntryModel } from "@follow/models/types"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { nextFrame } from "@follow/utils/dom"
|
||||
import { getOS } from "@follow/utils/utils"
|
||||
import { useMutation, useQuery } from "@tanstack/react-query"
|
||||
import type { FetchError } from "ofetch"
|
||||
import { ofetch } from "ofetch"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import type { ReactNode } from "react"
|
||||
import { useCallback, useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import {
|
||||
getReadabilityContent,
|
||||
getReadabilityStatus,
|
||||
ReadabilityStatus,
|
||||
setReadabilityContent,
|
||||
setReadabilityStatus,
|
||||
} from "~/atoms/readability"
|
||||
import { useIntegrationSettingValue } from "~/atoms/settings/integration"
|
||||
import {
|
||||
setShowSourceContent,
|
||||
toggleShowSourceContent,
|
||||
@@ -37,7 +25,6 @@ import { whoami } from "~/atoms/user"
|
||||
import { mountLottie } from "~/components/ui/lottie-container"
|
||||
import { shortcuts } from "~/constants/shortcuts"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import StarAnimationUri from "~/lottie/star.lottie?url"
|
||||
import { useTipModal } from "~/modules/wallet/hooks"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
@@ -45,6 +32,7 @@ import { entryActions } from "~/store/entry"
|
||||
import { getFeedById, useFeedById } from "~/store/feed"
|
||||
import { useInboxById } from "~/store/inbox"
|
||||
|
||||
import { useIntegrationActions } from "./useIntegrationActions"
|
||||
import { navigateEntry } from "./useNavigateEntry"
|
||||
|
||||
const absoluteStarAnimationUri = new URL(StarAnimationUri, import.meta.url).href
|
||||
@@ -170,7 +158,7 @@ export const useEntryActions = ({
|
||||
id: feed.id,
|
||||
}
|
||||
})
|
||||
|
||||
const integrationActions = useIntegrationActions({ entry, view })
|
||||
const inbox = useInboxById(entry?.inboxId)
|
||||
const isInbox = !!inbox
|
||||
|
||||
@@ -198,81 +186,11 @@ export const useEntryActions = ({
|
||||
const uncollect = useUnCollect(populatedEntry)
|
||||
const read = useRead()
|
||||
const unread = useUnread()
|
||||
|
||||
const {
|
||||
enableEagle,
|
||||
enableReadwise,
|
||||
enableInstapaper,
|
||||
enableOmnivore,
|
||||
enableObsidian,
|
||||
enableOutline,
|
||||
readwiseToken,
|
||||
instapaperUsername,
|
||||
instapaperPassword,
|
||||
omnivoreToken,
|
||||
omnivoreEndpoint,
|
||||
obsidianVaultPath,
|
||||
outlineToken,
|
||||
outlineEndpoint,
|
||||
outlineCollection,
|
||||
} = useIntegrationSettingValue()
|
||||
const isObsidianEnabled = enableObsidian && !!obsidianVaultPath
|
||||
|
||||
const saveToObsidian = useMutation({
|
||||
mutationKey: ["save-to-obsidian"],
|
||||
mutationFn: async (data: {
|
||||
url: string
|
||||
title: string
|
||||
content: string
|
||||
author: string
|
||||
publishedAt: string
|
||||
vaultPath: string
|
||||
}) => {
|
||||
return await tipcClient?.saveToObsidian(data)
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (data?.success) {
|
||||
toast.success(t("entry_actions.saved_to_obsidian"), {
|
||||
duration: 3000,
|
||||
})
|
||||
} else {
|
||||
toast.error(`${t("entry_actions.failed_to_save_to_obsidian")}: ${data?.error}`, {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const checkEagle = useQuery({
|
||||
queryKey: ["check-eagle"],
|
||||
enabled: ELECTRON && enableEagle && !!entry?.entries.url && view !== undefined,
|
||||
queryFn: async () => {
|
||||
try {
|
||||
await ofetch("http://localhost:41595")
|
||||
return true
|
||||
} catch (error: unknown) {
|
||||
return (error as FetchError).data?.code === 401
|
||||
}
|
||||
},
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
})
|
||||
|
||||
const deleteInboxEntry = useDeleteInboxEntry()
|
||||
|
||||
const items = useMemo(() => {
|
||||
if (!populatedEntry || view === undefined) return []
|
||||
|
||||
const getEntryContentAsMarkdown = () => {
|
||||
const isReadabilityReady =
|
||||
getReadabilityStatus()[populatedEntry.entries.id] === ReadabilityStatus.SUCCESS
|
||||
const content =
|
||||
(isReadabilityReady
|
||||
? getReadabilityContent()[populatedEntry.entries.id].content
|
||||
: populatedEntry.entries.content) || ""
|
||||
return parseHtml(content).toMarkdown()
|
||||
}
|
||||
|
||||
const items: {
|
||||
key: string
|
||||
className?: string
|
||||
@@ -284,265 +202,7 @@ export const useEntryActions = ({
|
||||
disabled?: boolean
|
||||
onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void
|
||||
}[] = [
|
||||
{
|
||||
name: t("entry_actions.save_media_to_eagle"),
|
||||
icon: <SimpleIconsEagle />,
|
||||
key: "saveToEagle",
|
||||
hide:
|
||||
!enableEagle ||
|
||||
(checkEagle.isLoading ? true : !checkEagle.data) ||
|
||||
!populatedEntry.entries.media?.length,
|
||||
onClick: async () => {
|
||||
if (!populatedEntry.entries.url || !populatedEntry.entries.media?.length) {
|
||||
return
|
||||
}
|
||||
window.analytics?.capture("integration", {
|
||||
type: "eagle",
|
||||
event: "save",
|
||||
})
|
||||
const response = await tipcClient?.saveToEagle({
|
||||
url: populatedEntry.entries.url,
|
||||
mediaUrls: populatedEntry.entries.media.map((m) => m.url),
|
||||
})
|
||||
|
||||
if (response?.status === "success") {
|
||||
toast.success(t("entry_actions.saved_to_eagle"), {
|
||||
duration: 3000,
|
||||
})
|
||||
} else {
|
||||
toast.error(t("entry_actions.failed_to_save_to_eagle"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_readwise"),
|
||||
icon: <SimpleIconsReadwise />,
|
||||
key: "saveToReadwise",
|
||||
hide: !enableReadwise || !readwiseToken || !populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
try {
|
||||
window.analytics?.capture("integration", {
|
||||
type: "readwise",
|
||||
event: "save",
|
||||
})
|
||||
const data = await ofetch("https://readwise.io/api/v3/save/", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Token ${readwiseToken}`,
|
||||
},
|
||||
body: {
|
||||
url: populatedEntry.entries.url,
|
||||
html: populatedEntry.entries.content || undefined,
|
||||
title: populatedEntry.entries.title || undefined,
|
||||
author: populatedEntry.entries.author || undefined,
|
||||
summary: populatedEntry.entries.description || undefined,
|
||||
published_date: populatedEntry.entries.publishedAt || undefined,
|
||||
image_url: populatedEntry.entries.media?.[0]?.url || undefined,
|
||||
saved_using: "Follow",
|
||||
},
|
||||
})
|
||||
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_readwise")},{" "}
|
||||
<a target="_blank" className="underline" href={data.url}>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_readwise"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_instapaper"),
|
||||
icon: <SimpleIconsInstapaper />,
|
||||
key: "saveToInstapaper",
|
||||
hide:
|
||||
!enableInstapaper ||
|
||||
!instapaperPassword ||
|
||||
!instapaperUsername ||
|
||||
!populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
try {
|
||||
window.analytics?.capture("integration", {
|
||||
type: "instapaper",
|
||||
event: "save",
|
||||
})
|
||||
const data = await ofetch("https://www.instapaper.com/api/add", {
|
||||
query: {
|
||||
url: populatedEntry.entries.url,
|
||||
title: populatedEntry.entries.title,
|
||||
},
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(`${instapaperUsername}:${instapaperPassword}`)}`,
|
||||
},
|
||||
parseResponse: JSON.parse,
|
||||
})
|
||||
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_instapaper")},{" "}
|
||||
<a
|
||||
target="_blank"
|
||||
className="underline"
|
||||
href={`https://www.instapaper.com/read/${data.bookmark_id}`}
|
||||
>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_instapaper"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_omnivore"),
|
||||
icon: <SimpleIconsOmnivore />,
|
||||
key: "saveToomnivore",
|
||||
hide: !enableOmnivore || !omnivoreToken || !omnivoreEndpoint || !populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
const saveUrlQuery = `
|
||||
mutation SaveUrl($input: SaveUrlInput!) {
|
||||
saveUrl(input: $input) {
|
||||
... on SaveSuccess {
|
||||
url
|
||||
clientRequestId
|
||||
}
|
||||
... on SaveError {
|
||||
errorCodes
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
window.analytics?.capture("integration", {
|
||||
type: "omnivore",
|
||||
event: "save",
|
||||
})
|
||||
try {
|
||||
const data = await ofetch(omnivoreEndpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: omnivoreToken,
|
||||
},
|
||||
body: {
|
||||
query: saveUrlQuery,
|
||||
variables: {
|
||||
input: {
|
||||
url: populatedEntry.entries.url,
|
||||
source: "Follow",
|
||||
clientRequestId: globalThis.crypto.randomUUID(),
|
||||
publishedAt: new Date(populatedEntry.entries.publishedAt),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_omnivore")},{" "}
|
||||
<a target="_blank" className="underline" href={data.data.saveUrl.url}>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_omnivore"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_obsidian"),
|
||||
icon: <SimpleIconsObsidian />,
|
||||
key: "saveToObsidian",
|
||||
hide: !isObsidianEnabled || !populatedEntry?.entries?.url || !IN_ELECTRON,
|
||||
onClick: () => {
|
||||
if (!isObsidianEnabled || !populatedEntry?.entries?.url || !IN_ELECTRON) return
|
||||
|
||||
const markdownContent = getEntryContentAsMarkdown()
|
||||
window.analytics?.capture("integration", {
|
||||
type: "obsidian",
|
||||
event: "save",
|
||||
})
|
||||
saveToObsidian.mutate({
|
||||
url: populatedEntry.entries.url,
|
||||
title: populatedEntry.entries.title || "",
|
||||
content: markdownContent,
|
||||
author: populatedEntry.entries.author || "",
|
||||
publishedAt: populatedEntry.entries.publishedAt || "",
|
||||
vaultPath: obsidianVaultPath,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_outline"),
|
||||
icon: <SimpleIconsOutline />,
|
||||
key: "saveTooutline",
|
||||
hide:
|
||||
!IN_ELECTRON ||
|
||||
!enableOutline ||
|
||||
!outlineToken ||
|
||||
!outlineEndpoint ||
|
||||
!outlineCollection ||
|
||||
!populatedEntry.entries.title,
|
||||
onClick: async () => {
|
||||
try {
|
||||
const request = async (method: string, params: Record<string, unknown>) => {
|
||||
return await ofetch(`${outlineEndpoint.replace(/\/$/, "")}/${method}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${outlineToken}`,
|
||||
},
|
||||
body: params,
|
||||
})
|
||||
}
|
||||
let collectionId = outlineCollection
|
||||
if (!/^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i.test(collectionId)) {
|
||||
const collection = await request("collections.info", {
|
||||
id: collectionId,
|
||||
})
|
||||
collectionId = collection.data.id
|
||||
}
|
||||
const markdownContent = getEntryContentAsMarkdown()
|
||||
await request("documents.create", {
|
||||
title: populatedEntry.entries.title,
|
||||
text: markdownContent,
|
||||
collectionId,
|
||||
publish: true,
|
||||
})
|
||||
toast.success(t("entry_actions.saved_to_outline"), {
|
||||
duration: 3000,
|
||||
})
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_outline"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
...integrationActions.items,
|
||||
{
|
||||
key: "tip",
|
||||
shortcut: shortcuts.entry.tip.key,
|
||||
@@ -707,30 +367,13 @@ export const useEntryActions = ({
|
||||
}, [
|
||||
populatedEntry,
|
||||
view,
|
||||
integrationActions.items,
|
||||
t,
|
||||
enableEagle,
|
||||
checkEagle.isLoading,
|
||||
checkEagle.data,
|
||||
enableReadwise,
|
||||
readwiseToken,
|
||||
enableInstapaper,
|
||||
instapaperPassword,
|
||||
instapaperUsername,
|
||||
enableOmnivore,
|
||||
omnivoreToken,
|
||||
omnivoreEndpoint,
|
||||
isObsidianEnabled,
|
||||
enableOutline,
|
||||
outlineToken,
|
||||
outlineEndpoint,
|
||||
outlineCollection,
|
||||
isInbox,
|
||||
feed?.ownerUserId,
|
||||
type,
|
||||
showSourceContent,
|
||||
inList,
|
||||
saveToObsidian,
|
||||
obsidianVaultPath,
|
||||
openTipModal,
|
||||
collect,
|
||||
uncollect,
|
||||
|
||||
@@ -7,9 +7,9 @@ import { isBizId } from "@follow/utils/utils"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import type { FollowMenuItem, MenuItemInput } from "~/atoms/context-menu"
|
||||
import { whoami } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import type { NativeMenuItem, NullableNativeMenuItem } from "~/lib/native-menu"
|
||||
import { useBoostModal } from "~/modules/boost/hooks"
|
||||
import { useFeedClaimModal } from "~/modules/claim"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
@@ -21,9 +21,10 @@ import {
|
||||
useAddFeedToFeedList,
|
||||
useFeedById,
|
||||
useRemoveFeedFromFeedList,
|
||||
useResetFeed,
|
||||
} from "~/store/feed"
|
||||
import { useInboxById } from "~/store/inbox"
|
||||
import { useListById, useOwnedList } from "~/store/list"
|
||||
import { useListById, useOwnedListByView } from "~/store/list"
|
||||
import { subscriptionActions, useSubscriptionByFeedId } from "~/store/subscription"
|
||||
|
||||
import { useNavigateEntry } from "./useNavigateEntry"
|
||||
@@ -65,6 +66,8 @@ export const useFeedActions = ({
|
||||
type: feed.type,
|
||||
ownerUserId: feed.ownerUserId,
|
||||
id: feed.id,
|
||||
url: feed.url,
|
||||
siteUrl: feed.siteUrl,
|
||||
}
|
||||
})
|
||||
const inbox = useInboxById(feedId)
|
||||
@@ -81,9 +84,10 @@ export const useFeedActions = ({
|
||||
|
||||
const { mutateAsync: addFeedToListMutation } = useAddFeedToFeedList()
|
||||
const { mutateAsync: removeFeedFromListMutation } = useRemoveFeedFromFeedList()
|
||||
const { mutateAsync: resetFeed } = useResetFeed()
|
||||
const openBoostModal = useBoostModal()
|
||||
|
||||
const listByView = useOwnedList(view!)
|
||||
const listByView = useOwnedListByView(view!)
|
||||
|
||||
const isMultipleSelection = feedIds && feedIds.length > 0
|
||||
|
||||
@@ -91,7 +95,9 @@ export const useFeedActions = ({
|
||||
const related = feed || inbox
|
||||
if (!related) return []
|
||||
|
||||
const items: NullableNativeMenuItem[] = [
|
||||
const isFeedOwner = related.ownerUserId === whoami()?.id
|
||||
|
||||
const items: MenuItemInput[] = [
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.mark_all_as_read"),
|
||||
@@ -115,12 +121,19 @@ export const useFeedActions = ({
|
||||
claimFeed()
|
||||
},
|
||||
},
|
||||
...(related.ownerUserId === whoami()?.id
|
||||
...(isFeedOwner
|
||||
? [
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.feed_owned_by_you"),
|
||||
},
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.reset_feed"),
|
||||
click: () => {
|
||||
resetFeed(feedId)
|
||||
},
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
@@ -273,10 +286,10 @@ export const useFeedActions = ({
|
||||
disabled: isEntryList,
|
||||
shortcut: "Meta+C",
|
||||
click: () => {
|
||||
// @ts-expect-error
|
||||
const { url } = feed || {}
|
||||
if (!url) return
|
||||
navigator.clipboard.writeText(url)
|
||||
const { url, siteUrl } = feed || {}
|
||||
const copied = url || siteUrl
|
||||
if (!copied) return
|
||||
navigator.clipboard.writeText(copied)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -328,7 +341,7 @@ export const useListActions = ({ listId, view }: { listId: string; view: FeedVie
|
||||
const items = useMemo(() => {
|
||||
if (!list) return []
|
||||
|
||||
const items: NullableNativeMenuItem[] = [
|
||||
const items: MenuItemInput[] = [
|
||||
list.ownerUserId === whoami()?.id && {
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.list_owned_by_you"),
|
||||
@@ -416,7 +429,7 @@ export const useInboxActions = ({ inboxId }: { inboxId: string }) => {
|
||||
const items = useMemo(() => {
|
||||
if (!inbox) return []
|
||||
|
||||
const items: NativeMenuItem[] = [
|
||||
const items: FollowMenuItem[] = [
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.edit"),
|
||||
|
||||
@@ -4,9 +4,9 @@ import { useCallback } from "react"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { CustomSafeError } from "~/components/errors/helper"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { MAX_TRIAL_USER_FEED_SUBSCRIPTION } from "~/constants/limit"
|
||||
import { CustomSafeError } from "~/errors/CustomSafeError"
|
||||
import { useActivationModal } from "~/modules/activation"
|
||||
import type { FeedFormDataValuesType } from "~/modules/discover/feed-form"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
import {
|
||||
SimpleIconsEagle,
|
||||
SimpleIconsInstapaper,
|
||||
SimpleIconsObsidian,
|
||||
SimpleIconsOmnivore,
|
||||
SimpleIconsOutline,
|
||||
SimpleIconsReadwise,
|
||||
} from "@follow/components/ui/platform-icon/icons.js"
|
||||
import type { CombinedEntryModel } from "@follow/models/types"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { useMutation, useQuery } from "@tanstack/react-query"
|
||||
import type { FetchError } from "ofetch"
|
||||
import { ofetch } from "ofetch"
|
||||
import type { ReactNode } from "react"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { getReadabilityContent, getReadabilityStatus, ReadabilityStatus } from "~/atoms/readability"
|
||||
import { useIntegrationSettingValue } from "~/atoms/settings/integration"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
import { getFeedById, useFeedById } from "~/store/feed"
|
||||
import { useInboxById } from "~/store/inbox"
|
||||
|
||||
export const useIntegrationActions = ({
|
||||
view,
|
||||
entry,
|
||||
}: {
|
||||
view?: number
|
||||
entry?: FlatEntryModel | null
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const feed = useFeedById(entry?.feedId, (feed) => {
|
||||
return {
|
||||
type: feed.type,
|
||||
ownerUserId: feed.ownerUserId,
|
||||
id: feed.id,
|
||||
}
|
||||
})
|
||||
|
||||
const inbox = useInboxById(entry?.inboxId)
|
||||
|
||||
const populatedEntry = useMemo(() => {
|
||||
if (!entry) return null
|
||||
if (!feed?.id && !inbox?.id) return null
|
||||
|
||||
return {
|
||||
...entry,
|
||||
feeds: feed ? getFeedById(feed.id) : undefined,
|
||||
inboxes: inbox,
|
||||
} as CombinedEntryModel
|
||||
}, [entry, feed, inbox])
|
||||
|
||||
const {
|
||||
enableEagle,
|
||||
enableReadwise,
|
||||
enableInstapaper,
|
||||
enableOmnivore,
|
||||
enableObsidian,
|
||||
enableOutline,
|
||||
readwiseToken,
|
||||
instapaperUsername,
|
||||
instapaperPassword,
|
||||
omnivoreToken,
|
||||
omnivoreEndpoint,
|
||||
obsidianVaultPath,
|
||||
outlineToken,
|
||||
outlineEndpoint,
|
||||
outlineCollection,
|
||||
} = useIntegrationSettingValue()
|
||||
const isObsidianEnabled = enableObsidian && !!obsidianVaultPath
|
||||
|
||||
const saveToObsidian = useMutation({
|
||||
mutationKey: ["save-to-obsidian"],
|
||||
mutationFn: async (data: {
|
||||
url: string
|
||||
title: string
|
||||
content: string
|
||||
author: string
|
||||
publishedAt: string
|
||||
vaultPath: string
|
||||
}) => {
|
||||
return await tipcClient?.saveToObsidian(data)
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
if (data?.success) {
|
||||
toast.success(t("entry_actions.saved_to_obsidian"), {
|
||||
duration: 3000,
|
||||
})
|
||||
} else {
|
||||
toast.error(`${t("entry_actions.failed_to_save_to_obsidian")}: ${data?.error}`, {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const checkEagle = useQuery({
|
||||
queryKey: ["check-eagle"],
|
||||
enabled: ELECTRON && enableEagle && !!entry?.entries.url && view !== undefined,
|
||||
queryFn: async () => {
|
||||
try {
|
||||
await ofetch("http://localhost:41595")
|
||||
return true
|
||||
} catch (error: unknown) {
|
||||
return (error as FetchError).data?.code === 401
|
||||
}
|
||||
},
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
})
|
||||
|
||||
const items = useMemo(() => {
|
||||
if (!populatedEntry || view === undefined) return []
|
||||
|
||||
const getEntryContentAsMarkdown = () => {
|
||||
const isReadabilityReady =
|
||||
getReadabilityStatus()[populatedEntry.entries.id] === ReadabilityStatus.SUCCESS
|
||||
const content =
|
||||
(isReadabilityReady
|
||||
? getReadabilityContent()[populatedEntry.entries.id].content
|
||||
: populatedEntry.entries.content) || ""
|
||||
return parseHtml(content).toMarkdown()
|
||||
}
|
||||
|
||||
const items: {
|
||||
key: string
|
||||
className?: string
|
||||
shortcut?: string
|
||||
name: string
|
||||
icon?: ReactNode
|
||||
hide?: boolean
|
||||
active?: boolean
|
||||
disabled?: boolean
|
||||
onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void
|
||||
}[] = [
|
||||
{
|
||||
name: t("entry_actions.save_media_to_eagle"),
|
||||
icon: <SimpleIconsEagle />,
|
||||
key: "saveToEagle",
|
||||
hide:
|
||||
!enableEagle ||
|
||||
(checkEagle.isLoading ? true : !checkEagle.data) ||
|
||||
!populatedEntry.entries.media?.length,
|
||||
onClick: async () => {
|
||||
if (!populatedEntry.entries.url || !populatedEntry.entries.media?.length) {
|
||||
return
|
||||
}
|
||||
window.analytics?.capture("integration", {
|
||||
type: "eagle",
|
||||
event: "save",
|
||||
})
|
||||
const response = await tipcClient?.saveToEagle({
|
||||
url: populatedEntry.entries.url,
|
||||
mediaUrls: populatedEntry.entries.media.map((m) => m.url),
|
||||
})
|
||||
|
||||
if (response?.status === "success") {
|
||||
toast.success(t("entry_actions.saved_to_eagle"), {
|
||||
duration: 3000,
|
||||
})
|
||||
} else {
|
||||
toast.error(t("entry_actions.failed_to_save_to_eagle"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_readwise"),
|
||||
icon: <SimpleIconsReadwise />,
|
||||
key: "saveToReadwise",
|
||||
hide: !enableReadwise || !readwiseToken || !populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
try {
|
||||
window.analytics?.capture("integration", {
|
||||
type: "readwise",
|
||||
event: "save",
|
||||
})
|
||||
const data = await ofetch("https://readwise.io/api/v3/save/", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Token ${readwiseToken}`,
|
||||
},
|
||||
body: {
|
||||
url: populatedEntry.entries.url,
|
||||
html: populatedEntry.entries.content || undefined,
|
||||
title: populatedEntry.entries.title || undefined,
|
||||
author: populatedEntry.entries.author || undefined,
|
||||
summary: populatedEntry.entries.description || undefined,
|
||||
published_date: populatedEntry.entries.publishedAt || undefined,
|
||||
image_url: populatedEntry.entries.media?.[0]?.url || undefined,
|
||||
saved_using: "Follow",
|
||||
},
|
||||
})
|
||||
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_readwise")},{" "}
|
||||
<a target="_blank" className="underline" href={data.url}>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_readwise"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_instapaper"),
|
||||
icon: <SimpleIconsInstapaper />,
|
||||
key: "saveToInstapaper",
|
||||
hide:
|
||||
!enableInstapaper ||
|
||||
!instapaperPassword ||
|
||||
!instapaperUsername ||
|
||||
!populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
try {
|
||||
window.analytics?.capture("integration", {
|
||||
type: "instapaper",
|
||||
event: "save",
|
||||
})
|
||||
const data = await ofetch("https://www.instapaper.com/api/add", {
|
||||
query: {
|
||||
url: populatedEntry.entries.url,
|
||||
title: populatedEntry.entries.title,
|
||||
},
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Basic ${btoa(`${instapaperUsername}:${instapaperPassword}`)}`,
|
||||
},
|
||||
parseResponse: JSON.parse,
|
||||
})
|
||||
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_instapaper")},{" "}
|
||||
<a
|
||||
target="_blank"
|
||||
className="underline"
|
||||
href={`https://www.instapaper.com/read/${data.bookmark_id}`}
|
||||
>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_instapaper"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_omnivore"),
|
||||
icon: <SimpleIconsOmnivore />,
|
||||
key: "saveToomnivore",
|
||||
hide: !enableOmnivore || !omnivoreToken || !omnivoreEndpoint || !populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
const saveUrlQuery = `
|
||||
mutation SaveUrl($input: SaveUrlInput!) {
|
||||
saveUrl(input: $input) {
|
||||
... on SaveSuccess {
|
||||
url
|
||||
clientRequestId
|
||||
}
|
||||
... on SaveError {
|
||||
errorCodes
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
window.analytics?.capture("integration", {
|
||||
type: "omnivore",
|
||||
event: "save",
|
||||
})
|
||||
try {
|
||||
const data = await ofetch(omnivoreEndpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: omnivoreToken,
|
||||
},
|
||||
body: {
|
||||
query: saveUrlQuery,
|
||||
variables: {
|
||||
input: {
|
||||
url: populatedEntry.entries.url,
|
||||
source: "Follow",
|
||||
clientRequestId: globalThis.crypto.randomUUID(),
|
||||
publishedAt: new Date(populatedEntry.entries.publishedAt),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_omnivore")},{" "}
|
||||
<a target="_blank" className="underline" href={data.data.saveUrl.url}>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_omnivore"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_obsidian"),
|
||||
icon: <SimpleIconsObsidian />,
|
||||
key: "saveToObsidian",
|
||||
hide: !isObsidianEnabled || !populatedEntry?.entries?.url || !IN_ELECTRON,
|
||||
onClick: () => {
|
||||
if (!isObsidianEnabled || !populatedEntry?.entries?.url || !IN_ELECTRON) return
|
||||
|
||||
const markdownContent = getEntryContentAsMarkdown()
|
||||
window.analytics?.capture("integration", {
|
||||
type: "obsidian",
|
||||
event: "save",
|
||||
})
|
||||
saveToObsidian.mutate({
|
||||
url: populatedEntry.entries.url,
|
||||
title: populatedEntry.entries.title || "",
|
||||
content: markdownContent,
|
||||
author: populatedEntry.entries.author || "",
|
||||
publishedAt: populatedEntry.entries.publishedAt || "",
|
||||
vaultPath: obsidianVaultPath,
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_outline"),
|
||||
icon: <SimpleIconsOutline />,
|
||||
key: "saveToOutline",
|
||||
hide:
|
||||
!IN_ELECTRON ||
|
||||
!enableOutline ||
|
||||
!outlineToken ||
|
||||
!outlineEndpoint ||
|
||||
!outlineCollection ||
|
||||
!populatedEntry.entries.title,
|
||||
onClick: async () => {
|
||||
try {
|
||||
const request = async (method: string, params: Record<string, unknown>) => {
|
||||
return await ofetch(`${outlineEndpoint.replace(/\/$/, "")}/${method}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${outlineToken}`,
|
||||
},
|
||||
body: params,
|
||||
})
|
||||
}
|
||||
let collectionId = outlineCollection
|
||||
if (!/^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/i.test(collectionId)) {
|
||||
const collection = await request("collections.info", {
|
||||
id: collectionId,
|
||||
})
|
||||
collectionId = collection.data.id
|
||||
}
|
||||
const markdownContent = getEntryContentAsMarkdown()
|
||||
await request("documents.create", {
|
||||
title: populatedEntry.entries.title,
|
||||
text: markdownContent,
|
||||
collectionId,
|
||||
publish: true,
|
||||
})
|
||||
toast.success(t("entry_actions.saved_to_outline"), {
|
||||
duration: 3000,
|
||||
})
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_outline"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
return items
|
||||
}, [
|
||||
populatedEntry,
|
||||
view,
|
||||
t,
|
||||
enableEagle,
|
||||
checkEagle.isLoading,
|
||||
checkEagle.data,
|
||||
enableReadwise,
|
||||
readwiseToken,
|
||||
enableInstapaper,
|
||||
instapaperPassword,
|
||||
instapaperUsername,
|
||||
enableOmnivore,
|
||||
omnivoreToken,
|
||||
omnivoreEndpoint,
|
||||
isObsidianEnabled,
|
||||
enableOutline,
|
||||
outlineToken,
|
||||
outlineEndpoint,
|
||||
outlineCollection,
|
||||
saveToObsidian,
|
||||
obsidianVaultPath,
|
||||
])
|
||||
|
||||
return {
|
||||
items,
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,14 @@ export const useDeleteSubscription = ({ onSuccess }: { onSuccess?: () => void })
|
||||
feedIdList?: string[]
|
||||
}) => {
|
||||
if (feedIdList) {
|
||||
await subscriptionActions.unfollowMany(feedIdList)
|
||||
await subscriptionActions.unfollow(feedIdList)
|
||||
toast.success(t("notify.unfollow_feed_many"))
|
||||
return
|
||||
}
|
||||
|
||||
if (!subscription) return
|
||||
|
||||
subscriptionActions.unfollow(subscription.feedId).then((feed) => {
|
||||
subscriptionActions.unfollow([subscription.feedId]).then(([feed]) => {
|
||||
subscriptionQuery.byView(subscription.view).invalidate()
|
||||
feedUnreadActions.updateByFeedId(subscription.feedId, 0)
|
||||
|
||||
@@ -106,3 +106,23 @@ const UnfollowInfo = ({ title, undo }: { title: string; undo: () => any }) => {
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export const useBatchUpdateSubscription = () => {
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
feedIdList,
|
||||
category,
|
||||
view,
|
||||
}: {
|
||||
feedIdList: string[]
|
||||
category: string
|
||||
view: number
|
||||
}) => {
|
||||
await subscriptionActions.batchUpdateSubscription({
|
||||
category,
|
||||
feedIdList,
|
||||
view,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { atom, useAtomValue, useSetAtom } from "jotai"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { tipcClient } from "~/lib/client"
|
||||
|
||||
const minimizeToTrayAtom = atom<boolean>(false)
|
||||
|
||||
minimizeToTrayAtom.onMount = (setAtom) => {
|
||||
tipcClient?.getMinimizeToTray().then((proxy: boolean) => {
|
||||
setAtom(proxy)
|
||||
})
|
||||
}
|
||||
|
||||
export const useMinimizeToTrayValue = () => useAtomValue(minimizeToTrayAtom)
|
||||
|
||||
export const useSetMinimizeToTray = () => {
|
||||
const setMinimizeToTray = useSetAtom(minimizeToTrayAtom)
|
||||
return useCallback(
|
||||
(value: boolean) => {
|
||||
if (!IN_ELECTRON) return
|
||||
setMinimizeToTray(value)
|
||||
tipcClient?.setMinimizeToTray(value)
|
||||
},
|
||||
[setMinimizeToTray],
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { callWindowExposeRenderer } from "@follow/shared/bridge"
|
||||
|
||||
interface ShortcutDefinition {
|
||||
accelerator: string
|
||||
action: () => void
|
||||
}
|
||||
|
||||
const parseAccelerator = (
|
||||
accelerator: string,
|
||||
): { key: string; ctrl?: boolean; meta?: boolean; shift?: boolean } => {
|
||||
const parts = accelerator.toLowerCase().split("+")
|
||||
return {
|
||||
key: parts.at(-1) ?? "",
|
||||
ctrl: parts.includes("ctrl") || parts.includes("cmdorctrl"),
|
||||
meta: parts.includes("cmd") || parts.includes("cmdorctrl"),
|
||||
shift: parts.includes("shift"),
|
||||
}
|
||||
}
|
||||
|
||||
export const registerAppGlobalShortcuts = () => {
|
||||
// @see apps/main/menu.ts
|
||||
const shortcuts: ShortcutDefinition[] = [
|
||||
{
|
||||
accelerator: "CmdOrCtrl+,",
|
||||
action: () => window.router.showSettings(),
|
||||
},
|
||||
{
|
||||
accelerator: "Ctrl+Shift+Z",
|
||||
action: () => {
|
||||
const caller = callWindowExposeRenderer()
|
||||
caller.zenMode()
|
||||
},
|
||||
},
|
||||
{
|
||||
accelerator: "CmdOrCtrl+T",
|
||||
action: () => {
|
||||
const caller = callWindowExposeRenderer()
|
||||
caller.goToDiscover()
|
||||
},
|
||||
},
|
||||
{
|
||||
accelerator: "CmdOrCtrl+N",
|
||||
action: () => {
|
||||
const caller = callWindowExposeRenderer()
|
||||
caller.quickAdd()
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const handleKeydown = (e: KeyboardEvent) => {
|
||||
// Prevent on input, textarea, [contenteditable]
|
||||
if (
|
||||
["INPUT", "TEXTAREA"].includes((e.target as HTMLElement)?.tagName) ||
|
||||
(e.target as HTMLElement)?.contentEditable === "true"
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
shortcuts.forEach(({ accelerator, action }) => {
|
||||
const { key, ctrl, meta, shift } = parseAccelerator(accelerator)
|
||||
|
||||
const matchesKey = e.key.toLowerCase() === key.toLowerCase()
|
||||
const matchesModifier = ctrl
|
||||
? e.ctrlKey || e.metaKey
|
||||
: !ctrl && !e.ctrlKey && !meta && !e.metaKey
|
||||
const matchesShift = shift ? e.shiftKey : !e.shiftKey
|
||||
|
||||
if (matchesKey && matchesModifier && matchesShift) {
|
||||
action()
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", handleKeydown, true)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeydown, true)
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,17 @@ declare global {
|
||||
__app_is_upgraded__: boolean
|
||||
}
|
||||
}
|
||||
export const doMigration = () => {
|
||||
const lastVersion = localStorage.getItem(appVersionKey)
|
||||
|
||||
if (lastVersion && lastVersion !== APP_VERSION) {
|
||||
appLog(`Upgrade from ${lastVersion} to ${APP_VERSION}`)
|
||||
window.__app_is_upgraded__ = true
|
||||
|
||||
// NOTE: Add migration logic here
|
||||
}
|
||||
export const doMigration = async () => {
|
||||
const lastVersion = localStorage.getItem(appVersionKey) || APP_VERSION
|
||||
localStorage.setItem(appVersionKey, APP_VERSION)
|
||||
|
||||
if (lastVersion === APP_VERSION) return
|
||||
|
||||
// NOTE: Add migration logic here
|
||||
|
||||
if (!APP_VERSION.includes("nightly")) {
|
||||
window.__app_is_upgraded__ = true
|
||||
}
|
||||
appLog(`Upgrade from ${lastVersion} to ${APP_VERSION}`)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { env } from "@follow/shared/env"
|
||||
import type { BrowserOptions } from "@sentry/react"
|
||||
import { FetchError } from "ofetch"
|
||||
|
||||
import { CustomSafeError } from "./components/errors/helper"
|
||||
import { CustomSafeError } from "../errors/CustomSafeError"
|
||||
|
||||
const ERROR_PATTERNS = [
|
||||
/Network Error/i,
|
||||
@@ -49,6 +49,14 @@ export const SentryConfig: BrowserOptions = {
|
||||
if (isPassthroughError || isAbortError) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (error instanceof Error && "traceId" in error && error.traceId) {
|
||||
event.tags = {
|
||||
...event.tags,
|
||||
traceId: error.traceId as string,
|
||||
}
|
||||
}
|
||||
|
||||
return event
|
||||
},
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { env } from "@follow/shared/env"
|
||||
import { appSessionTraceId } from "@follow/utils/environment"
|
||||
import { version } from "@pkg"
|
||||
import { nanoid } from "nanoid"
|
||||
import { useEffect } from "react"
|
||||
import {
|
||||
createRoutesFromChildren,
|
||||
@@ -10,8 +12,16 @@ import {
|
||||
|
||||
import { whoami } from "~/atoms/user"
|
||||
|
||||
import { SentryConfig } from "../configs"
|
||||
import { SentryConfig } from "./sentry.config"
|
||||
|
||||
Object.defineProperty(window.Error.prototype, "traceId", {
|
||||
get() {
|
||||
if (!this._traceId) {
|
||||
this._traceId = nanoid()
|
||||
}
|
||||
return this._traceId
|
||||
},
|
||||
})
|
||||
export const initSentry = async () => {
|
||||
if (!window.SENTRY_RELEASE) return
|
||||
if (import.meta.env.DEV) return
|
||||
@@ -42,5 +52,6 @@ export const initSentry = async () => {
|
||||
Sentry.setTag("user_name", user.name)
|
||||
}
|
||||
|
||||
Sentry.setTag("session_trace_id", appSessionTraceId)
|
||||
Sentry.setTag("appVersion", version)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,10 @@ export const toastFetchError = (
|
||||
|
||||
if (error instanceof FetchError) {
|
||||
try {
|
||||
const json = JSON.parse(error.response?._data)
|
||||
const json =
|
||||
typeof error.response?._data === "string"
|
||||
? JSON.parse(error.response?._data)
|
||||
: error.response?._data
|
||||
|
||||
const { reason, code, message: _message } = json
|
||||
message = _message
|
||||
|
||||
@@ -5,16 +5,21 @@ interface IssueOptions {
|
||||
title: string
|
||||
body: string
|
||||
label: string
|
||||
error?: Error
|
||||
}
|
||||
export const getNewIssueUrl = ({ body, label, title }: Partial<IssueOptions> = {}) => {
|
||||
export const getNewIssueUrl = ({ body, label, title, error }: Partial<IssueOptions> = {}) => {
|
||||
const baseUrl = `${repository.url}/issues/new`
|
||||
|
||||
const searchParams = new URLSearchParams()
|
||||
|
||||
const nextBody = [body || "", "", ...getCurrentEnvironment()].join("\n")
|
||||
searchParams.set("body", nextBody)
|
||||
let nextBody = [body || "", "", ...getCurrentEnvironment()].join("\n")
|
||||
if (label) searchParams.set("label", label)
|
||||
if (title) searchParams.set("title", title)
|
||||
|
||||
if (error && "traceId" in error && error.traceId) {
|
||||
nextBody += `\n\n### Sentry Trace ID\n${error.traceId}`
|
||||
}
|
||||
|
||||
searchParams.set("body", nextBody)
|
||||
return `${baseUrl}?${searchParams.toString()}`
|
||||
}
|
||||
|
||||
@@ -1,165 +1,54 @@
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { getOS } from "@follow/utils/utils"
|
||||
import { get } from "lodash-es"
|
||||
import type { MenuItemConstructorOptions } from "electron"
|
||||
|
||||
import { tipcClient } from "./client"
|
||||
|
||||
type MenuItemWithHide<T> = T & {
|
||||
hide?: boolean
|
||||
}
|
||||
|
||||
type BaseMenuItemText = MenuItemWithHide<{
|
||||
type: "text"
|
||||
label: string
|
||||
export type ElectronMenuItem = Omit<MenuItemConstructorOptions, "click" | "submenu"> & {
|
||||
click?: () => void
|
||||
/** only work in web app */
|
||||
icon?: React.ReactNode
|
||||
shortcut?: string
|
||||
disabled?: boolean
|
||||
checked?: boolean
|
||||
supportMultipleSelection?: boolean
|
||||
}>
|
||||
|
||||
type BaseMenuItemSeparator = MenuItemWithHide<{
|
||||
type: "separator"
|
||||
disabled?: boolean
|
||||
}>
|
||||
|
||||
type BaseMenuItem = BaseMenuItemText | BaseMenuItemSeparator
|
||||
|
||||
export type NativeMenuItem = BaseMenuItem & {
|
||||
submenu?: NativeMenuItem[]
|
||||
submenu?: ElectronMenuItem[]
|
||||
}
|
||||
|
||||
export type NullableNativeMenuItem =
|
||||
| (BaseMenuItemText & { submenu?: NullableNativeMenuItem[] })
|
||||
| BaseMenuItemSeparator
|
||||
| null
|
||||
| undefined
|
||||
| false
|
||||
| ""
|
||||
|
||||
function sortShortcutsString(shortcut: string) {
|
||||
const order = ["Shift", "Ctrl", "Meta", "Alt"]
|
||||
let nextShortcut = shortcut
|
||||
if (getOS() === "Windows") {
|
||||
nextShortcut = shortcut.replace("Meta", "Ctrl").replace("meta", "ctrl")
|
||||
}
|
||||
const arr = nextShortcut.split("+")
|
||||
|
||||
const sortedModifiers = arr
|
||||
.filter((key) => order.includes(key))
|
||||
.sort((a, b) => order.indexOf(a) - order.indexOf(b))
|
||||
|
||||
const otherKeys = arr.filter((key) => !order.includes(key))
|
||||
|
||||
return [...sortedModifiers, ...otherKeys].join("+")
|
||||
export const showElectronContextMenu = async (items: Array<ElectronMenuItem>) => {
|
||||
if (!window.electron) throw new Error("electron is not available")
|
||||
const dispose = window.electron.ipcRenderer.on(
|
||||
"menu-click",
|
||||
(_, { path }: { path: number[] }) => {
|
||||
const targetMenu = getMenuItemByPath(items, path)
|
||||
if (targetMenu && typeof targetMenu.click === "function") {
|
||||
targetMenu.click()
|
||||
} else {
|
||||
console.warn(`Menu item not found or click handler missing for path: ${path}`)
|
||||
}
|
||||
},
|
||||
)
|
||||
const itemsWithoutClick = removeClick(items)
|
||||
await tipcClient?.showContextMenu({ items: itemsWithoutClick })
|
||||
dispose()
|
||||
}
|
||||
|
||||
function processMenuItems(items: NullableNativeMenuItem[]): NativeMenuItem[] {
|
||||
return (items.filter((item) => item && !item.hide) as NativeMenuItem[]).map((item) => {
|
||||
if (item.type === "text") {
|
||||
const removeClick = (item: ElectronMenuItem[]): ElectronMenuItem[] =>
|
||||
item.map(({ click, ...rest }) => {
|
||||
if (rest.submenu)
|
||||
return {
|
||||
...item,
|
||||
shortcut: item.shortcut ? sortShortcutsString(item.shortcut) : undefined,
|
||||
submenu: item.submenu ? processMenuItems(item.submenu) : undefined,
|
||||
...rest,
|
||||
submenu: removeClick(rest.submenu),
|
||||
}
|
||||
}
|
||||
return item
|
||||
return rest
|
||||
})
|
||||
|
||||
// Function to retrieve the menu item based on the provided path
|
||||
const getMenuItemByPath = (items: ElectronMenuItem[], path: number[]): ElectronMenuItem | null => {
|
||||
let currentItems = items
|
||||
let currentItem: ElectronMenuItem | null = null
|
||||
|
||||
for (const index of path) {
|
||||
if (!currentItems || index >= currentItems.length) return null
|
||||
currentItem = currentItems[index]
|
||||
|
||||
if (currentItem.submenu && Array.isArray(currentItem.submenu)) {
|
||||
currentItems = currentItem.submenu
|
||||
} else {
|
||||
currentItems = []
|
||||
}
|
||||
}
|
||||
return currentItem
|
||||
}
|
||||
export const showNativeMenu = async (
|
||||
items: Array<NullableNativeMenuItem>,
|
||||
e?: MouseEvent | React.MouseEvent,
|
||||
) => {
|
||||
const nextItems = processMenuItems(items)
|
||||
|
||||
const el = e && e.currentTarget
|
||||
|
||||
if (el instanceof HTMLElement) {
|
||||
el.dataset.contextMenuOpen = "true"
|
||||
}
|
||||
|
||||
// only show native menu on macOS electron, because in other platform, the native ui is not good
|
||||
if (!IN_ELECTRON || getOS() !== "macOS") {
|
||||
document.dispatchEvent(
|
||||
new CustomEvent(CONTEXT_MENU_SHOW_EVENT_KEY, {
|
||||
detail: {
|
||||
items: nextItems,
|
||||
x: e?.clientX,
|
||||
y: e?.clientY,
|
||||
},
|
||||
}),
|
||||
)
|
||||
return
|
||||
} else {
|
||||
if (import.meta.env.DEV && e) {
|
||||
nextItems.push(
|
||||
{
|
||||
type: "separator" as const,
|
||||
},
|
||||
{
|
||||
type: "text" as const,
|
||||
label: "Inspect Element",
|
||||
click: () => {
|
||||
tipcClient?.inspectElement({
|
||||
x: e.pageX,
|
||||
y: e.pageY,
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const dispose = window.electron?.ipcRenderer.on("menu-click", (_, combinedIndex: string) => {
|
||||
const arr = combinedIndex.split("-")
|
||||
const accessors = [] as string[]
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
accessors.push(arr[i])
|
||||
|
||||
if (i !== arr.length - 1) {
|
||||
accessors.push("submenu")
|
||||
}
|
||||
}
|
||||
const item = get(nextItems, accessors)
|
||||
|
||||
if (item && item.type === "text") {
|
||||
item.click?.()
|
||||
}
|
||||
})
|
||||
|
||||
window.electron?.ipcRenderer.once("menu-closed", () => {
|
||||
dispose?.()
|
||||
if (el instanceof HTMLElement) {
|
||||
delete el.dataset.contextMenuOpen
|
||||
}
|
||||
|
||||
// dispatch mouse move event
|
||||
// NOTE: in order to remove the highlight of the trigger item
|
||||
// e.g. https://vscode.dev/github/RSSNext/follow/blob/dev/apps/renderer/src/modules/entry-column/layouts/EntryItemWrapper.tsx#L80
|
||||
document.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true }))
|
||||
})
|
||||
|
||||
await tipcClient?.showContextMenu({
|
||||
items: transformMenuItemsForNative(nextItems),
|
||||
})
|
||||
|
||||
function transformMenuItemsForNative(nextItems: NativeMenuItem[]) {
|
||||
return nextItems.map((item) => {
|
||||
if (item.type === "text") {
|
||||
return {
|
||||
...item,
|
||||
icon: undefined,
|
||||
enabled: item.click !== undefined || (!!item.submenu && item.submenu.length > 0),
|
||||
click: undefined,
|
||||
submenu: item.submenu ? transformMenuItemsForNative(item.submenu) : undefined,
|
||||
shortcut: item.shortcut?.replace("Meta", "CmdOrCtrl"),
|
||||
}
|
||||
}
|
||||
return item
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const CONTEXT_MENU_SHOW_EVENT_KEY = "contextmenu-show"
|
||||
|
||||
@@ -18,13 +18,13 @@ import rehypeStringify from "rehype-stringify"
|
||||
import { unified } from "unified"
|
||||
import type { Node } from "unist"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { visitParents } from "unist-util-visit-parents"
|
||||
import { VFile } from "vfile"
|
||||
|
||||
import { ShadowDOM } from "~/components/common/ShadowDOM"
|
||||
import { ShikiHighLighter } from "~/components/ui/code-highlighter"
|
||||
import { LazyKateX } from "~/components/ui/katex/lazy"
|
||||
import { MarkdownBlockImage, MarkdownLink, MarkdownP } from "~/components/ui/markdown/renderers"
|
||||
import { BlockError } from "~/components/ui/markdown/renderers/BlockErrorBoundary"
|
||||
import { useIsInParagraphContext } from "~/components/ui/markdown/renderers/ctx"
|
||||
import { createHeadingRenderer } from "~/components/ui/markdown/renderers/Heading"
|
||||
import { MarkdownInlineImage } from "~/components/ui/markdown/renderers/InlineImage"
|
||||
@@ -100,10 +100,7 @@ export const parseHtml = (
|
||||
|
||||
const tree = pipeline.parse(content)
|
||||
|
||||
// NOTE: disable for now, it introduces some issues
|
||||
// 1. It may convert parts beyond the actual link into links
|
||||
// 2. It cannot correctly handle the situation in the code block
|
||||
// rehypeUrlToAnchor(tree)
|
||||
rehypeUrlToAnchor(tree)
|
||||
|
||||
// console.log("tree", tree)
|
||||
|
||||
@@ -134,12 +131,30 @@ export const parseHtml = (
|
||||
},
|
||||
img: Img,
|
||||
|
||||
h1: createHeadingRenderer(1),
|
||||
h2: createHeadingRenderer(2),
|
||||
h3: createHeadingRenderer(3),
|
||||
h4: createHeadingRenderer(4),
|
||||
h5: createHeadingRenderer(5),
|
||||
h6: createHeadingRenderer(6),
|
||||
h1: (props) => {
|
||||
markInlineImage(props.node)
|
||||
return createHeadingRenderer(1)(props)
|
||||
},
|
||||
h2: (props) => {
|
||||
markInlineImage(props.node)
|
||||
return createHeadingRenderer(2)(props)
|
||||
},
|
||||
h3: (props) => {
|
||||
markInlineImage(props.node)
|
||||
return createHeadingRenderer(3)(props)
|
||||
},
|
||||
h4: (props) => {
|
||||
markInlineImage(props.node)
|
||||
return createHeadingRenderer(4)(props)
|
||||
},
|
||||
h5: (props) => {
|
||||
markInlineImage(props.node)
|
||||
return createHeadingRenderer(5)(props)
|
||||
},
|
||||
h6: (props) => {
|
||||
markInlineImage(props.node)
|
||||
return createHeadingRenderer(6)(props)
|
||||
},
|
||||
style: Style,
|
||||
|
||||
video: ({ node, ...props }) =>
|
||||
@@ -158,6 +173,14 @@ export const parseHtml = (
|
||||
markInlineImage(node)
|
||||
return createElement("span", props, props.children)
|
||||
},
|
||||
b: ({ node, ...props }) => {
|
||||
markInlineImage(node)
|
||||
return createElement("b", props, props.children)
|
||||
},
|
||||
i: ({ node, ...props }) => {
|
||||
markInlineImage(node)
|
||||
return createElement("i", props, props.children)
|
||||
},
|
||||
// @ts-expect-error
|
||||
math: Math,
|
||||
hr: ({ node, ...props }) =>
|
||||
@@ -209,10 +232,8 @@ export const parseHtml = (
|
||||
try {
|
||||
codeString = extractCodeFromHtml(renderToString(code))
|
||||
} catch (error) {
|
||||
return createElement(BlockError, {
|
||||
error,
|
||||
message: "Code Block Render Error",
|
||||
})
|
||||
console.error("Code Block Render Error", error)
|
||||
return createElement("pre", props, props.children)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +272,9 @@ const Img: Components["img"] = ({ node, ...props }) => {
|
||||
const widthPx = Number.parseInt(props.width as string)
|
||||
|
||||
return createElement(
|
||||
node?.properties.inline && widthPx < 600 ? MarkdownInlineImage : MarkdownBlockImage,
|
||||
node?.properties.inline && (Number.isNaN(widthPx) || widthPx < 600)
|
||||
? MarkdownInlineImage
|
||||
: MarkdownBlockImage,
|
||||
nextProps,
|
||||
)
|
||||
}
|
||||
@@ -328,9 +351,21 @@ const Style: Components["style"] = ({ node, ...props }) => {
|
||||
return null
|
||||
}
|
||||
|
||||
function _rehypeUrlToAnchor(tree: Node) {
|
||||
function rehypeUrlToAnchor(tree: Node) {
|
||||
const tagsShouldNotBeWrapped = new Set(["a", "pre", "code"])
|
||||
// https://chatgpt.com/share/37e0ceec-5c9e-4086-b9d6-5afc1af13bb0
|
||||
visit(tree, "text", (node: Text, index, parent: Node) => {
|
||||
visitParents(tree, "text", (node: Text, ancestors: Node[]) => {
|
||||
if (
|
||||
ancestors.some(
|
||||
(ancestor) =>
|
||||
"tagName" in ancestor && tagsShouldNotBeWrapped.has((ancestor as Element).tagName),
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const parent = ancestors.at(-1)
|
||||
|
||||
const urlRegex = /https?:\/\/\S+/g
|
||||
const text = node.value
|
||||
const matches = [...text.matchAll(urlRegex)]
|
||||
@@ -372,6 +407,7 @@ function _rehypeUrlToAnchor(tree: Node) {
|
||||
})
|
||||
}
|
||||
|
||||
const index = (parent.children as (Text | Element)[]).indexOf(node)
|
||||
;(parent.children as (Text | Element)[]).splice(index, 1, ...newNodes)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ import { FetchError } from "ofetch"
|
||||
|
||||
import { QUERY_PERSIST_KEY } from "../constants/app"
|
||||
|
||||
const defaultStaleTime = 600_000 // 10min
|
||||
const DO_NOT_RETRY_CODES = new Set([400, 401, 403, 404, 422])
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
refetchOnWindowFocus: false,
|
||||
retryDelay: 1000,
|
||||
staleTime: defaultStaleTime,
|
||||
retry(failureCount, error) {
|
||||
console.error(error)
|
||||
if (
|
||||
|
||||
@@ -12,6 +12,7 @@ import { RouterProvider } from "react-router-dom"
|
||||
import { setAppIsReady } from "./atoms/app"
|
||||
import { ElECTRON_CUSTOM_TITLEBAR_HEIGHT } from "./constants"
|
||||
import { initializeApp } from "./initialize"
|
||||
import { registerAppGlobalShortcuts } from "./initialize/global-shortcuts"
|
||||
import { router } from "./router"
|
||||
|
||||
initializeApp().finally(() => {
|
||||
@@ -20,8 +21,22 @@ initializeApp().finally(() => {
|
||||
|
||||
const $container = document.querySelector("#root") as HTMLElement
|
||||
|
||||
if (IN_ELECTRON && getOS() === "Windows") {
|
||||
document.body.style.cssText += `--fo-window-padding-top: ${ElECTRON_CUSTOM_TITLEBAR_HEIGHT}px;`
|
||||
if (IN_ELECTRON) {
|
||||
const os = getOS()
|
||||
|
||||
switch (os) {
|
||||
case "Windows": {
|
||||
document.body.style.cssText += `--fo-window-padding-top: ${ElECTRON_CUSTOM_TITLEBAR_HEIGHT}px;`
|
||||
break
|
||||
}
|
||||
case "macOS": {
|
||||
document.body.style.cssText += `--fo-macos-traffic-light-width: 100px; --fo-macos-traffic-light-height: 30px;`
|
||||
break
|
||||
}
|
||||
}
|
||||
document.documentElement.dataset.os = getOS()
|
||||
} else {
|
||||
registerAppGlobalShortcuts()
|
||||
}
|
||||
|
||||
ReactDOM.createRoot($container).render(
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useAuthQuery, useI18n } from "~/hooks/common"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { defineQuery } from "~/lib/defineQuery"
|
||||
import { toastFetchError } from "~/lib/error-parser"
|
||||
import { userActions } from "~/store/user"
|
||||
|
||||
import { updateFeedBoostStatus } from "./atom"
|
||||
|
||||
@@ -20,12 +21,7 @@ const query = {
|
||||
}),
|
||||
getBoosters: ({ feedId }: { feedId: string }) =>
|
||||
defineQuery(["boosters", feedId], async () => {
|
||||
const res = await apiClient.boosts.boosters.$get({
|
||||
query: {
|
||||
feedId,
|
||||
},
|
||||
})
|
||||
return res.data
|
||||
return userActions.getBoosters(feedId)
|
||||
}),
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
export const RSSHubCategoryOptions: {
|
||||
name: string
|
||||
value: string
|
||||
}[] = [
|
||||
{
|
||||
name: "All",
|
||||
value: "all",
|
||||
},
|
||||
{
|
||||
name: "Social Media",
|
||||
value: "social-media",
|
||||
},
|
||||
{
|
||||
name: "New Media",
|
||||
value: "new-media",
|
||||
},
|
||||
{
|
||||
name: "News",
|
||||
value: "traditional-media",
|
||||
},
|
||||
{
|
||||
name: "BBS",
|
||||
value: "bbs",
|
||||
},
|
||||
{
|
||||
name: "Blog",
|
||||
value: "blog",
|
||||
},
|
||||
{
|
||||
name: "Programming",
|
||||
value: "programming",
|
||||
},
|
||||
{
|
||||
name: "Design",
|
||||
value: "design",
|
||||
},
|
||||
{
|
||||
name: "Live",
|
||||
value: "live",
|
||||
},
|
||||
{
|
||||
name: "Multimedia",
|
||||
value: "multimedia",
|
||||
},
|
||||
{
|
||||
name: "Picture",
|
||||
value: "picture",
|
||||
},
|
||||
{
|
||||
name: "ACG",
|
||||
value: "anime",
|
||||
},
|
||||
{
|
||||
name: "Application Updates",
|
||||
value: "program-update",
|
||||
},
|
||||
{
|
||||
name: "University",
|
||||
value: "university",
|
||||
},
|
||||
{
|
||||
name: "Forecast",
|
||||
value: "forecast",
|
||||
},
|
||||
{
|
||||
name: "Travel",
|
||||
value: "travel",
|
||||
},
|
||||
{
|
||||
name: "Shopping",
|
||||
value: "shopping",
|
||||
},
|
||||
{
|
||||
name: "Gaming",
|
||||
value: "game",
|
||||
},
|
||||
{
|
||||
name: "Reading",
|
||||
value: "reading",
|
||||
},
|
||||
{
|
||||
name: "Government",
|
||||
value: "government",
|
||||
},
|
||||
{
|
||||
name: "Study",
|
||||
value: "study",
|
||||
},
|
||||
{
|
||||
name: "Scientific Journal",
|
||||
value: "journal",
|
||||
},
|
||||
{
|
||||
name: "Finance",
|
||||
value: "finance",
|
||||
},
|
||||
]
|
||||
|
||||
export const RSSHubCategoryMap: Record<string, string> = Object.fromEntries(
|
||||
RSSHubCategoryOptions.map((item) => [item.value, item.name]),
|
||||
)
|
||||
@@ -16,10 +16,10 @@ import { toast } from "sonner"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useUserRole } from "~/atoms/user"
|
||||
import { CustomSafeError } from "~/components/errors/helper"
|
||||
import { CopyButton } from "~/components/ui/code-highlighter"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { MAX_TRIAL_USER_INBOX_SUBSCRIPTION } from "~/constants/limit"
|
||||
import { CustomSafeError } from "~/errors/CustomSafeError"
|
||||
import { createErrorToaster } from "~/lib/error-parser"
|
||||
import { useInboxList } from "~/queries/inboxes"
|
||||
import { inboxActions } from "~/store/inbox"
|
||||
|
||||
@@ -327,7 +327,7 @@ const ListInnerForm = ({
|
||||
<FormDescription className="mt-0.5">{t("feed_form.fee_description")}</FormDescription>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-1 items-end justify-end gap-4">
|
||||
<div className="flex flex-1 items-center justify-end gap-4">
|
||||
{isSubscribed && (
|
||||
<Button
|
||||
type="button"
|
||||
|
||||
@@ -1,58 +1,153 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@follow/components/ui/card/index.jsx"
|
||||
import clsx from "clsx"
|
||||
import { upperFirst } from "lodash-es"
|
||||
import type { FC } from "react"
|
||||
import { memo } from "react"
|
||||
import { memo, useMemo } from "react"
|
||||
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
|
||||
import { RSSHubCategoryMap } from "./constants"
|
||||
import { RecommendationContent } from "./recommendation-content"
|
||||
import styles from "./recommendations.module.css"
|
||||
import type { RSSHubRouteDeclaration } from "./types"
|
||||
|
||||
interface RecommendationCardProps {
|
||||
data: RSSHubRouteDeclaration
|
||||
routePrefix: string
|
||||
setCategory: (category: string) => void
|
||||
}
|
||||
export const RecommendationCard: FC<RecommendationCardProps> = memo(({ data, routePrefix }) => {
|
||||
const { present } = useModalStack()
|
||||
return (
|
||||
<Card className="shadow-none">
|
||||
<CardHeader className="p-5 pb-3">
|
||||
<CardTitle className="flex items-center text-base">
|
||||
<FeedIcon siteUrl={`https://${data.url}`} />
|
||||
{data.name}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-5 pt-0">
|
||||
<ul className="space-y-1 text-sm text-muted-foreground">
|
||||
{Object.keys(data.routes).map((route) => (
|
||||
<li
|
||||
key={route}
|
||||
className="group hover:text-theme-foreground-hover"
|
||||
onClick={(e) => {
|
||||
;(e.target as HTMLElement).querySelector("button")?.click()
|
||||
}}
|
||||
tabIndex={-1}
|
||||
export const RecommendationCard: FC<RecommendationCardProps> = memo(
|
||||
({ data, routePrefix, setCategory }) => {
|
||||
const { present } = useModalStack()
|
||||
|
||||
const { maintainers, categories } = useMemo(() => {
|
||||
const maintainers = new Set<string>()
|
||||
const categories = new Set<string>()
|
||||
for (const route in data.routes) {
|
||||
const routeData = data.routes[route]
|
||||
if (routeData.maintainers) {
|
||||
routeData.maintainers.forEach((m) => maintainers.add(m))
|
||||
}
|
||||
if (routeData.categories) {
|
||||
routeData.categories.forEach((c) => categories.add(c))
|
||||
}
|
||||
}
|
||||
categories.delete("popular")
|
||||
return {
|
||||
maintainers: Array.from(maintainers),
|
||||
categories: Array.from(categories),
|
||||
}
|
||||
}, [data])
|
||||
|
||||
return (
|
||||
<Card className={styles["recommendations-card"]}>
|
||||
<CardHeader className="relative p-5 pb-3 @container">
|
||||
<div className="absolute left-0 top-0 h-[50px] w-full overflow-hidden @[280px]:h-[80px] dark:brightness-75">
|
||||
<span className="opacity-50 blur-2xl">
|
||||
<FeedIcon
|
||||
disableFadeIn
|
||||
siteUrl={`https://${data.url}`}
|
||||
size={400}
|
||||
className="pointer-events-none size-[500px]"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<CardTitle className="relative z-[1] flex items-center pt-[10px] text-base @[280px]:pt-10">
|
||||
<span className="center box-content flex aspect-square rounded-full bg-background p-1.5">
|
||||
<span className="overflow-hidden rounded-full">
|
||||
<FeedIcon size={28} className="mr-0" siteUrl={`https://${data.url}`} />
|
||||
</span>
|
||||
</span>
|
||||
<a
|
||||
href={`https://${data.url}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="ml-2 translate-y-1.5"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="-translate-x-1.5 rounded p-0.5 px-1.5 duration-200 group-hover:translate-x-0 group-hover:bg-muted"
|
||||
onClick={() => {
|
||||
present({
|
||||
id: `recommendation-content-${route}`,
|
||||
content: () => (
|
||||
<RecommendationContent routePrefix={routePrefix} route={data.routes[route]} />
|
||||
),
|
||||
icon: <FeedIcon className="size-4" size={16} siteUrl={`https://${data.url}`} />,
|
||||
title: `${data.name} - ${data.routes[route].name}`,
|
||||
})
|
||||
{data.name}
|
||||
</a>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex grow flex-col p-5 pt-0">
|
||||
<ul className="grow columns-2 gap-2 space-y-1 text-sm text-foreground/90">
|
||||
{Object.keys(data.routes).map((route) => (
|
||||
<li
|
||||
key={route}
|
||||
className="group ml-1 hover:text-theme-foreground-hover"
|
||||
onClick={(e) => {
|
||||
;(e.target as HTMLElement).querySelector("button")?.click()
|
||||
}}
|
||||
tabIndex={-1}
|
||||
>
|
||||
{data.routes[route].name}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
})
|
||||
<button
|
||||
type="button"
|
||||
className="relative rounded p-0.5 px-1 duration-200 before:absolute before:inset-y-0 before:-left-2 before:my-auto before:size-1.5 before:rounded-full before:bg-accent before:content-[''] group-hover:bg-muted"
|
||||
onClick={() => {
|
||||
present({
|
||||
id: `recommendation-content-${route}`,
|
||||
content: () => (
|
||||
<RecommendationContent
|
||||
routePrefix={routePrefix}
|
||||
route={data.routes[route]}
|
||||
/>
|
||||
),
|
||||
icon: (
|
||||
<FeedIcon className="size-4" size={16} siteUrl={`https://${data.url}`} />
|
||||
),
|
||||
title: `${data.name} - ${data.routes[route].name}`,
|
||||
})
|
||||
}}
|
||||
>
|
||||
{data.routes[route].name}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<div className="mt-4 flex flex-col gap-2 text-muted-foreground">
|
||||
<div className="flex flex-1 items-center text-sm">
|
||||
<i className="i-mingcute-hammer-line mr-1 shrink-0 translate-y-0.5 self-start" />
|
||||
|
||||
<span className="flex flex-wrap gap-1">
|
||||
{maintainers.map((m) => (
|
||||
<a
|
||||
key={m}
|
||||
href={`https://github.com/${m}`}
|
||||
className="follow-link--underline"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
@{m}
|
||||
</a>
|
||||
))}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-1 items-center text-sm">
|
||||
<i className="i-mingcute-tag-2-line mr-1 shrink-0 translate-y-1 self-start" />
|
||||
<span className="flex flex-wrap gap-1">
|
||||
{categories.map((c) => (
|
||||
<button
|
||||
onClick={() => {
|
||||
if (!RSSHubCategoryMap[c]) return
|
||||
setCategory(c)
|
||||
}}
|
||||
key={c}
|
||||
type="button"
|
||||
className={clsx(
|
||||
"cursor-pointer rounded bg-muted/50 px-1.5 duration-200 hover:bg-muted",
|
||||
!RSSHubCategoryMap[c] && "pointer-events-none opacity-50",
|
||||
)}
|
||||
>
|
||||
{RSSHubCategoryMap[c] || upperFirst(c)}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
.recommendations-grid {
|
||||
--rows: 4;
|
||||
--max-item-width: 280px;
|
||||
--gap: 1em;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(
|
||||
auto-fill,
|
||||
minmax(
|
||||
max(var(--max-item-width), calc((100% - var(--gap) * (var(--rows) - 1)) / var(--rows))),
|
||||
1fr
|
||||
)
|
||||
);
|
||||
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
.recommendations-card {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.06) inset;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
@@ -1,59 +1,133 @@
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.js"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@follow/components/ui/select/index.jsx"
|
||||
import { Tabs, TabsList, TabsTrigger } from "@follow/components/ui/tabs/index.js"
|
||||
import { cn, isASCII } from "@follow/utils/utils"
|
||||
import { useMemo } from "react"
|
||||
import { keepPreviousData } from "@tanstack/react-query"
|
||||
import { useMemo, useRef, useState } from "react"
|
||||
import { flushSync } from "react-dom"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { Queries } from "~/queries"
|
||||
|
||||
import { RSSHubCategoryOptions } from "./constants"
|
||||
import styles from "./recommendations.module.css"
|
||||
import { RecommendationCard } from "./recommendations-card"
|
||||
|
||||
const LanguageOptions = [
|
||||
{
|
||||
name: "English",
|
||||
value: "en",
|
||||
},
|
||||
{
|
||||
name: "简体中文",
|
||||
value: "zh-CN",
|
||||
},
|
||||
] as const
|
||||
|
||||
type Language = (typeof LanguageOptions)[number]["value"]
|
||||
type DiscoverCategories = (typeof RSSHubCategoryOptions)[number]["value"]
|
||||
|
||||
const fetchRsshubPopular = (category: DiscoverCategories, lang: Language) => {
|
||||
return Queries.discover.rsshubCategory({
|
||||
category: "popular",
|
||||
categories: category === "all" ? "popular" : `popular,${category}`,
|
||||
lang,
|
||||
})
|
||||
}
|
||||
export function Recommendations({
|
||||
hideTitle,
|
||||
className,
|
||||
headerClassName,
|
||||
}: {
|
||||
hideTitle?: boolean
|
||||
className?: string
|
||||
headerClassName?: string
|
||||
}) {
|
||||
const rsshubPopular = useAuthQuery(
|
||||
Queries.discover.rsshubCategory({
|
||||
category: "popular",
|
||||
}),
|
||||
{
|
||||
meta: {
|
||||
persist: true,
|
||||
},
|
||||
},
|
||||
)
|
||||
const { t } = useTranslation()
|
||||
const lang = useGeneralSettingKey("language")
|
||||
|
||||
const { data } = rsshubPopular
|
||||
const defaultLang = ["zh-CN", "zh-HK", "zh-TW"].includes(lang ?? "") ? "zh-CN" : "en"
|
||||
const [category, setCategory] = useState<DiscoverCategories>("all")
|
||||
const [selectedLang, setSelectedLang] = useState<Language>(defaultLang)
|
||||
|
||||
const rsshubPopular = useAuthQuery(fetchRsshubPopular(category, selectedLang), {
|
||||
meta: {
|
||||
persist: true,
|
||||
},
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
|
||||
const { data, isLoading, isFetching } = rsshubPopular
|
||||
|
||||
const keys = useMemo(() => {
|
||||
if (data) {
|
||||
return Object.keys(data).sort((a, b) => {
|
||||
const aname = data[a].name
|
||||
const bname = data[b].name
|
||||
|
||||
const aRouteName = data[a].routes[Object.keys(data[a].routes)[0]].name
|
||||
const bRouteName = data[b].routes[Object.keys(data[b].routes)[0]].name
|
||||
|
||||
const ia = isASCII(aname) && isASCII(aRouteName)
|
||||
const ib = isASCII(bname) && isASCII(bRouteName)
|
||||
|
||||
if (ia && ib) {
|
||||
return aname.toLowerCase() < bname.toLowerCase() ? -1 : 1
|
||||
} else if (ia || ib) {
|
||||
return ia > ib ? -1 : 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (!data) {
|
||||
return []
|
||||
}
|
||||
return Object.keys(data).sort((a, b) => {
|
||||
const aname = data[a].name
|
||||
const bname = data[b].name
|
||||
|
||||
const aRouteName = data[a].routes[Object.keys(data[a].routes)[0]].name
|
||||
const bRouteName = data[b].routes[Object.keys(data[b].routes)[0]].name
|
||||
|
||||
const ia = isASCII(aname) && isASCII(aRouteName)
|
||||
const ib = isASCII(bname) && isASCII(bRouteName)
|
||||
|
||||
if (ia && ib) {
|
||||
return aname.toLowerCase() < bname.toLowerCase() ? -1 : 1
|
||||
} else if (ia || ib) {
|
||||
return ia > ib ? -1 : 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
})
|
||||
}, [data])
|
||||
|
||||
const { t } = useTranslation()
|
||||
if (rsshubPopular.isLoading) {
|
||||
const handleCategoryChange = (value: DiscoverCategories) => {
|
||||
flushSync(() => {
|
||||
setCategory(value)
|
||||
})
|
||||
rsshubPopular.refetch()
|
||||
}
|
||||
|
||||
const handleLangChange = (value: string) => {
|
||||
flushSync(() => {
|
||||
setSelectedLang(value as Language)
|
||||
})
|
||||
rsshubPopular.refetch()
|
||||
}
|
||||
|
||||
const tabRef = useRef<HTMLDivElement>(null)
|
||||
const handleChangeCategoryAndJumpTo = useEventCallback((category: DiscoverCategories) => {
|
||||
handleCategoryChange(category)
|
||||
|
||||
if (tabRef.current) {
|
||||
const tab = tabRef.current.querySelector(`[data-value="${category}"]`)
|
||||
if (tab) {
|
||||
const tabRect = tab.getBoundingClientRect()
|
||||
const containerRect = tabRef.current.getBoundingClientRect()
|
||||
const scrollLeft =
|
||||
tabRect.left -
|
||||
containerRect.left +
|
||||
tabRef.current.scrollLeft -
|
||||
(containerRect.width - tabRect.width) / 2
|
||||
|
||||
tabRef.current.scrollTo({ left: scrollLeft, behavior: "smooth" })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (isLoading) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -62,12 +136,71 @@ export function Recommendations({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(!hideTitle && "mt-8")}>
|
||||
{!hideTitle && <div className="text-center text-lg font-bold">{t("discover.popular")}</div>}
|
||||
<div className={cn(!hideTitle && "mt-8 w-full max-w-[1200px] px-4")}>
|
||||
{!hideTitle && (
|
||||
<div className="relative text-center text-lg font-bold">
|
||||
<span>{t("discover.popular")}</span>
|
||||
|
||||
<div className={cn("mt-4 grid grid-cols-3 gap-4 px-3", className)}>
|
||||
{isFetching && (
|
||||
<div className="pointer-events-none absolute inset-x-0 top-0 flex items-center justify-center gap-8">
|
||||
<span className="opacity-0" aria-hidden>
|
||||
{t("discover.popular")}
|
||||
</span>
|
||||
<LoadingCircle size="small" className="center flex" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
"z-[9] my-3 flex w-full items-center gap-4 bg-theme-background",
|
||||
headerClassName,
|
||||
)}
|
||||
>
|
||||
<ScrollArea.ScrollArea
|
||||
ref={tabRef}
|
||||
orientation="horizontal"
|
||||
rootClassName="grow min-w-0 overflow-visible"
|
||||
scrollbarClassName="-mb-3 z-[100]"
|
||||
>
|
||||
<Tabs value={category} onValueChange={handleCategoryChange}>
|
||||
<TabsList>
|
||||
{RSSHubCategoryOptions.map((category) => (
|
||||
<TabsTrigger
|
||||
data-value={category.value}
|
||||
key={category.value}
|
||||
value={category.value}
|
||||
>
|
||||
{category.name}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
</ScrollArea.ScrollArea>
|
||||
<Select value={selectedLang} onValueChange={handleLangChange}>
|
||||
<SelectTrigger size="sm" className="w-32">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
|
||||
<SelectContent className="z-[1]" position="item-aligned">
|
||||
{LanguageOptions.map((lang) => (
|
||||
<SelectItem key={lang.value} value={lang.value}>
|
||||
{lang.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className={cn(styles["recommendations-grid"], "mt-6", className)}>
|
||||
{keys.map((key) => (
|
||||
<RecommendationCard key={key} data={data[key]} routePrefix={key} />
|
||||
<RecommendationCard
|
||||
key={key}
|
||||
data={data[key]}
|
||||
routePrefix={key}
|
||||
setCategory={handleChangeCategoryAndJumpTo}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -67,7 +67,7 @@ export const EntryColumnShortcutHandler: FC<{
|
||||
entryId: nextId,
|
||||
})
|
||||
},
|
||||
{ scopes: HotKeyScopeMap.Home, enabled: enabledArrowKey },
|
||||
{ scopes: HotKeyScopeMap.Home, enabled: enabledArrowKey, preventDefault: true },
|
||||
)
|
||||
useHotkeys(
|
||||
shortcuts.entries.previous.key,
|
||||
@@ -87,7 +87,7 @@ export const EntryColumnShortcutHandler: FC<{
|
||||
entryId: nextId,
|
||||
})
|
||||
},
|
||||
{ scopes: HotKeyScopeMap.Home, enabled: enabledArrowKey },
|
||||
{ scopes: HotKeyScopeMap.Home, enabled: enabledArrowKey, preventDefault: true },
|
||||
)
|
||||
return null
|
||||
})
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import {
|
||||
MasonryIntersectionContext,
|
||||
useMasonryItemRatio,
|
||||
useMasonryItemWidth,
|
||||
useSetStableMasonryItemRatio,
|
||||
} from "@follow/components/ui/masonry/contexts.jsx"
|
||||
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
@@ -22,12 +28,6 @@ import { usePreviewMedia } from "../../../components/ui/media/hooks"
|
||||
import { EntryItemWrapper } from "../layouts/EntryItemWrapper"
|
||||
import { GridItem, GridItemFooter } from "../templates/grid-item-template"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
import {
|
||||
MasonryIntersectionContext,
|
||||
useMasonryItemRatio,
|
||||
useMasonryItemWidth,
|
||||
useSetStableMasonryItemRatio,
|
||||
} from "./contexts/picture-masonry-context"
|
||||
|
||||
export function PictureItem({ entryId, entryPreview, translation }: UniversalItemProps) {
|
||||
const entry = useEntry(entryId) || entryPreview
|
||||
@@ -75,7 +75,8 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
|
||||
entryPreview,
|
||||
translation,
|
||||
index,
|
||||
}: UniversalItemProps & { index: number }) {
|
||||
className,
|
||||
}: UniversalItemProps & { index: number; className?: string }) {
|
||||
const entry = useEntry(entryId) || entryPreview
|
||||
|
||||
const isActive = useRouteParamsSelector(({ entryId }) => entryId === entry?.entries.id)
|
||||
@@ -97,6 +98,7 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
|
||||
}, [ref, intersectionObserver])
|
||||
|
||||
const [isMouseEnter, setIsMouseEnter] = useState(false)
|
||||
|
||||
if (!entry) return null
|
||||
|
||||
const media = filterSmallMedia(entry.entries.media)
|
||||
@@ -108,6 +110,7 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
|
||||
data-index={index}
|
||||
onMouseEnter={() => setIsMouseEnter(true)}
|
||||
onMouseLeave={() => setIsMouseEnter(false)}
|
||||
className={className}
|
||||
>
|
||||
<EntryItemWrapper
|
||||
view={FeedViewType.Pictures}
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
import {
|
||||
MasonryIntersectionContext,
|
||||
MasonryItemsAspectRatioContext,
|
||||
MasonryItemsAspectRatioSetterContext,
|
||||
MasonryItemWidthContext,
|
||||
} from "@follow/components/ui/masonry/contexts.jsx"
|
||||
import { useMasonryColumn } from "@follow/components/ui/masonry/hooks.js"
|
||||
import { Masonry } from "@follow/components/ui/masonry/index.js"
|
||||
import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
|
||||
import { Skeleton } from "@follow/components/ui/skeleton/index.jsx"
|
||||
import { useRefValue } from "@follow/hooks"
|
||||
import { nextFrame } from "@follow/utils/dom"
|
||||
import { throttle } from "lodash-es"
|
||||
import clsx from "clsx"
|
||||
import type { RenderComponentProps } from "masonic"
|
||||
import { useInfiniteLoader } from "masonic"
|
||||
import type { FC } from "react"
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"
|
||||
import {
|
||||
createContext,
|
||||
startTransition,
|
||||
useCallback,
|
||||
useContext,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
@@ -16,45 +33,13 @@ import { getEntry } from "~/store/entry"
|
||||
import { imageActions } from "~/store/image"
|
||||
|
||||
import { batchMarkRead } from "../hooks"
|
||||
import {
|
||||
MasonryIntersectionContext,
|
||||
MasonryItemsAspectRatioContext,
|
||||
MasonryItemsAspectRatioSetterContext,
|
||||
MasonryItemWidthContext,
|
||||
} from "./contexts/picture-masonry-context"
|
||||
import { PictureWaterFallItem } from "./picture-item"
|
||||
|
||||
// grid grid-cols-1 @lg:grid-cols-2 @3xl:grid-cols-3 @6xl:grid-cols-4 @7xl:grid-cols-5 px-4 gap-1.5
|
||||
|
||||
const breakpoints = {
|
||||
0: 1,
|
||||
// 32rem => 32 * 16= 512
|
||||
512: 2,
|
||||
// 48rem => 48 * 16= 768
|
||||
768: 3,
|
||||
// 72rem => 72 * 16= 1152
|
||||
1152: 4,
|
||||
// 80rem => 80 * 16= 1280
|
||||
1280: 5,
|
||||
1536: 6,
|
||||
1792: 7,
|
||||
2048: 8,
|
||||
}
|
||||
const getCurrentColumn = (w: number) => {
|
||||
// Initialize column count with the minimum number of columns
|
||||
let columns = 1
|
||||
|
||||
// Iterate through each breakpoint and determine the column count
|
||||
for (const [breakpoint, cols] of Object.entries(breakpoints)) {
|
||||
if (w >= Number.parseInt(breakpoint)) {
|
||||
columns = cols
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return columns
|
||||
}
|
||||
const FirstScreenItemCount = 20
|
||||
const FirstScreenReadyCountDown = 150
|
||||
const FirstScreenReadyContext = createContext(false)
|
||||
const gutter = 24
|
||||
|
||||
export const PictureMasonry: FC<MasonryProps> = (props) => {
|
||||
@@ -62,7 +47,7 @@ export const PictureMasonry: FC<MasonryProps> = (props) => {
|
||||
const cacheMap = useState(() => new Map<string, object>())[0]
|
||||
const [isInitDim, setIsInitDim] = useState(false)
|
||||
const [isInitLayout, setIsInitLayout] = useState(false)
|
||||
const [currentItemWidth, setCurrentItemWidth] = useState(0)
|
||||
const deferIsInitLayout = useDeferredValue(isInitLayout)
|
||||
const restoreDimensions = useEventCallback(async () => {
|
||||
const images = [] as string[]
|
||||
data.forEach((entryId) => {
|
||||
@@ -73,48 +58,18 @@ export const PictureMasonry: FC<MasonryProps> = (props) => {
|
||||
})
|
||||
return imageActions.fetchDimensionsFromDb(images)
|
||||
})
|
||||
useEffect(() => {
|
||||
restoreDimensions().finally(() => {
|
||||
setIsInitDim(true)
|
||||
})
|
||||
}, [])
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const [currentColumn, setCurrentColumn] = useState(1)
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const $warpper = containerRef.current
|
||||
if (!$warpper) return
|
||||
const handler = () => {
|
||||
const column = getCurrentColumn($warpper.clientWidth)
|
||||
setCurrentItemWidth(Math.trunc($warpper.clientWidth / column - gutter))
|
||||
|
||||
setCurrentColumn(column)
|
||||
|
||||
nextFrame(() => {
|
||||
setIsInitLayout(true)
|
||||
restoreDimensions().finally(() => {
|
||||
startTransition(() => {
|
||||
setIsInitDim(true)
|
||||
})
|
||||
}
|
||||
const recal = throttle(handler, 1000 / 12)
|
||||
|
||||
let previousWidth = $warpper.offsetWidth
|
||||
const resizeObserver = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const newWidth = entry.contentRect.width
|
||||
|
||||
if (newWidth !== previousWidth) {
|
||||
previousWidth = newWidth
|
||||
|
||||
recal()
|
||||
}
|
||||
}
|
||||
})
|
||||
recal()
|
||||
resizeObserver.observe($warpper)
|
||||
return () => {
|
||||
resizeObserver.disconnect()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const { containerRef, currentColumn, currentItemWidth } = useMasonryColumn(gutter, () => {
|
||||
setIsInitLayout(true)
|
||||
})
|
||||
|
||||
const items = useMemo(() => {
|
||||
const result = data.map((entryId) => {
|
||||
const cache = cacheMap.get(entryId)
|
||||
@@ -228,24 +183,37 @@ export const PictureMasonry: FC<MasonryProps> = (props) => {
|
||||
}
|
||||
}, [scrollElement, renderMarkRead, scrollMarkRead, dataRef])
|
||||
|
||||
const [firstScreenReady, setFirstScreenReady] = useState(false)
|
||||
useEffect(() => {
|
||||
if (firstScreenReady) return
|
||||
const timer = setTimeout(() => {
|
||||
setFirstScreenReady(true)
|
||||
}, FirstScreenReadyCountDown)
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="px-4 pt-2">
|
||||
{isInitDim && isInitLayout && (
|
||||
{isInitDim && deferIsInitLayout && (
|
||||
<MasonryItemWidthContext.Provider value={currentItemWidth}>
|
||||
<MasonryItemsAspectRatioContext.Provider value={masonryItemsRadio}>
|
||||
<MasonryItemsAspectRatioSetterContext.Provider value={setMasonryItemsRadio}>
|
||||
<MasonryIntersectionContext.Provider value={intersectionObserver}>
|
||||
<MediaContainerWidthProvider width={currentItemWidth}>
|
||||
<Masonry
|
||||
items={items}
|
||||
columnGutter={gutter}
|
||||
columnWidth={currentItemWidth}
|
||||
columnCount={currentColumn}
|
||||
overscanBy={2}
|
||||
render={render}
|
||||
onRender={handleRender}
|
||||
itemKey={itemKey}
|
||||
/>
|
||||
<FirstScreenReadyContext.Provider value={firstScreenReady}>
|
||||
<Masonry
|
||||
items={firstScreenReady ? items : items.slice(0, FirstScreenItemCount)}
|
||||
columnGutter={gutter}
|
||||
columnWidth={currentItemWidth}
|
||||
columnCount={currentColumn}
|
||||
overscanBy={2}
|
||||
render={MasonryRender}
|
||||
onRender={handleRender}
|
||||
itemKey={itemKey}
|
||||
/>
|
||||
</FirstScreenReadyContext.Provider>
|
||||
</MediaContainerWidthProvider>
|
||||
</MasonryIntersectionContext.Provider>
|
||||
</MasonryItemsAspectRatioSetterContext.Provider>
|
||||
@@ -257,16 +225,26 @@ export const PictureMasonry: FC<MasonryProps> = (props) => {
|
||||
}
|
||||
|
||||
const itemKey = (item: { entryId: string }) => item.entryId
|
||||
const render: React.ComponentType<
|
||||
const MasonryRender: React.ComponentType<
|
||||
RenderComponentProps<{
|
||||
entryId: string
|
||||
}>
|
||||
> = ({ data, index }) => {
|
||||
const firstScreenReady = useContext(FirstScreenReadyContext)
|
||||
if (data.entryId.startsWith("placeholder")) {
|
||||
return <LoadingSkeletonItem />
|
||||
}
|
||||
|
||||
return <PictureWaterFallItem entryId={data.entryId} index={index} />
|
||||
return (
|
||||
<PictureWaterFallItem
|
||||
className={clsx(
|
||||
firstScreenReady ? "opacity-100" : "opacity-0",
|
||||
"transition-opacity duration-200",
|
||||
)}
|
||||
entryId={data.entryId}
|
||||
index={index}
|
||||
/>
|
||||
)
|
||||
}
|
||||
interface MasonryProps {
|
||||
data: string[]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useViewport } from "@follow/components/hooks/useViewport.js"
|
||||
import { ActionButton, Button, IconButton } from "@follow/components/ui/button/index.js"
|
||||
import { RootPortal } from "@follow/components/ui/portal/index.jsx"
|
||||
import { useCountdown } from "@follow/hooks"
|
||||
import { cn, getOS } from "@follow/utils/utils"
|
||||
import { AnimatePresence, m } from "framer-motion"
|
||||
import type { FC, ReactNode } from "react"
|
||||
@@ -86,7 +87,7 @@ export const MarkAllReadWithOverlay = forwardRef<
|
||||
<Trans
|
||||
i18nKey="mark_all_read_button.mark_as_read"
|
||||
components={{
|
||||
which: commonT(`words.which.${which}` as any),
|
||||
which: <>{commonT(`words.which.${which}` as any)}</>,
|
||||
}}
|
||||
/>
|
||||
{shortcut && (
|
||||
@@ -162,7 +163,7 @@ const Popup = ({ which, containerRef, setPopoverRef, setShow, handleMarkAllAsRea
|
||||
<Trans
|
||||
i18nKey="mark_all_read_button.confirm_mark_all"
|
||||
components={{
|
||||
which: commonT(`words.which.${which}` as any),
|
||||
which: <>{commonT(`words.which.${which}` as any)}</>,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
@@ -186,14 +187,19 @@ const Popup = ({ which, containerRef, setPopoverRef, setShow, handleMarkAllAsRea
|
||||
|
||||
const ConfirmMarkAllReadInfo = ({ undo }: { undo: () => any }) => {
|
||||
const { t } = useTranslation()
|
||||
const [countdown] = useCountdown({ countStart: 3 })
|
||||
|
||||
useHotkeys("ctrl+z,meta+z", undo, {
|
||||
scopes: HotKeyScopeMap.Home,
|
||||
preventDefault: true,
|
||||
})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>{t("mark_all_read_button.confirm_mark_all_info")}</p>
|
||||
<small className="opacity-50">{t("mark_all_read_button.auto_confirm_info")}</small>
|
||||
<small className="opacity-50">
|
||||
{t("mark_all_read_button.auto_confirm_info", { countdown })}
|
||||
</small>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { views } from "@follow/constants"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import type { ListRange } from "react-virtuoso"
|
||||
import { useDebounceCallback } from "usehooks-ts"
|
||||
@@ -6,8 +7,9 @@ import { useDebounceCallback } from "usehooks-ts"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { apiClient, apiFetch } from "~/lib/api-fetch"
|
||||
import { entries, useEntries } from "~/queries/entries"
|
||||
import { entryActions, useEntryIdsByFeedIdOrView } from "~/store/entry"
|
||||
import { entryActions, getEntry, useEntryIdsByFeedIdOrView } from "~/store/entry"
|
||||
import { useFolderFeedsByFeedId } from "~/store/subscription"
|
||||
import { feedUnreadActions } from "~/store/unread"
|
||||
|
||||
@@ -50,6 +52,7 @@ export const useEntryMarkReadHandler = (entriesIds: string[]) => {
|
||||
}, [feedView, handleMarkReadInRange, handleRenderAsRead, renderAsRead, scrollMarkUnread])
|
||||
}
|
||||
const anyString = [] as string[]
|
||||
|
||||
export const useEntriesByView = ({
|
||||
onReset,
|
||||
isArchived,
|
||||
@@ -114,6 +117,8 @@ export const useEntriesByView = ({
|
||||
] as string[]
|
||||
}, [query.data?.pages])
|
||||
|
||||
useFetchEntryContentByStream(remoteEntryIds)
|
||||
|
||||
const currentEntries = useEntryIdsByFeedIdOrView(isAllFeeds ? view : folderIds || feedId!, {
|
||||
unread: unreadOnly,
|
||||
view,
|
||||
@@ -273,3 +278,82 @@ function sortEntriesIdByEntryInsertedAt(entries: string[]) {
|
||||
entriesId2Map[b]?.entries.insertedAt.localeCompare(entriesId2Map[a]?.entries.insertedAt),
|
||||
)
|
||||
}
|
||||
|
||||
const useFetchEntryContentByStream = (remoteEntryIds?: string[]) => {
|
||||
const { mutate: updateEntryContent } = useMutation({
|
||||
mutationKey: ["stream-entry-content", remoteEntryIds],
|
||||
mutationFn: async (remoteEntryIds: string[]) => {
|
||||
const onlyNoStored = true
|
||||
|
||||
const nextIds = [] as string[]
|
||||
if (onlyNoStored) {
|
||||
for (const id of remoteEntryIds) {
|
||||
const entry = getEntry(id)
|
||||
if (entry.entries.content) {
|
||||
continue
|
||||
}
|
||||
|
||||
nextIds.push(id)
|
||||
}
|
||||
}
|
||||
|
||||
if (nextIds.length === 0) return
|
||||
|
||||
const readStream = async () => {
|
||||
const response = await apiFetch(apiClient.entries.stream.$url().toString(), {
|
||||
method: "post",
|
||||
body: JSON.stringify({
|
||||
ids: nextIds,
|
||||
}),
|
||||
responseType: "stream",
|
||||
})
|
||||
|
||||
const reader = response.getReader()
|
||||
if (!reader) return
|
||||
|
||||
const decoder = new TextDecoder()
|
||||
let buffer = ""
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
|
||||
buffer += decoder.decode(value, { stream: true })
|
||||
const lines = buffer.split("\n")
|
||||
|
||||
// Process all complete lines
|
||||
for (let i = 0; i < lines.length - 1; i++) {
|
||||
if (lines[i].trim()) {
|
||||
const json = JSON.parse(lines[i])
|
||||
// Handle each JSON line here
|
||||
entryActions.updateEntryContent(json.id, json.content)
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the last incomplete line in the buffer
|
||||
buffer = lines.at(-1) || ""
|
||||
}
|
||||
|
||||
// Process any remaining data
|
||||
if (buffer.trim()) {
|
||||
const json = JSON.parse(buffer)
|
||||
|
||||
entryActions.updateEntryContent(json.id, json.content)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error reading stream:", error)
|
||||
} finally {
|
||||
reader.releaseLock()
|
||||
}
|
||||
}
|
||||
|
||||
readStream()
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!remoteEntryIds) return
|
||||
updateEntryContent(remoteEntryIds)
|
||||
}, [remoteEntryIds, updateEntryContent])
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { useAnyPointDown } from "@follow/hooks"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import type { FC, PropsWithChildren } from "react"
|
||||
import { useCallback, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useDebounceCallback } from "usehooks-ts"
|
||||
|
||||
import { useShowContextMenu } from "~/atoms/context-menu"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useAsRead } from "~/hooks/biz/useAsRead"
|
||||
import { useEntryActions } from "~/hooks/biz/useEntryActions"
|
||||
import { useFeedActions } from "~/hooks/biz/useFeedActions"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { showNativeMenu } from "~/lib/native-menu"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
import { entryActions } from "~/store/entry"
|
||||
|
||||
@@ -76,12 +75,12 @@ export const EntryItemWrapper: FC<
|
||||
[entry.entries.url],
|
||||
)
|
||||
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
||||
useAnyPointDown(() => isContextMenuOpen && setIsContextMenuOpen(false))
|
||||
const showContextMenu = useShowContextMenu()
|
||||
const handleContextMenu: React.MouseEventHandler<HTMLDivElement> = useCallback(
|
||||
(e) => {
|
||||
async (e) => {
|
||||
e.preventDefault()
|
||||
setIsContextMenuOpen(true)
|
||||
showNativeMenu(
|
||||
await showContextMenu(
|
||||
[
|
||||
...items
|
||||
.filter((item) => !item.hide)
|
||||
@@ -109,8 +108,9 @@ export const EntryItemWrapper: FC<
|
||||
],
|
||||
e,
|
||||
)
|
||||
setIsContextMenuOpen(false)
|
||||
},
|
||||
[items, feedItems, t, entry.entries.id],
|
||||
[showContextMenu, items, feedItems, t, entry.entries.id],
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { MdiMeditation } from "@follow/components/icons/Meditation.jsx"
|
||||
import { ActionButton } from "@follow/components/ui/button/index.js"
|
||||
import { DividerVertical } from "@follow/components/ui/divider/index.js"
|
||||
import { RotatingRefreshIcon } from "@follow/components/ui/loading/index.jsx"
|
||||
@@ -12,7 +13,13 @@ import * as React from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { setGeneralSetting, useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { setUISetting, useUISettingKey } from "~/atoms/settings/ui"
|
||||
import {
|
||||
setUISetting,
|
||||
useIsZenMode,
|
||||
useRealInWideMode,
|
||||
useSetZenMode,
|
||||
useUISettingKey,
|
||||
} from "~/atoms/settings/ui"
|
||||
import { useWhoami } from "~/atoms/user"
|
||||
import { ImpressionView } from "~/components/common/ImpressionTracker"
|
||||
import { FEED_COLLECTION_LIST, ROUTE_ENTRY_PENDING, ROUTE_FEED_IN_LIST } from "~/constants"
|
||||
@@ -234,9 +241,11 @@ const SwitchToMasonryButton = () => {
|
||||
}
|
||||
|
||||
const WideModeButton = () => {
|
||||
const isWideMode = useUISettingKey("wideMode")
|
||||
const isWideMode = useRealInWideMode()
|
||||
const isZenMode = useIsZenMode()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const setIsZenMode = useSetZenMode()
|
||||
return (
|
||||
<ImpressionView
|
||||
event="Switch to Wide Mode"
|
||||
@@ -247,23 +256,33 @@ const WideModeButton = () => {
|
||||
<ActionButton
|
||||
shortcut={shortcuts.layout.toggleWideMode.key}
|
||||
onClick={() => {
|
||||
setUISetting("wideMode", !isWideMode)
|
||||
// TODO: Remove this after useMeasure can get bounds in time
|
||||
window.dispatchEvent(new Event("resize"))
|
||||
if (isZenMode) {
|
||||
setIsZenMode(false)
|
||||
} else {
|
||||
setUISetting("wideMode", !isWideMode)
|
||||
// TODO: Remove this after useMeasure can get bounds in time
|
||||
window.dispatchEvent(new Event("resize"))
|
||||
}
|
||||
window.analytics?.capture("Switch to Wide Mode", {
|
||||
wideMode: !isWideMode ? 1 : 0,
|
||||
click: 1,
|
||||
})
|
||||
}}
|
||||
tooltip={
|
||||
!isWideMode
|
||||
? t("entry_list_header.switch_to_widemode")
|
||||
: t("entry_list_header.switch_to_normalmode")
|
||||
isZenMode
|
||||
? t("zen.exit")
|
||||
: !isWideMode
|
||||
? t("entry_list_header.switch_to_widemode")
|
||||
: t("entry_list_header.switch_to_normalmode")
|
||||
}
|
||||
>
|
||||
<i
|
||||
className={cn(isWideMode ? "i-mgc-align-justify-cute-re" : "i-mgc-align-left-cute-re")}
|
||||
/>
|
||||
{isZenMode ? (
|
||||
<MdiMeditation />
|
||||
) : (
|
||||
<i
|
||||
className={cn(isWideMode ? "i-mgc-align-justify-cute-re" : "i-mgc-align-left-cute-re")}
|
||||
/>
|
||||
)}
|
||||
</ActionButton>
|
||||
</ImpressionView>
|
||||
)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
|
||||
import { cn, isSafari } from "@follow/utils/utils"
|
||||
import { useDebounceCallback } from "usehooks-ts"
|
||||
|
||||
import { AudioPlayer, useAudioPlayerAtomSelector } from "~/atoms/player"
|
||||
import { useUISettingKeys } from "~/atoms/settings/ui"
|
||||
import { useRealInWideMode, useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { FEED_COLLECTION_LIST } from "~/constants"
|
||||
@@ -12,7 +11,6 @@ import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { EntryTranslation } from "~/modules/entry-column/translation"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
import { Queries } from "~/queries"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
import { getPreferredTitle, useFeedById } from "~/store/feed"
|
||||
import { useInboxById } from "~/store/inbox"
|
||||
@@ -52,17 +50,18 @@ export function ListItem({
|
||||
|
||||
const inbox = useInboxById(entry?.inboxId)
|
||||
|
||||
const handlePrefetchEntry = useDebounceCallback(
|
||||
() => {
|
||||
inbox
|
||||
? Queries.entries.byInboxId(entryId).prefetch()
|
||||
: Queries.entries.byId(entryId).prefetch()
|
||||
},
|
||||
300,
|
||||
{ leading: false },
|
||||
)
|
||||
// const handlePrefetchEntry = useDebounceCallback(
|
||||
// () => {
|
||||
// inbox
|
||||
// ? Queries.entries.byInboxId(entryId).prefetch()
|
||||
// : Queries.entries.byId(entryId).prefetch()
|
||||
// },
|
||||
// 300,
|
||||
// { leading: false },
|
||||
// )
|
||||
|
||||
const [settingWideMode, thumbnailRatio] = useUISettingKeys(["wideMode", "thumbnailRatio"])
|
||||
const settingWideMode = useRealInWideMode()
|
||||
const thumbnailRatio = useUISettingKey("thumbnailRatio")
|
||||
const rid = `list-item-${entryId}`
|
||||
|
||||
// NOTE: prevent 0 height element, react virtuoso will not stop render any more
|
||||
@@ -75,8 +74,8 @@ export function ListItem({
|
||||
|
||||
return (
|
||||
<div
|
||||
onMouseEnter={handlePrefetchEntry}
|
||||
onMouseLeave={handlePrefetchEntry.cancel}
|
||||
// onMouseEnter={handlePrefetchEntry}
|
||||
// onMouseLeave={handlePrefetchEntry.cancel}
|
||||
className={cn(
|
||||
"group relative flex cursor-menu pl-3 pr-2",
|
||||
!asRead &&
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import {
|
||||
MasonryItemsAspectRatioContext,
|
||||
MasonryItemsAspectRatioSetterContext,
|
||||
MasonryItemWidthContext,
|
||||
useMasonryItemRatio,
|
||||
useMasonryItemWidth,
|
||||
useSetStableMasonryItemRatio,
|
||||
} from "@follow/components/ui/masonry/contexts.jsx"
|
||||
import { useMasonryColumn } from "@follow/components/ui/masonry/hooks.js"
|
||||
import type { MediaModel } from "@follow/models/types"
|
||||
import type { RenderComponentProps } from "masonic"
|
||||
import { Masonry } from "masonic"
|
||||
import type { PropsWithChildren } from "react"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
|
||||
import { Media, MediaContainerWidthProvider } from "~/components/ui/media"
|
||||
import { useImageDimensions } from "~/store/image"
|
||||
|
||||
const gutter = 24
|
||||
|
||||
const Render: React.ComponentType<
|
||||
RenderComponentProps<{
|
||||
url: string
|
||||
type: "photo" | "video"
|
||||
height?: number
|
||||
width?: number
|
||||
blurhash?: string
|
||||
}>
|
||||
> = ({ data }) => {
|
||||
const { url, type, height, width, blurhash } = data
|
||||
|
||||
const itemWidth = useMasonryItemWidth()
|
||||
|
||||
return (
|
||||
<MasonryItemFixedDimensionWrapper url={url}>
|
||||
<Media
|
||||
thumbnail
|
||||
src={url}
|
||||
type={type}
|
||||
className="size-full overflow-hidden"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: itemWidth,
|
||||
height: 0,
|
||||
}}
|
||||
height={height}
|
||||
width={width}
|
||||
blurhash={blurhash}
|
||||
/>
|
||||
</MasonryItemFixedDimensionWrapper>
|
||||
)
|
||||
}
|
||||
export const ImageGallery = ({ images }: { images: MediaModel[] }) => {
|
||||
const { containerRef, currentColumn, currentItemWidth } = useMasonryColumn(gutter)
|
||||
|
||||
const [masonryItemsRadio, setMasonryItemsRadio] = useState<Record<string, number>>({})
|
||||
return (
|
||||
<div ref={containerRef}>
|
||||
<MasonryItemWidthContext.Provider value={currentItemWidth}>
|
||||
<MasonryItemsAspectRatioContext.Provider value={masonryItemsRadio}>
|
||||
<MasonryItemsAspectRatioSetterContext.Provider value={setMasonryItemsRadio}>
|
||||
<MediaContainerWidthProvider width={currentItemWidth}>
|
||||
<Masonry<(typeof images)[number]>
|
||||
items={images}
|
||||
columnGutter={gutter}
|
||||
columnWidth={currentItemWidth}
|
||||
columnCount={currentColumn}
|
||||
overscanBy={2}
|
||||
render={Render as any}
|
||||
/>
|
||||
</MediaContainerWidthProvider>
|
||||
</MasonryItemsAspectRatioSetterContext.Provider>
|
||||
</MasonryItemsAspectRatioContext.Provider>
|
||||
</MasonryItemWidthContext.Provider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const MasonryItemFixedDimensionWrapper = (
|
||||
props: PropsWithChildren<{
|
||||
url: string
|
||||
}>,
|
||||
) => {
|
||||
const { url, children } = props
|
||||
const dim = useImageDimensions(url)
|
||||
const itemWidth = useMasonryItemWidth()
|
||||
|
||||
const itemHeight = dim ? itemWidth / dim.ratio : itemWidth
|
||||
const stableRadio = useState(() => itemWidth / itemHeight || 1)[0]
|
||||
const setItemStableRatio = useSetStableMasonryItemRatio()
|
||||
|
||||
const stableRadioCtx = useMasonryItemRatio(url)
|
||||
|
||||
useEffect(() => {
|
||||
setItemStableRatio(url, stableRadio)
|
||||
}, [setItemStableRatio, stableRadio, url])
|
||||
|
||||
const style = useMemo(
|
||||
() => ({
|
||||
width: itemWidth,
|
||||
height: itemWidth / stableRadioCtx,
|
||||
}),
|
||||
[itemWidth, stableRadioCtx],
|
||||
)
|
||||
|
||||
if (!style.height) return null
|
||||
|
||||
return (
|
||||
<div className="relative flex h-full gap-2 overflow-x-auto overflow-y-hidden" style={style}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -77,13 +77,20 @@ export const EntryTitle = ({ entryId, compact }: EntryLinkProps) => {
|
||||
<a
|
||||
href={populatedFullHref || void 0}
|
||||
target="_blank"
|
||||
draggable="false"
|
||||
className="-mx-6 block cursor-button rounded-lg p-6 transition-colors hover:bg-theme-item-hover focus-visible:bg-theme-item-hover focus-visible:!outline-none @sm:-mx-3 @sm:p-3"
|
||||
rel="noreferrer"
|
||||
onClick={(e) => {
|
||||
if (window.getSelection()?.toString()) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className={cn("select-text break-words font-bold", compact ? "text-2xl" : "text-3xl")}>
|
||||
<EntryTranslation
|
||||
source={entry.entries.title}
|
||||
target={translation.data?.title}
|
||||
className="select-text"
|
||||
useOverlay
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ActionButton } from "@follow/components/ui/button/index.js"
|
||||
import { DividerVertical } from "@follow/components/ui/divider/index.js"
|
||||
import { FeedViewType, views } from "@follow/constants"
|
||||
import type { CombinedEntryModel } from "@follow/models/types"
|
||||
import type { CombinedEntryModel, MediaModel } from "@follow/models/types"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
@@ -17,15 +17,18 @@ import {
|
||||
useEntryInReadabilityStatus,
|
||||
} from "~/atoms/readability"
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { shortcuts } from "~/constants/shortcuts"
|
||||
import { useEntryActions, useEntryReadabilityToggle } from "~/hooks/biz/useEntryActions"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import { filterSmallMedia } from "~/lib/utils"
|
||||
import type { FlatEntryModel } from "~/store/entry"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
import { useFeedById } from "~/store/feed"
|
||||
|
||||
import { ImageGallery } from "./actions/picture-gallery"
|
||||
import { useEntryContentScrollToTop, useEntryTitleMeta } from "./atoms"
|
||||
import { EntryReadHistory } from "./components/EntryReadHistory"
|
||||
|
||||
@@ -62,7 +65,7 @@ function EntryHeaderImpl({
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex min-w-0 items-center justify-between gap-3 overflow-hidden text-lg text-zinc-500 duration-200",
|
||||
"relative flex min-w-0 items-center justify-between gap-3 overflow-hidden text-lg text-zinc-500 duration-200 zen-mode-macos:ml-margin-macos-traffic-light-x",
|
||||
shouldShowMeta && "border-b border-border",
|
||||
className,
|
||||
)}
|
||||
@@ -70,7 +73,7 @@ function EntryHeaderImpl({
|
||||
{!hideRecentReader && (
|
||||
<div
|
||||
className={cn(
|
||||
"absolute left-5 top-0 flex h-full items-center gap-2 text-[13px] leading-none text-zinc-500",
|
||||
"absolute left-5 top-0 flex h-full items-center gap-2 text-[13px] leading-none text-zinc-500 zen-mode-macos:left-12",
|
||||
"visible z-[11]",
|
||||
views[view].wideMode && "static",
|
||||
shouldShowMeta && "hidden",
|
||||
@@ -102,6 +105,7 @@ function EntryHeaderImpl({
|
||||
<div className="relative flex shrink-0 items-center justify-end gap-3">
|
||||
{!compact && <ElectronAdditionActions view={view} entry={entry} key={entry.entries.id} />}
|
||||
|
||||
<SpecialActions id={entry.entries.id} />
|
||||
{items
|
||||
.filter((item) => !item.hide)
|
||||
.map((item) => (
|
||||
@@ -228,3 +232,26 @@ const ElectronAdditionActions = IN_ELECTRON
|
||||
: noop
|
||||
|
||||
export const EntryHeader = memo(EntryHeaderImpl)
|
||||
|
||||
const SpecialActions = ({ id }: { id: string }) => {
|
||||
const images = useEntry(id, (entry) => entry.entries.media)
|
||||
const { present } = useModalStack()
|
||||
const filteredImages = filterSmallMedia(images)
|
||||
if (filteredImages?.length && filteredImages.length > 5) {
|
||||
return (
|
||||
<ActionButton
|
||||
onClick={() => {
|
||||
window.analytics?.capture("entry_content_header_image_gallery_click")
|
||||
present({
|
||||
title: "Image Gallery",
|
||||
content: () => <ImageGallery images={filteredImages as any as MediaModel[]} />,
|
||||
max: true,
|
||||
})
|
||||
}}
|
||||
icon={<i className="i-mgc-pic-cute-fi" />}
|
||||
tooltip={`Image Gallery`}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { useTitle } from "@follow/hooks"
|
||||
import type { FeedModel, InboxModel } from "@follow/models/types"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { clearSelection, stopPropagation } from "@follow/utils/dom"
|
||||
import { EventBus } from "@follow/utils/event-bus"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import type { FallbackRender } from "@sentry/react"
|
||||
@@ -210,6 +210,7 @@ export const EntryContentRender: Component<{
|
||||
ref={scrollerRef}
|
||||
>
|
||||
<div
|
||||
onPointerDown={clearSelection}
|
||||
style={stableRenderStyle}
|
||||
className="duration-200 ease-in-out animate-in fade-in slide-in-from-bottom-24 f-motion-reduce:fade-in-0 f-motion-reduce:slide-in-from-bottom-0"
|
||||
key={entry.entries.id}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { Trans, useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { createErrorToaster } from "~/lib/error-parser"
|
||||
import { subscriptionActions } from "~/store/subscription"
|
||||
|
||||
import { useCurrentModal } from "../../components/ui/modal/stacked/hooks"
|
||||
@@ -10,6 +12,10 @@ export function CategoryRemoveDialogContent({ feedIdList }: { feedIdList: string
|
||||
const { t } = useTranslation()
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: () => subscriptionActions.deleteCategory(feedIdList),
|
||||
onError: createErrorToaster(t("sidebar.category_remove_dialog.error")),
|
||||
onSuccess: () => {
|
||||
toast.success(t("sidebar.category_remove_dialog.success"))
|
||||
},
|
||||
})
|
||||
|
||||
const { dismiss } = useCurrentModal()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useDroppable } from "@dnd-kit/core"
|
||||
import { MotionButtonBase } from "@follow/components/ui/button/index.js"
|
||||
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
|
||||
import { useScrollViewElement } from "@follow/components/ui/scroll-area/hooks.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
import { useAnyPointDown, useInputComposition, useRefValue } from "@follow/hooks"
|
||||
import { useInputComposition, useRefValue } from "@follow/hooks"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { cn, sortByAlphabet } from "@follow/utils/utils"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
@@ -11,15 +12,17 @@ import { AnimatePresence, m } from "framer-motion"
|
||||
import type { FC } from "react"
|
||||
import { Fragment, memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
import { useOnClickOutside } from "usehooks-ts"
|
||||
|
||||
import type { MenuItemInput } from "~/atoms/context-menu"
|
||||
import { useShowContextMenu } from "~/atoms/context-menu"
|
||||
import { ROUTE_FEED_IN_FOLDER } from "~/constants"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { getRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import type { NullableNativeMenuItem } from "~/lib/native-menu"
|
||||
import { showNativeMenu } from "~/lib/native-menu"
|
||||
import { createErrorToaster } from "~/lib/error-parser"
|
||||
import { getPreferredTitle, useAddFeedToFeedList, useFeedStore } from "~/store/feed"
|
||||
import { useOwnedList } from "~/store/list"
|
||||
import { useOwnedListByView } from "~/store/list"
|
||||
import {
|
||||
subscriptionActions,
|
||||
subscriptionCategoryExist,
|
||||
@@ -144,22 +147,33 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
const [isCategoryEditing, setIsCategoryEditing] = useState(false)
|
||||
|
||||
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
||||
useAnyPointDown(() => {
|
||||
isContextMenuOpen && setIsContextMenuOpen(false)
|
||||
})
|
||||
const isCategoryIsWaiting = isChangePending
|
||||
|
||||
const addMutation = useAddFeedToFeedList()
|
||||
|
||||
const listList = useOwnedList(view!)
|
||||
const listList = useOwnedListByView(view!)
|
||||
const showContextMenu = useShowContextMenu()
|
||||
|
||||
const isAutoGroupedCategory = !!folderName && !subscriptionCategoryExist(folderName)
|
||||
|
||||
const { isOver, setNodeRef } = useDroppable({
|
||||
id: `category-${folderName}`,
|
||||
disabled: isAutoGroupedCategory,
|
||||
data: {
|
||||
category: folderName,
|
||||
view,
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<div tabIndex={-1} onClick={stopPropagation}>
|
||||
{!!showCollapse && (
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
data-active={isActive || isContextMenuOpen}
|
||||
className={cn(
|
||||
"my-px flex w-full cursor-menu items-center justify-between rounded-md px-2.5",
|
||||
isOver && "border-theme-accent-400 bg-theme-accent-400/60",
|
||||
feedColumnStyles.item,
|
||||
)}
|
||||
onClick={(e) => {
|
||||
@@ -168,10 +182,10 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
setCategoryActive()
|
||||
}
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
onContextMenu={async (e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
|
||||
showNativeMenu(
|
||||
await showContextMenu(
|
||||
[
|
||||
{
|
||||
type: "text",
|
||||
@@ -199,7 +213,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
listId: list.id,
|
||||
})
|
||||
},
|
||||
}) as NullableNativeMenuItem,
|
||||
}) as MenuItemInput,
|
||||
)
|
||||
.concat(listList?.length > 0 ? [{ type: "separator" as const }] : [])
|
||||
.concat([
|
||||
@@ -242,7 +256,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
{
|
||||
type: "text",
|
||||
label: t("sidebar.feed_column.context_menu.delete_category"),
|
||||
hide: !folderName || !subscriptionCategoryExist(folderName),
|
||||
hide: !folderName || isAutoGroupedCategory,
|
||||
click: () => {
|
||||
present({
|
||||
title: t("sidebar.feed_column.context_menu.delete_category_confirmation", {
|
||||
@@ -255,6 +269,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
],
|
||||
e,
|
||||
)
|
||||
setIsContextMenuOpen(false)
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full min-w-0 items-center" onDoubleClick={toggleCategoryOpenState}>
|
||||
@@ -303,7 +318,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
{open && (
|
||||
<m.div
|
||||
ref={itemsRef}
|
||||
className="space-y-px overflow-hidden"
|
||||
className="space-y-px"
|
||||
initial={
|
||||
!!showCollapse && {
|
||||
height: 0,
|
||||
@@ -338,6 +353,7 @@ const RenameCategoryForm: FC<{
|
||||
onFinished: () => void
|
||||
}> = ({ currentCategory, onFinished }) => {
|
||||
const navigate = useNavigateEntry()
|
||||
const { t } = useTranslation()
|
||||
const renameMutation = useMutation({
|
||||
mutationFn: async ({
|
||||
lastCategory,
|
||||
@@ -357,6 +373,10 @@ const RenameCategoryForm: FC<{
|
||||
|
||||
onFinished()
|
||||
},
|
||||
onError: createErrorToaster(t("sidebar.feed_column.context_menu.rename_category_error")),
|
||||
onSuccess: () => {
|
||||
toast.success(t("sidebar.feed_column.context_menu.rename_category_success"))
|
||||
},
|
||||
})
|
||||
const formRef = useRef<HTMLFormElement>(null)
|
||||
useOnClickOutside(
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { DraggableAttributes, DraggableSyntheticListeners } from "@dnd-kit/core"
|
||||
import type { CSSProperties } from "react"
|
||||
import { createContext } from "react"
|
||||
|
||||
export const DraggableContext = createContext<{
|
||||
attributes: DraggableAttributes
|
||||
listeners: DraggableSyntheticListeners
|
||||
style?: CSSProperties | undefined
|
||||
} | null>(null)
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { MdiMeditation } from "@follow/components/icons/Meditation.js"
|
||||
import { ActionButton } from "@follow/components/ui/button/index.js"
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@follow/components/ui/popover/index.jsx"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
@@ -13,6 +14,7 @@ import { toast } from "sonner"
|
||||
|
||||
import { setAppSearchOpen } from "~/atoms/app"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useIsZenMode, useSetZenMode } from "~/atoms/settings/ui"
|
||||
import { setFeedColumnShow, useFeedColumnShow, useSidebarActiveView } from "~/atoms/sidebar"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useI18n } from "~/hooks/common"
|
||||
@@ -81,7 +83,8 @@ const LayoutActionButton = () => {
|
||||
const [animation, setAnimation] = useState({
|
||||
width: !feedColumnShow ? "auto" : 0,
|
||||
})
|
||||
|
||||
const isZenMode = useIsZenMode()
|
||||
const setIsZenMode = useSetZenMode()
|
||||
useEffect(() => {
|
||||
setAnimation({
|
||||
width: !feedColumnShow ? "auto" : 0,
|
||||
@@ -95,18 +98,28 @@ const LayoutActionButton = () => {
|
||||
return (
|
||||
<m.div initial={animation} animate={animation} className="overflow-hidden">
|
||||
<ActionButton
|
||||
tooltip={t("app.toggle_sidebar")}
|
||||
tooltip={isZenMode ? t("zen.exit") : t("app.toggle_sidebar")}
|
||||
icon={
|
||||
<i
|
||||
className={cn(
|
||||
!feedColumnShow
|
||||
? "i-mgc-layout-leftbar-open-cute-re "
|
||||
: "i-mgc-layout-leftbar-close-cute-re",
|
||||
"text-theme-vibrancyFg",
|
||||
)}
|
||||
/>
|
||||
isZenMode ? (
|
||||
<MdiMeditation />
|
||||
) : (
|
||||
<i
|
||||
className={cn(
|
||||
!feedColumnShow
|
||||
? "i-mgc-layout-leftbar-open-cute-re "
|
||||
: "i-mgc-layout-leftbar-close-cute-re",
|
||||
"text-theme-vibrancyFg",
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
onClick={() => setFeedColumnShow(!feedColumnShow)}
|
||||
onClick={() => {
|
||||
if (isZenMode) {
|
||||
setIsZenMode(false)
|
||||
} else {
|
||||
setFeedColumnShow(!feedColumnShow)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</m.div>
|
||||
)
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { DndContext, pointerWithin, useDroppable } from "@dnd-kit/core"
|
||||
import { ActionButton } from "@follow/components/ui/button/index.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { Routes, views } from "@follow/constants"
|
||||
import { useTypeScriptHappyCallback } from "@follow/hooks"
|
||||
import { useSubscribeElectronEvent } from "@follow/shared/event"
|
||||
import { useRegisterGlobalContext } from "@follow/shared/bridge"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { clamp, cn } from "@follow/utils/utils"
|
||||
import { useWheel } from "@use-gesture/react"
|
||||
import { AnimatePresence, m } from "framer-motion"
|
||||
import { Lethargy } from "lethargy"
|
||||
import type { FC, PropsWithChildren } from "react"
|
||||
import { useCallback, useLayoutEffect, useRef, useState } from "react"
|
||||
import { startTransition, useCallback, useLayoutEffect, useRef, useState } from "react"
|
||||
import { isHotkeyPressed, useHotkeys } from "react-hotkeys-hook"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
@@ -19,13 +21,14 @@ import { shortcuts } from "~/constants/shortcuts"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useBatchUpdateSubscription } from "~/hooks/biz/useSubscriptionActions"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { Queries } from "~/queries"
|
||||
import { useSubscriptionStore } from "~/store/subscription"
|
||||
import { useFeedUnreadStore } from "~/store/unread"
|
||||
|
||||
import { WindowUnderBlur } from "../../components/ui/background"
|
||||
import { getSelectedFeedIds, setSelectedFeedIds } from "./atom"
|
||||
import { getSelectedFeedIds, setSelectedFeedIds, useSelectedFeedIds } from "./atom"
|
||||
import { FeedColumnHeader } from "./header"
|
||||
import { FeedList } from "./list"
|
||||
|
||||
@@ -87,27 +90,6 @@ export function FeedColumn({ children, className }: PropsWithChildren<{ classNam
|
||||
}
|
||||
}, [setActive_])
|
||||
|
||||
const [useHotkeysSwitch, setUseHotkeysSwitch] = useState<boolean>(false)
|
||||
useHotkeys(
|
||||
shortcuts.feeds.switchBetweenViews.key,
|
||||
(e) => {
|
||||
e.preventDefault()
|
||||
setUseHotkeysSwitch(true)
|
||||
if (isHotkeyPressed("Left")) {
|
||||
setActive((i) => {
|
||||
if (i === 0) {
|
||||
return views.length - 1
|
||||
} else {
|
||||
return i - 1
|
||||
}
|
||||
})
|
||||
} else {
|
||||
setActive((i) => (i + 1) % views.length)
|
||||
}
|
||||
},
|
||||
{ scopes: HotKeyScopeMap.Home },
|
||||
)
|
||||
|
||||
useWheel(
|
||||
({ event, last, memo: wait = false, direction: [dx], delta: [dex] }) => {
|
||||
if (!last) {
|
||||
@@ -131,88 +113,157 @@ export function FeedColumn({ children, className }: PropsWithChildren<{ classNam
|
||||
},
|
||||
)
|
||||
|
||||
const unreadByView = useUnreadByView()
|
||||
const { t } = useTranslation()
|
||||
const [useHotkeysSwitch, setUseHotkeysSwitch] = useState<boolean>(false)
|
||||
useHotkeys(
|
||||
shortcuts.feeds.switchBetweenViews.key,
|
||||
(e) => {
|
||||
e.preventDefault()
|
||||
setUseHotkeysSwitch(true)
|
||||
if (isHotkeyPressed("Left")) {
|
||||
setActive((i) => {
|
||||
if (i === 0) {
|
||||
return views.length - 1
|
||||
} else {
|
||||
return i - 1
|
||||
}
|
||||
})
|
||||
} else {
|
||||
setActive((i) => (i + 1) % views.length)
|
||||
}
|
||||
},
|
||||
{ scopes: HotKeyScopeMap.Home },
|
||||
)
|
||||
|
||||
const showSidebarUnreadCount = useUISettingKey("sidebarShowUnreadCount")
|
||||
|
||||
useSubscribeElectronEvent("Discover", () => {
|
||||
useRegisterGlobalContext("goToDiscover", () => {
|
||||
window.router.navigate(Routes.Discover)
|
||||
})
|
||||
|
||||
const [selectedIds, setSelectedIds] = useSelectedFeedIds()
|
||||
|
||||
const { mutate } = useBatchUpdateSubscription()
|
||||
|
||||
return (
|
||||
<WindowUnderBlur
|
||||
className={cn("relative flex h-full flex-col space-y-3 pt-2.5", className)}
|
||||
onClick={useCallback(() => navigateBackHome(), [navigateBackHome])}
|
||||
<DndContext
|
||||
collisionDetection={pointerWithin}
|
||||
onDragEnd={(event) => {
|
||||
if (!event.over) {
|
||||
return
|
||||
}
|
||||
|
||||
const { category, view } = event.over.data.current as {
|
||||
category: string
|
||||
view: FeedViewType
|
||||
}
|
||||
|
||||
mutate({ category, view, feedIdList: selectedIds })
|
||||
|
||||
setSelectedIds([])
|
||||
}}
|
||||
>
|
||||
<FeedColumnHeader />
|
||||
<WindowUnderBlur
|
||||
className={cn("relative flex h-full flex-col space-y-3 pt-2.5", className)}
|
||||
onClick={useCallback(() => navigateBackHome(), [navigateBackHome])}
|
||||
>
|
||||
<FeedColumnHeader />
|
||||
|
||||
<div
|
||||
className="flex w-full justify-between px-3 text-xl text-theme-vibrancyFg"
|
||||
onClick={stopPropagation}
|
||||
>
|
||||
{views.map((item, index) => (
|
||||
<ActionButton
|
||||
key={item.name}
|
||||
tooltip={t(item.name)}
|
||||
shortcut={`${index + 1}`}
|
||||
className={cn(
|
||||
active === index && item.className,
|
||||
"flex h-11 flex-col items-center gap-1 text-xl",
|
||||
ELECTRON ? "hover:!bg-theme-item-hover" : "",
|
||||
active === index && useHotkeysSwitch ? "bg-theme-item-active" : "",
|
||||
)}
|
||||
onClick={(e) => {
|
||||
setActive(index)
|
||||
setUseHotkeysSwitch(false)
|
||||
e.stopPropagation()
|
||||
}}
|
||||
>
|
||||
{item.icon}
|
||||
{showSidebarUnreadCount ? (
|
||||
<div className="text-[0.625rem] font-medium leading-none">
|
||||
{unreadByView[index] > 99 ? (
|
||||
<span className="-mr-0.5">99+</span>
|
||||
) : (
|
||||
unreadByView[index]
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<i
|
||||
className={cn(
|
||||
"i-mgc-round-cute-fi text-[0.25rem]",
|
||||
unreadByView[index]
|
||||
? active === index
|
||||
? "opacity-100"
|
||||
: "opacity-60"
|
||||
: "opacity-0",
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</ActionButton>
|
||||
))}
|
||||
</div>
|
||||
<div
|
||||
className="relative flex size-full overflow-hidden"
|
||||
ref={carouselRef}
|
||||
onPointerDown={useTypeScriptHappyCallback((e) => {
|
||||
if (!(e.target instanceof HTMLElement) || !e.target.closest("[data-feed-id]")) {
|
||||
const nextSelectedFeedIds = getSelectedFeedIds()
|
||||
setSelectedFeedIds(nextSelectedFeedIds.length === 0 ? nextSelectedFeedIds : [])
|
||||
}
|
||||
}, [])}
|
||||
>
|
||||
<SwipeWrapper active={active}>
|
||||
<div
|
||||
className="flex w-full justify-between px-3 text-xl text-theme-vibrancyFg"
|
||||
onClick={stopPropagation}
|
||||
>
|
||||
{views.map((item, index) => (
|
||||
<section key={item.name} className="h-full w-feed-col shrink-0 snap-center">
|
||||
<FeedList className="flex size-full flex-col text-sm" view={index} />
|
||||
</section>
|
||||
<ViewSwitchButton
|
||||
key={item.name}
|
||||
item={item}
|
||||
index={index}
|
||||
active={active}
|
||||
setActive={setActive}
|
||||
useHotkeysSwitch={useHotkeysSwitch}
|
||||
setUseHotkeysSwitch={setUseHotkeysSwitch}
|
||||
/>
|
||||
))}
|
||||
</SwipeWrapper>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="relative flex size-full"
|
||||
ref={carouselRef}
|
||||
onPointerDown={useTypeScriptHappyCallback((e) => {
|
||||
if (!(e.target instanceof HTMLElement) || !e.target.closest("[data-feed-id]")) {
|
||||
const nextSelectedFeedIds = getSelectedFeedIds()
|
||||
setSelectedFeedIds(nextSelectedFeedIds.length === 0 ? nextSelectedFeedIds : [])
|
||||
}
|
||||
}, [])}
|
||||
>
|
||||
<SwipeWrapper active={active}>
|
||||
{views.map((item, index) => (
|
||||
<section key={item.name} className="h-full w-feed-col shrink-0 snap-center">
|
||||
<FeedList className="flex size-full flex-col text-sm" view={index} />
|
||||
</section>
|
||||
))}
|
||||
</SwipeWrapper>
|
||||
</div>
|
||||
|
||||
{children}
|
||||
</WindowUnderBlur>
|
||||
{children}
|
||||
</WindowUnderBlur>
|
||||
</DndContext>
|
||||
)
|
||||
}
|
||||
|
||||
const ViewSwitchButton: FC<{
|
||||
item: (typeof views)[number]
|
||||
index: number
|
||||
|
||||
active: number
|
||||
setActive: (next: number | ((prev: number) => number)) => void
|
||||
|
||||
useHotkeysSwitch: boolean
|
||||
setUseHotkeysSwitch: (next: boolean) => void
|
||||
}> = ({ item, index, active, setActive, useHotkeysSwitch, setUseHotkeysSwitch }) => {
|
||||
const unreadByView = useUnreadByView()
|
||||
const { t } = useTranslation()
|
||||
const showSidebarUnreadCount = useUISettingKey("sidebarShowUnreadCount")
|
||||
|
||||
const { isOver, setNodeRef } = useDroppable({
|
||||
id: `view-${item.name}`,
|
||||
data: {
|
||||
category: "",
|
||||
view: item.view,
|
||||
},
|
||||
})
|
||||
|
||||
return (
|
||||
<ActionButton
|
||||
ref={setNodeRef}
|
||||
key={item.name}
|
||||
tooltip={t(item.name)}
|
||||
shortcut={`${index + 1}`}
|
||||
className={cn(
|
||||
active === index && item.className,
|
||||
"flex h-11 flex-col items-center gap-1 text-xl",
|
||||
ELECTRON ? "hover:!bg-theme-item-hover" : "",
|
||||
active === index && useHotkeysSwitch ? "bg-theme-item-active" : "",
|
||||
isOver && "border-theme-accent-400 bg-theme-accent-400/60",
|
||||
)}
|
||||
onClick={(e) => {
|
||||
startTransition(() => {
|
||||
setActive(index)
|
||||
setUseHotkeysSwitch(false)
|
||||
})
|
||||
e.stopPropagation()
|
||||
}}
|
||||
>
|
||||
{item.icon}
|
||||
{showSidebarUnreadCount ? (
|
||||
<div className="text-[0.625rem] font-medium leading-none">
|
||||
{unreadByView[index] > 99 ? <span className="-mr-0.5">99+</span> : unreadByView[index]}
|
||||
</div>
|
||||
) : (
|
||||
<i
|
||||
className={cn(
|
||||
"i-mgc-round-cute-fi text-[0.25rem]",
|
||||
unreadByView[index] ? (active === index ? "opacity-100" : "opacity-60") : "opacity-0",
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</ActionButton>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,20 +7,19 @@ import {
|
||||
} from "@follow/components/ui/tooltip/index.jsx"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { useAnyPointDown } from "@follow/hooks"
|
||||
import { nextFrame } from "@follow/utils/dom"
|
||||
import { UrlBuilder } from "@follow/utils/url-builder"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import dayjs from "dayjs"
|
||||
import { memo, useCallback, useState } from "react"
|
||||
import { memo, useCallback, useContext, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useShowContextMenu } from "~/atoms/context-menu"
|
||||
import { getMainContainerElement } from "~/atoms/dom"
|
||||
import { useFeedActions, useInboxActions, useListActions } from "~/hooks/biz/useFeedActions"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { getNewIssueUrl } from "~/lib/issues"
|
||||
import { showNativeMenu } from "~/lib/native-menu"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
import { getPreferredTitle, useFeedById } from "~/store/feed"
|
||||
@@ -30,6 +29,7 @@ import { subscriptionActions, useSubscriptionByFeedId } from "~/store/subscripti
|
||||
import { useFeedUnreadStore } from "~/store/unread"
|
||||
|
||||
import { useSelectedFeedIds } from "./atom"
|
||||
import { DraggableContext } from "./context"
|
||||
import { feedColumnStyles } from "./styles"
|
||||
import { UnreadNumber } from "./unread-number"
|
||||
|
||||
@@ -52,10 +52,14 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
url: feed.url,
|
||||
image: feed.image,
|
||||
siteUrl: feed.siteUrl,
|
||||
ownerUserId: feed.ownerUserId,
|
||||
owner: feed.owner,
|
||||
}
|
||||
})
|
||||
|
||||
const [selectedFeedIds, setSelectedFeedIds] = useSelectedFeedIds()
|
||||
const draggableContext = useContext(DraggableContext)
|
||||
const isInMultipleSelection = selectedFeedIds.includes(feedId)
|
||||
|
||||
const handleClick: React.MouseEventHandler<HTMLDivElement> = useCallback(
|
||||
(e) => {
|
||||
@@ -91,9 +95,7 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
})
|
||||
|
||||
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
||||
useAnyPointDown(() => {
|
||||
isContextMenuOpen && setIsContextMenuOpen(false)
|
||||
})
|
||||
const showContextMenu = useShowContextMenu()
|
||||
if (!feed) return null
|
||||
|
||||
const isFeed = feed.type === "feed" || !feed.type
|
||||
@@ -101,8 +103,15 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
{...(isInMultipleSelection && draggableContext?.attributes
|
||||
? draggableContext.attributes
|
||||
: {})}
|
||||
{...(isInMultipleSelection && draggableContext?.listeners
|
||||
? draggableContext.listeners
|
||||
: {})}
|
||||
style={isInMultipleSelection ? draggableContext?.style : undefined}
|
||||
data-feed-id={feedId}
|
||||
data-active={isActive || isContextMenuOpen || selectedFeedIds.includes(feedId)}
|
||||
data-active={isActive || isContextMenuOpen || isInMultipleSelection}
|
||||
className={cn(
|
||||
"flex w-full cursor-menu items-center justify-between rounded-md py-[2px] pr-2.5 text-sm font-medium leading-loose",
|
||||
feedColumnStyles.item,
|
||||
@@ -113,8 +122,7 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
onDoubleClick={() => {
|
||||
window.open(UrlBuilder.shareFeed(feedId, view), "_blank")
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
onContextMenu={async (e) => {
|
||||
const nextItems = items.concat()
|
||||
if (isFeed && feed.errorAt && feed.errorMessage) {
|
||||
nextItems.push(
|
||||
@@ -139,7 +147,8 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
},
|
||||
)
|
||||
}
|
||||
showNativeMenu(
|
||||
setIsContextMenuOpen(true)
|
||||
await showContextMenu(
|
||||
nextItems.filter(
|
||||
(item) =>
|
||||
selectedFeedIds.length === 0 ||
|
||||
@@ -150,6 +159,7 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
),
|
||||
e,
|
||||
)
|
||||
setIsContextMenuOpen(false)
|
||||
}}
|
||||
>
|
||||
<div
|
||||
@@ -216,9 +226,6 @@ const ListItemImpl: Component<{
|
||||
const listUnread = useFeedUnreadStore((state) => state.data[listId] || 0)
|
||||
|
||||
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
||||
useAnyPointDown(() => {
|
||||
isContextMenuOpen && setIsContextMenuOpen(false)
|
||||
})
|
||||
const subscription = useSubscriptionByFeedId(listId)
|
||||
const navigate = useNavigateEntry()
|
||||
const handleNavigate = useCallback(
|
||||
@@ -240,6 +247,7 @@ const ListItemImpl: Component<{
|
||||
},
|
||||
[listId, navigate, view],
|
||||
)
|
||||
const showContextMenu = useShowContextMenu()
|
||||
const { t } = useTranslation()
|
||||
if (!list) return null
|
||||
return (
|
||||
@@ -256,10 +264,10 @@ const ListItemImpl: Component<{
|
||||
onDoubleClick={() => {
|
||||
window.open(UrlBuilder.shareList(listId, view), "_blank")
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
onContextMenu={async (e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
|
||||
showNativeMenu(items, e)
|
||||
await showContextMenu(items, e)
|
||||
setIsContextMenuOpen(false)
|
||||
}}
|
||||
>
|
||||
<div className={"flex min-w-0 items-center"}>
|
||||
@@ -299,9 +307,6 @@ const InboxItemImpl: Component<{
|
||||
const inboxUnread = useFeedUnreadStore((state) => state.data[inboxId] || 0)
|
||||
|
||||
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
|
||||
useAnyPointDown(() => {
|
||||
isContextMenuOpen && setIsContextMenuOpen(false)
|
||||
})
|
||||
const navigate = useNavigateEntry()
|
||||
const handleNavigate = useCallback(
|
||||
(e: React.MouseEvent<HTMLDivElement>) => {
|
||||
@@ -315,6 +320,8 @@ const InboxItemImpl: Component<{
|
||||
},
|
||||
[inboxId, navigate, view],
|
||||
)
|
||||
const showContextMenu = useShowContextMenu()
|
||||
|
||||
if (!inbox) return null
|
||||
return (
|
||||
<div
|
||||
@@ -327,9 +334,10 @@ const InboxItemImpl: Component<{
|
||||
className,
|
||||
)}
|
||||
onClick={handleNavigate}
|
||||
onContextMenu={(e) => {
|
||||
onContextMenu={async (e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
showNativeMenu(items, e)
|
||||
await showContextMenu(items, e)
|
||||
setIsContextMenuOpen(false)
|
||||
}}
|
||||
>
|
||||
<div className={"flex min-w-0 items-center"}>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useDraggable } from "@dnd-kit/core"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
import { views } from "@follow/constants"
|
||||
@@ -28,8 +29,9 @@ import {
|
||||
setFeedListSortBy,
|
||||
setFeedListSortOrder,
|
||||
useFeedListSort,
|
||||
useSetSelectedFeedIds,
|
||||
useSelectedFeedIds,
|
||||
} from "./atom"
|
||||
import { DraggableContext } from "./context"
|
||||
import { SortableFeedList, SortByAlphabeticalInbox, SortByAlphabeticalList } from "./sort-by"
|
||||
import { feedColumnStyles } from "./styles"
|
||||
import { UnreadNumber } from "./unread-number"
|
||||
@@ -110,19 +112,6 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
|
||||
const listsData = useListsGroupedData(view)
|
||||
const inboxesData = useInboxesGroupedData(view)
|
||||
const categoryOpenStateData = useCategoryOpenStateByView(view)
|
||||
const expansion = Object.values(categoryOpenStateData).every((value) => value === true)
|
||||
useUpdateUnreadCount()
|
||||
|
||||
const totalUnread = useFeedUnreadStore((state) => {
|
||||
let unread = 0
|
||||
|
||||
for (const category in feedsData) {
|
||||
for (const feedId of feedsData[category]) {
|
||||
unread += state.data[feedId] || 0
|
||||
}
|
||||
}
|
||||
return unread
|
||||
})
|
||||
|
||||
const hasData =
|
||||
Object.keys(feedsData).length > 0 ||
|
||||
@@ -142,48 +131,45 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
|
||||
|
||||
const scrollerRef = useRef<HTMLDivElement>(null)
|
||||
const selectoRef = useRef<Selecto>(null)
|
||||
const setSelectedFeedIds = useSetSelectedFeedIds()
|
||||
const [selectedFeedIds, setSelectedFeedIds] = useSelectedFeedIds()
|
||||
|
||||
const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({
|
||||
id: "selected-feed",
|
||||
disabled: selectedFeedIds.length === 0,
|
||||
})
|
||||
const style = useMemo(
|
||||
() =>
|
||||
transform
|
||||
? ({
|
||||
transform: `translate3d(${transform.x}px, ${transform.y}px, 0)`,
|
||||
transitionDuration: "0",
|
||||
transition: "none",
|
||||
} as React.CSSProperties)
|
||||
: undefined,
|
||||
[transform],
|
||||
)
|
||||
|
||||
const draggableContextValue = useMemo(
|
||||
() => ({
|
||||
attributes,
|
||||
listeners,
|
||||
style: {
|
||||
...style,
|
||||
willChange: "transform",
|
||||
},
|
||||
}),
|
||||
[attributes, listeners, style],
|
||||
)
|
||||
|
||||
return (
|
||||
<div className={cn(className, "font-medium")}>
|
||||
<div onClick={stopPropagation} className="mx-3 flex items-center justify-between px-2.5 py-1">
|
||||
<div
|
||||
className="font-bold"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (!document.hasFocus()) return
|
||||
if (view !== undefined) {
|
||||
navigateEntry({
|
||||
entryId: null,
|
||||
feedId: null,
|
||||
view,
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
{view !== undefined && t(views[view].name)}
|
||||
</div>
|
||||
<div className="ml-2 flex items-center gap-3 text-sm text-theme-vibrancyFg">
|
||||
<SortButton />
|
||||
{expansion ? (
|
||||
<i
|
||||
className="i-mgc-list-collapse-cute-re"
|
||||
onClick={() => subscriptionActions.expandCategoryOpenStateByView(view, false)}
|
||||
/>
|
||||
) : (
|
||||
<i
|
||||
className="i-mgc-list-expansion-cute-re"
|
||||
onClick={() => subscriptionActions.expandCategoryOpenStateByView(view, true)}
|
||||
/>
|
||||
)}
|
||||
<UnreadNumber unread={totalUnread} className="text-xs !text-inherit" />
|
||||
</div>
|
||||
</div>
|
||||
<ListHeader view={view} />
|
||||
<Selecto
|
||||
className="!border-theme-accent-400 !bg-theme-accent-400/60"
|
||||
ref={selectoRef}
|
||||
rootContainer={document.body}
|
||||
dragContainer={"#feeds-area"}
|
||||
dragCondition={() => !(selectedFeedIds.length > 0 && isDragging)}
|
||||
selectableTargets={["[data-feed-id]"]}
|
||||
continueSelect
|
||||
hitRate={10}
|
||||
@@ -221,8 +207,11 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
|
||||
}}
|
||||
mask={false}
|
||||
flex
|
||||
viewportClassName="!px-3"
|
||||
rootClassName="h-full"
|
||||
viewportClassName={cn(
|
||||
"!px-3 [&>[data-radix-scroll-area-content]]:h-full",
|
||||
isDragging && "!overflow-visible",
|
||||
)}
|
||||
rootClassName={cn("h-full", isDragging && "overflow-visible")}
|
||||
>
|
||||
<div
|
||||
data-active={feedId === FEED_COLLECTION_LIST}
|
||||
@@ -261,42 +250,101 @@ function FeedListImpl({ className, view }: { className?: string; view: number })
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="space-y-px" id="feeds-area">
|
||||
{(hasListData || hasInboxData) && (
|
||||
<div
|
||||
className={cn(
|
||||
"mb-1 flex h-6 w-full shrink-0 items-center rounded-md px-2.5 text-xs font-semibold text-theme-vibrancyFg transition-colors",
|
||||
Object.keys(feedsData).length === 0 ? "mt-0" : "mt-1",
|
||||
)}
|
||||
>
|
||||
{t("words.feeds")}
|
||||
</div>
|
||||
)}
|
||||
{hasData ? (
|
||||
<SortableFeedList
|
||||
view={view}
|
||||
data={feedsData}
|
||||
categoryOpenStateData={categoryOpenStateData}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full flex-1 items-center font-normal text-zinc-500">
|
||||
<Link
|
||||
to="/discover"
|
||||
className="absolute inset-0 mt-[-3.75rem] flex h-full flex-1 cursor-menu flex-col items-center justify-center gap-2"
|
||||
onClick={stopPropagation}
|
||||
<DraggableContext.Provider value={draggableContextValue}>
|
||||
<div className="h-full space-y-px" id="feeds-area" ref={setNodeRef}>
|
||||
{(hasListData || hasInboxData) && (
|
||||
<div
|
||||
className={cn(
|
||||
"mb-1 flex h-6 w-full shrink-0 items-center rounded-md px-2.5 text-xs font-semibold text-theme-vibrancyFg transition-colors",
|
||||
Object.keys(feedsData).length === 0 ? "mt-0" : "mt-1",
|
||||
)}
|
||||
>
|
||||
<i className="i-mgc-add-cute-re text-3xl" />
|
||||
<span className="text-base">{t("sidebar.add_more_feeds")}</span>
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{t("words.feeds")}
|
||||
</div>
|
||||
)}
|
||||
{hasData ? (
|
||||
<SortableFeedList
|
||||
view={view}
|
||||
data={feedsData}
|
||||
categoryOpenStateData={categoryOpenStateData}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full flex-1 items-center font-normal text-zinc-500">
|
||||
<Link
|
||||
to="/discover"
|
||||
className="absolute inset-0 mt-[-3.75rem] flex h-full flex-1 cursor-menu flex-col items-center justify-center gap-2"
|
||||
onClick={stopPropagation}
|
||||
>
|
||||
<i className="i-mgc-add-cute-re text-3xl" />
|
||||
<span className="text-base">{t("sidebar.add_more_feeds")}</span>
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DraggableContext.Provider>
|
||||
</ScrollArea.ScrollArea>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const LIST = [
|
||||
const ListHeader = ({ view }: { view: number }) => {
|
||||
const { t } = useTranslation()
|
||||
const feedsData = useFeedsGroupedData(view)
|
||||
const categoryOpenStateData = useCategoryOpenStateByView(view)
|
||||
const expansion = Object.values(categoryOpenStateData).every((value) => value === true)
|
||||
useUpdateUnreadCount()
|
||||
|
||||
const totalUnread = useFeedUnreadStore((state) => {
|
||||
let unread = 0
|
||||
|
||||
for (const category in feedsData) {
|
||||
for (const feedId of feedsData[category]) {
|
||||
unread += state.data[feedId] || 0
|
||||
}
|
||||
}
|
||||
return unread
|
||||
})
|
||||
|
||||
const navigateEntry = useNavigateEntry()
|
||||
|
||||
return (
|
||||
<div onClick={stopPropagation} className="mx-3 flex items-center justify-between px-2.5 py-1">
|
||||
<div
|
||||
className="font-bold"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (!document.hasFocus()) return
|
||||
if (view !== undefined) {
|
||||
navigateEntry({
|
||||
entryId: null,
|
||||
feedId: null,
|
||||
view,
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
{view !== undefined && t(views[view].name)}
|
||||
</div>
|
||||
<div className="ml-2 flex items-center gap-3 text-sm text-theme-vibrancyFg">
|
||||
<SortButton />
|
||||
{expansion ? (
|
||||
<i
|
||||
className="i-mgc-list-collapse-cute-re"
|
||||
onClick={() => subscriptionActions.expandCategoryOpenStateByView(view, false)}
|
||||
/>
|
||||
) : (
|
||||
<i
|
||||
className="i-mgc-list-expansion-cute-re"
|
||||
onClick={() => subscriptionActions.expandCategoryOpenStateByView(view, true)}
|
||||
/>
|
||||
)}
|
||||
<UnreadNumber unread={totalUnread} className="text-xs !text-inherit" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const SORT_LIST = [
|
||||
{ icon: "i-mgc-sort-ascending-cute-re", by: "count", order: "asc" },
|
||||
{ icon: "i-mgc-sort-descending-cute-re", by: "count", order: "desc" },
|
||||
|
||||
@@ -311,6 +359,7 @@ const LIST = [
|
||||
order: "desc",
|
||||
},
|
||||
] as const
|
||||
|
||||
const SortButton = () => {
|
||||
const { by, order } = useFeedListSort()
|
||||
const { t } = useTranslation()
|
||||
@@ -353,7 +402,7 @@ const SortButton = () => {
|
||||
<section className="w-[170px] text-center">
|
||||
<span className="text-[13px]">{t("sidebar.select_sort_method")}</span>
|
||||
<div className="mt-4 grid grid-cols-2 grid-rows-2 gap-2">
|
||||
{LIST.map(({ icon, by, order }) => {
|
||||
{SORT_LIST.map(({ icon, by, order }) => {
|
||||
const current = getFeedListSort()
|
||||
const active = by === current.by && order === current.order
|
||||
return (
|
||||
|
||||
@@ -73,6 +73,10 @@ type FeedIconFeed =
|
||||
| FeedOrListRespModel
|
||||
|
||||
type FeedIconEntry = Pick<CombinedEntryModel["entries"], "media" | "authorAvatar">
|
||||
const fadeInVariant = {
|
||||
initial: { opacity: 0 },
|
||||
animate: { opacity: 1 },
|
||||
}
|
||||
export function FeedIcon({
|
||||
feed,
|
||||
entry,
|
||||
@@ -82,6 +86,7 @@ export function FeedIcon({
|
||||
fallback = true,
|
||||
siteUrl,
|
||||
useMedia,
|
||||
disableFadeIn,
|
||||
}: {
|
||||
feed?: FeedIconFeed | null
|
||||
entry?: FeedIconEntry | null
|
||||
@@ -95,6 +100,7 @@ export function FeedIcon({
|
||||
fallback?: boolean
|
||||
|
||||
useMedia?: boolean
|
||||
disableFadeIn?: boolean
|
||||
}) {
|
||||
const image =
|
||||
(useMedia
|
||||
@@ -122,8 +128,8 @@ export function FeedIcon({
|
||||
const colorfulStyle: React.CSSProperties = useMemo(() => {
|
||||
const [, , , bgAccent, bgAccentLight, bgAccentUltraLight] = colors
|
||||
return {
|
||||
// Create a bottom-left to top-right avatar fallback background gradient
|
||||
backgroundImage: `linear-gradient(to top right, ${bgAccent} 20%, ${bgAccentLight} 80%, ${bgAccentUltraLight} 95%)`,
|
||||
backgroundImage: `linear-gradient(to top, ${bgAccent} 0%, ${bgAccentLight} 99%, ${bgAccentUltraLight} 100%)`,
|
||||
|
||||
...sizeStyle,
|
||||
}
|
||||
}, [colors, sizeStyle])
|
||||
@@ -157,7 +163,7 @@ export function FeedIcon({
|
||||
|
||||
ImageElement = (
|
||||
<PlatformIcon url={siteUrl} style={sizeStyle} className={cn("center mr-2", className)}>
|
||||
<m.img style={sizeStyle} initial={{ opacity: 0 }} animate={{ opacity: 1 }} />
|
||||
<m.img style={sizeStyle} {...(disableFadeIn ? {} : fadeInVariant)} />
|
||||
</PlatformIcon>
|
||||
)
|
||||
break
|
||||
@@ -173,8 +179,7 @@ export function FeedIcon({
|
||||
<m.img
|
||||
className={cn("mr-2", className)}
|
||||
style={sizeStyle}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
{...(disableFadeIn ? {} : fadeInVariant)}
|
||||
/>
|
||||
</PlatformIcon>
|
||||
)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -6,10 +6,12 @@ import { useAuthQuery } from "~/hooks/common"
|
||||
import { Recommendations } from "~/modules/discover/recommendations"
|
||||
import { Queries } from "~/queries"
|
||||
|
||||
export function RSSHubGuide() {
|
||||
export function RSSHubGuide({ categories, lang }: { categories?: string; lang?: string }) {
|
||||
const rsshubPopular = useAuthQuery(
|
||||
Queries.discover.rsshubCategory({
|
||||
category: "popular",
|
||||
categories,
|
||||
lang,
|
||||
}),
|
||||
{
|
||||
meta: {
|
||||
@@ -30,9 +32,13 @@ export function RSSHubGuide() {
|
||||
|
||||
return (
|
||||
<AppErrorBoundary errorType={ErrorComponentType.RSSHubDiscoverError}>
|
||||
<ScrollArea.ScrollArea viewportClassName="h-[450px]">
|
||||
<ScrollArea.ScrollArea
|
||||
viewportClassName="h-[450px]"
|
||||
scrollbarClassName="-mr-4"
|
||||
rootClassName="overflow-visible"
|
||||
>
|
||||
<div className="space-y-3">
|
||||
<Recommendations hideTitle className="grid-cols-4" />
|
||||
<Recommendations hideTitle headerClassName="sticky top-0" />
|
||||
</div>
|
||||
</ScrollArea.ScrollArea>
|
||||
</AppErrorBoundary>
|
||||
|
||||
@@ -19,6 +19,8 @@ const CmdFImpl: FC<{
|
||||
onClose: () => void
|
||||
}> = ({ onClose }) => {
|
||||
const [value, setValue] = useState("")
|
||||
const [activeMatchOrdinal, setActiveMatchOrdinal] = useState(0)
|
||||
const [matches, setMatches] = useState(0)
|
||||
|
||||
const currentValue = useRefValue(value)
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
@@ -88,6 +90,10 @@ const CmdFImpl: FC<{
|
||||
forward: dir === "forward",
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
setMatches(result?.matches || 0)
|
||||
setActiveMatchOrdinal(result?.activeMatchOrdinal || 0)
|
||||
})
|
||||
.finally(() => {
|
||||
if (searchId === searchIdRef.current) {
|
||||
setIsSearching(false)
|
||||
@@ -148,6 +154,11 @@ const CmdFImpl: FC<{
|
||||
/>
|
||||
</div>
|
||||
<div className="center gap-1 [&>*]:opacity-80">
|
||||
{!!value && matches > 0 && activeMatchOrdinal > 0 && (
|
||||
<span>
|
||||
{activeMatchOrdinal}/{matches}
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="center hover:opacity-90"
|
||||
|
||||
@@ -377,14 +377,14 @@ const SearchOptions: Component = memo(({ children }) => {
|
||||
value={`${SearchType.Entry}`}
|
||||
disabled={searchType === SearchType.Entry}
|
||||
>
|
||||
{t("search.options.entries")}
|
||||
{t("search.options.entry")}
|
||||
</SelectItem>
|
||||
<SelectItem
|
||||
className="hover:bg-theme-item-hover"
|
||||
value={`${SearchType.Feed}`}
|
||||
disabled={searchType === SearchType.Feed}
|
||||
>
|
||||
{t("search.options.feeds")}
|
||||
{t("search.options.feed")}
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user