Skip to content

Commit

Permalink
Merge pull request #10852 from notbakaneko/update-ziggy
Browse files Browse the repository at this point in the history
Update ziggy
  • Loading branch information
nanaya authored Jan 11, 2024
2 parents 459ef4a + f3b455f commit 8d4c947
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"paypal/paypal-checkout-sdk": "*",
"sentry/sentry-laravel": "*",
"symfony/yaml": "*",
"tightenco/ziggy": ">=0.8.1",
"tightenco/ziggy": "^1.8",
"xsolla/xsolla-sdk-php": "dev-php81"
},
"require-dev": {
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"webpack-cli": "^5.1.4",
"webpack-manifest-plugin": "^5.0.0",
"webpack-sentry-plugin": "^2.0.2",
"yargs": "^12.0.5"
"yargs": "^12.0.5",
"ziggy-js": "^1.8.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.6.0",
Expand Down
4 changes: 2 additions & 2 deletions resources/js/beatmap-discussions/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export default class Post extends React.Component<Props> {

private deleteHref(op: 'destroy' | 'restore') {
const [controller, key] = this.props.type === 'reply'
? ['beatmapsets.discussions.posts', 'post']
: ['beatmapsets.discussions', 'discussion'];
? ['beatmapsets.discussions.posts', 'post'] as const
: ['beatmapsets.discussions', 'discussion'] as const;

return route(`${controller}.${op}`, { [key]: this.deleteModel.id });
}
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/quick-search-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface State {

@observer export default class QuickSearchButton extends React.Component<Props, State> {
formRef = React.createRef<QuickSearch>();
searchPath = route('search', null, false);
searchPath = route('search', undefined, false);
state: State = { open: false };

private get isSearchPage() {
Expand All @@ -36,7 +36,7 @@ interface State {
render() {
let className = 'nav2__menu-link-main nav2__menu-link-main--search';

if (this.state.open || currentUrl().pathname === route('search', null, false)) {
if (this.state.open || currentUrl().pathname === route('search', undefined, false)) {
className += ' u-section--bg-normal';
}

Expand Down
9 changes: 6 additions & 3 deletions resources/js/laroute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

import { currentUrl } from 'utils/turbolinks';
import { Ziggy } from 'ziggy';
import ziggyRoute from 'ziggy-route';
import ziggyRoute, { RouteList } from 'ziggy-js';

// ensure correct url
const siteUrl = currentUrl();
Ziggy.port = +siteUrl.port || null; // either port number or null if empty (converted to 0)
Ziggy.url = siteUrl.origin;

export function route(name: string, params?: Partial<Record<string, string | number | null>> | null, absolute?: boolean) {
return ziggyRoute(name, params ?? {}, absolute, Ziggy).toString();
type RouteName = keyof RouteList;
type Params<T extends RouteName> = Parameters<typeof ziggyRoute<T>>[1];

export function route<T extends RouteName>(name: T, params?: Params<T>, absolute?: boolean) {
return ziggyRoute<T>(name, params, absolute, Ziggy);
}
2 changes: 1 addition & 1 deletion resources/js/profile-page/cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { trans } from 'utils/lang';

interface Props {
coverUrl: string | null;
currentMode: GameMode | null;
currentMode: GameMode;
editor?: JSX.Element;
isUpdatingCover?: boolean;
modifiers?: Modifiers;
Expand Down
3 changes: 2 additions & 1 deletion resources/js/utils/offset-paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import KudosuHistoryJson from 'interfaces/kudosu-history-json';
import { route } from 'laroute';
import { action } from 'mobx';
import { RouteList } from 'ziggy-js';

type RouteParams = Partial<Record<string, string | number>>;

Expand All @@ -17,7 +18,7 @@ export interface OffsetPaginatorJson<T> {
pagination: OffsetPaginationJson;
}

export const apiShowMore = action(<T>(json: OffsetPaginatorJson<T>, routeName: string, baseRouteParams: RouteParams): JQuery.jqXHR<T[]> => {
export const apiShowMore = action(<T>(json: OffsetPaginatorJson<T>, routeName: keyof RouteList, baseRouteParams: RouteParams): JQuery.jqXHR<T[]> => {
json.pagination.loading = true;

let limit = baseRouteParams.limit;
Expand Down
11 changes: 2 additions & 9 deletions resources/js/ziggy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

declare module 'ziggy' {
interface ZiggyClass {
port: number | null;
url: string;
}
import route, { RouteList } from 'ziggy-js';

export const Ziggy: ZiggyClass;
}

declare module 'ziggy-route' {
export default function route(name: string, params: any, absolute?: boolean, ziggy?: import('ziggy').ZiggyClass): string;
export const Ziggy: NonNullable<Parameters<typeof route<keyof RouteList>>[3]>;
}
1 change: 1 addition & 0 deletions tests/karma/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"include": [
"../../resources/js",
"../../resources/builds/ziggy.d.ts",
".",
]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"useDefineForClassFields": true
},
"include": [
"resources/js"
"resources/js",
"resources/builds/ziggy.d.ts"
]
}
3 changes: 1 addition & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ const resolve = {
alias: {
'@fonts': path.resolve(__dirname, 'resources/fonts'),
'@images': path.resolve(__dirname, 'public/images'),
'ziggy-route': resolvePath('vendor/tightenco/ziggy/dist/index.es.js'),
},
extensions: ['*', '.js', '.coffee', '.ts', '.tsx'],
modules: [
Expand Down Expand Up @@ -294,7 +293,7 @@ const watches = [
{
callback: () => spawnSync(
'php',
['artisan', 'ziggy:generate', 'resources/builds/ziggy.js'],
['artisan', 'ziggy:generate', 'resources/builds/ziggy.js', '--types'],
{ stdio: 'inherit' },
),
path: resolvePath('routes/web.php'),
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6483,6 +6483,11 @@ qs@~6.5.2:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.3.tgz#3aeeffc91967ef6e35c0e488ef46fb296ab76aad"
integrity sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==

qs@~6.9.7:
version "6.9.7"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.7.tgz#4610846871485e1e048f44ae3b94033f0e675afe"
integrity sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==

"qtip2@https://github.com/notbakaneko/qTip2.git#cd5f038667d2b23a44f4274c46de01834d704ce6":
version "3.0.3-jquery3"
resolved "https://github.com/notbakaneko/qTip2.git#cd5f038667d2b23a44f4274c46de01834d704ce6"
Expand Down Expand Up @@ -8245,6 +8250,13 @@ yargs@^16.1.1:
y18n "^5.0.5"
yargs-parser "^20.2.2"

ziggy-js@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/ziggy-js/-/ziggy-js-1.8.1.tgz#582f4c19424cec0f8b80de2d033d70f953314a94"
integrity sha512-fnf30uG0yvUQBPL4T8YPgmkBHUdjYaOFgUb1K1gj0+rclnLTNr9/K/cxC3xkCZyYCZz8oTnXkdf3oJXRPSzavw==
dependencies:
qs "~6.9.7"

zwitch@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920"
Expand Down

0 comments on commit 8d4c947

Please sign in to comment.