Skip to content

Commit

Permalink
fix: replace +title with useConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Sep 16, 2024
1 parent 6d6c5a3 commit 424abb4
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 81 deletions.
11 changes: 11 additions & 0 deletions boilerplates/react/files/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";
import { useConfig } from "vike-react/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
// Set <title>
title: movie.title

Check failure on line 18 in boilerplates/react/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 18 in boilerplates/react/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to
// the client; we should minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/react/files/pages/star-wars/@id/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/react/files/pages/star-wars/index/+data.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// https://vike.dev/data

import type { Movie, MovieDetails } from "../types.js";
import { useConfig } from "vike-react/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const moviesData = (await response.json()) as MovieDetails[];

config({
// Set <title>
title: `${moviesData.length} Star Wars Movies`

Check failure on line 17 in boilerplates/react/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 17 in boilerplates/react/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to the client; we should
// minimize what is sent over the network.
const movies = minimize(moviesData);

return movies;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/react/files/pages/star-wars/index/+title.ts

This file was deleted.

14 changes: 1 addition & 13 deletions boilerplates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,12 @@
"./pages/star-wars/@id/+Page": {
"types": "./dist/types/pages/star-wars/@id/+Page.d.ts"
},
"./pages/star-wars/@id/+title": {
"types": "./dist/types/pages/star-wars/@id/+title.d.ts"
},
"./pages/star-wars/index/+data": {
"types": "./dist/types/pages/star-wars/index/+data.d.ts"
},
"./pages/star-wars/index/+Page": {
"types": "./dist/types/pages/star-wars/index/+Page.d.ts"
},
"./pages/star-wars/index/+title": {
"types": "./dist/types/pages/star-wars/index/+title.d.ts"
},
"./pages/todo/TodoList": {
"types": "./dist/types/pages/todo/TodoList.d.ts"
},
Expand Down Expand Up @@ -135,18 +129,12 @@
"pages/star-wars/@id/+Page": [
"./dist/types/pages/star-wars/@id/+Page.d.ts"
],
"pages/star-wars/@id/+title": [
"./dist/types/pages/star-wars/@id/+title.d.ts"
],
"pages/star-wars/index/+data": [
"./dist/types/pages/star-wars/index/+data.d.ts"
],
"pages/star-wars/index/+Page": [
"./dist/types/pages/star-wars/index/+Page.d.ts"
],
"pages/star-wars/index/+title": [
"./dist/types/pages/star-wars/index/+title.d.ts"
],
"pages/todo/TodoList": [
"./dist/types/pages/todo/TodoList.d.ts"
],
Expand All @@ -155,4 +143,4 @@
]
}
}
}
}
11 changes: 11 additions & 0 deletions boilerplates/solid/files/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";
import { useConfig } from "vike-solid/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
// Set <title>
title: movie.title

Check failure on line 18 in boilerplates/solid/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 18 in boilerplates/solid/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to
// the client; we should minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/solid/files/pages/star-wars/@id/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/solid/files/pages/star-wars/index/+data.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// https://vike.dev/data

import type { Movie, MovieDetails } from "../types.js";
import { useConfig } from "vike-solid/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const moviesData = (await response.json()) as MovieDetails[];

config({
// Set <title>
title: `${moviesData.length} Star Wars Movies`

Check failure on line 17 in boilerplates/solid/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 17 in boilerplates/solid/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to the client; we should
// minimize what is sent over the network.
const movies = minimize(moviesData);

return movies;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/solid/files/pages/star-wars/index/+title.ts

This file was deleted.

14 changes: 1 addition & 13 deletions boilerplates/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,12 @@
"./pages/star-wars/@id/+Page": {
"types": "./dist/types/pages/star-wars/@id/+Page.d.ts"
},
"./pages/star-wars/@id/+title": {
"types": "./dist/types/pages/star-wars/@id/+title.d.ts"
},
"./pages/star-wars/index/+data": {
"types": "./dist/types/pages/star-wars/index/+data.d.ts"
},
"./pages/star-wars/index/+Page": {
"types": "./dist/types/pages/star-wars/index/+Page.d.ts"
},
"./pages/star-wars/index/+title": {
"types": "./dist/types/pages/star-wars/index/+title.d.ts"
},
"./pages/todo/TodoList": {
"types": "./dist/types/pages/todo/TodoList.d.ts"
},
Expand Down Expand Up @@ -127,18 +121,12 @@
"pages/star-wars/@id/+Page": [
"./dist/types/pages/star-wars/@id/+Page.d.ts"
],
"pages/star-wars/@id/+title": [
"./dist/types/pages/star-wars/@id/+title.d.ts"
],
"pages/star-wars/index/+data": [
"./dist/types/pages/star-wars/index/+data.d.ts"
],
"pages/star-wars/index/+Page": [
"./dist/types/pages/star-wars/index/+Page.d.ts"
],
"pages/star-wars/index/+title": [
"./dist/types/pages/star-wars/index/+title.d.ts"
],
"pages/todo/TodoList": [
"./dist/types/pages/todo/TodoList.d.ts"
],
Expand All @@ -147,4 +135,4 @@
]
}
}
}
}
11 changes: 11 additions & 0 deletions boilerplates/vue/files/pages/star-wars/@id/+data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import type { PageContextServer } from "vike/types";
import type { MovieDetails } from "../types.js";
import { useConfig } from "vike-vue/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
let movie = (await response.json()) as MovieDetails;

config({
// Set <title>
title: movie.title

Check failure on line 18 in boilerplates/vue/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 18 in boilerplates/vue/files/pages/star-wars/@id/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to
// the client; we should minimize what is sent over the network.
movie = minimize(movie);

return movie;
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/vue/files/pages/star-wars/@id/+title.ts

This file was deleted.

11 changes: 11 additions & 0 deletions boilerplates/vue/files/pages/star-wars/index/+data.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// https://vike.dev/data

import type { Movie, MovieDetails } from "../types.js";
import { useConfig } from "vike-vue/useConfig";

export type Data = Awaited<ReturnType<typeof data>>;

export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();

const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const moviesData = (await response.json()) as MovieDetails[];

config({
// Set <title>
title: `${moviesData.length} Star Wars Movies`

Check failure on line 17 in boilerplates/vue/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (20)

Insert `,`

Check failure on line 17 in boilerplates/vue/files/pages/star-wars/index/+data.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-types (18)

Insert `,`
});

// We remove data we don't need because the data is passed to the client; we should
// minimize what is sent over the network.
const movies = minimize(moviesData);

return { data: movies };
};

Expand Down
7 changes: 0 additions & 7 deletions boilerplates/vue/files/pages/star-wars/index/+title.ts

This file was deleted.

14 changes: 1 addition & 13 deletions boilerplates/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@
"./pages/star-wars/@id/+data": {
"types": "./dist/types/pages/star-wars/@id/+data.d.ts"
},
"./pages/star-wars/@id/+title": {
"types": "./dist/types/pages/star-wars/@id/+title.d.ts"
},
"./pages/star-wars/index/+data": {
"types": "./dist/types/pages/star-wars/index/+data.d.ts"
},
"./pages/star-wars/index/+title": {
"types": "./dist/types/pages/star-wars/index/+title.d.ts"
}
},
"typesVersions": {
Expand All @@ -86,15 +80,9 @@
"pages/star-wars/@id/+data": [
"./dist/types/pages/star-wars/@id/+data.d.ts"
],
"pages/star-wars/@id/+title": [
"./dist/types/pages/star-wars/@id/+title.d.ts"
],
"pages/star-wars/index/+data": [
"./dist/types/pages/star-wars/index/+data.d.ts"
],
"pages/star-wars/index/+title": [
"./dist/types/pages/star-wars/index/+title.d.ts"
]
}
}
}
}

0 comments on commit 424abb4

Please sign in to comment.